Dr A Olowofoyeku wrote:
Here is the fsync function. I get compile errors when converting it to a macro in os-hacks.h - so please convert it for me.
int fsync (int __fd) { return FlushFileBuffers ((HANDLE) _get_osfhandle (__fd)); }
I don't know all the relevant declarations, but normally, the following should work:
#define fsync(__fd) (FlushFileBuffers ((HANDLE) _get_osfhandle (__fd)))
If it doesn't, please show me the error messages. BTW, does FlushFileBuffers return 0 on success and -1 on error? If it returns 1 on success and 0 on error (as some Windoze routines do IIRC), try:
#define fsync(__fd) ((FlushFileBuffers ((HANDLE) _get_osfhandle (__fd))) ? 0 : -1)
getpwnam, getpwuid - get password file entry
Here is my implementation. The WinAPI calls are correct, but I am clearly not doing things correctly as far as the return values for pointers to the passwd structure is concerned - I get garbabe in the fields when I call the functions that return pointers to the passwd structure (but inside the functions themselves, when I do "printf" of the return values from the WinAPI functions, I get correct values). So the problem is how to assign the values returned by WinAPI to the fields of the structure, and how to return correctly.
This is because local variables (can) become invalid after the function returns which is problematic if you return a pointer to them. To solve it, declare them as `static'.
AFAICS, this affects the following variables:
char fcc[260]; WCHAR wname[256]; struct passwd psw; struct passwd psw; struct passwd psw1;
BTW: The statment `psw0 = malloc (sizeof (*psw0));' seems to be superfluous as psw0 is overwritten two lines below.
Another thing, in the function:
char *wide2ansi (LPWSTR wide) { char fcc[260]; fcc[0] = NULL; WideCharToMultiByte ( CP_ACP, 0, wide, -1, fcc, 260, NULL, NULL ); return &fcc; }
The `&' should be omitted (in C, arrays are automatically treated as pointers when necessary -- though it seems to work with the `&' as well, but produces a warning).
Frank