Untabify posixfcn.c.

This commit is contained in:
Eli Zaretskii 2013-10-07 19:16:11 +03:00
parent b69b04dc8c
commit 723e047428

View File

@ -40,106 +40,106 @@ fcntl (intptr_t fd, int cmd, ...)
switch (cmd) switch (cmd)
{ {
case F_GETFD: case F_GETFD:
va_end (ap); va_end (ap);
/* Could have used GetHandleInformation, but that isn't /* Could have used GetHandleInformation, but that isn't
supported on Windows 9X. */ supported on Windows 9X. */
if (_get_osfhandle (fd) == -1) if (_get_osfhandle (fd) == -1)
return -1; return -1;
return 0; return 0;
case F_SETLKW: case F_SETLKW:
{ {
void *buf = va_arg (ap, void *); void *buf = va_arg (ap, void *);
struct flock *fl = (struct flock *)buf; struct flock *fl = (struct flock *)buf;
HANDLE hmutex = (HANDLE)fd; HANDLE hmutex = (HANDLE)fd;
static struct flock last_fl; static struct flock last_fl;
short last_type = last_fl.l_type; short last_type = last_fl.l_type;
va_end (ap); va_end (ap);
if (hmutex == INVALID_HANDLE_VALUE || !hmutex) if (hmutex == INVALID_HANDLE_VALUE || !hmutex)
return -1; return -1;
last_fl = *fl; last_fl = *fl;
switch (fl->l_type) switch (fl->l_type)
{ {
case F_WRLCK: case F_WRLCK:
{ {
DWORD result; DWORD result;
if (last_type == F_WRLCK) if (last_type == F_WRLCK)
{ {
/* Don't call WaitForSingleObject if we already /* Don't call WaitForSingleObject if we already
own the mutex, because doing so will require own the mutex, because doing so will require
us to call ReleaseMutex an equal number of us to call ReleaseMutex an equal number of
times, before the mutex is actually times, before the mutex is actually
released. */ released. */
return 0; return 0;
} }
result = WaitForSingleObject (hmutex, INFINITE); result = WaitForSingleObject (hmutex, INFINITE);
switch (result) switch (result)
{ {
case WAIT_OBJECT_0: case WAIT_OBJECT_0:
/* We don't care if the mutex owner crashed or /* We don't care if the mutex owner crashed or
exited. */ exited. */
case WAIT_ABANDONED: case WAIT_ABANDONED:
return 0; return 0;
case WAIT_FAILED: case WAIT_FAILED:
case WAIT_TIMEOUT: /* cannot happen, really */ case WAIT_TIMEOUT: /* cannot happen, really */
{ {
DWORD err = GetLastError (); DWORD err = GetLastError ();
/* Invalidate the last command. */ /* Invalidate the last command. */
memset (&last_fl, 0, sizeof (last_fl)); memset (&last_fl, 0, sizeof (last_fl));
switch (err) switch (err)
{ {
case ERROR_INVALID_HANDLE: case ERROR_INVALID_HANDLE:
case ERROR_INVALID_FUNCTION: case ERROR_INVALID_FUNCTION:
errno = EINVAL; errno = EINVAL;
return -1; return -1;
default: default:
errno = EDEADLOCK; errno = EDEADLOCK;
return -1; return -1;
} }
} }
} }
} }
case F_UNLCK: case F_UNLCK:
{ {
/* FIXME: Perhaps we should call ReleaseMutex /* FIXME: Perhaps we should call ReleaseMutex
repatedly until it errors out, to make sure the repatedly until it errors out, to make sure the
mutext is released even if we somehow managed to mutext is released even if we somehow managed to
to take ownership multiple times? */ to take ownership multiple times? */
BOOL status = ReleaseMutex (hmutex); BOOL status = ReleaseMutex (hmutex);
if (status) if (status)
return 0; return 0;
else else
{ {
DWORD err = GetLastError (); DWORD err = GetLastError ();
if (err == ERROR_NOT_OWNER) if (err == ERROR_NOT_OWNER)
errno = EPERM; errno = EPERM;
else else
{ {
memset (&last_fl, 0, sizeof (last_fl)); memset (&last_fl, 0, sizeof (last_fl));
errno = EINVAL; errno = EINVAL;
} }
return -1; return -1;
} }
} }
default: default:
errno = ENOSYS; errno = ENOSYS;
return -1; return -1;
} }
} }
default: default:
errno = ENOSYS; errno = ENOSYS;
va_end (ap); va_end (ap);
return -1; return -1;
} }
} }
@ -210,49 +210,49 @@ same_stream (FILE *f1, FILE *f2)
&& fh2 && fh2 != INVALID_HANDLE_VALUE) && fh2 && fh2 != INVALID_HANDLE_VALUE)
{ {
if (fh1 == fh2) if (fh1 == fh2)
return 1; return 1;
else else
{ {
DWORD ftyp1 = GetFileType (fh1), ftyp2 = GetFileType (fh2); DWORD ftyp1 = GetFileType (fh1), ftyp2 = GetFileType (fh2);
if (ftyp1 != ftyp2 if (ftyp1 != ftyp2
|| ftyp1 == FILE_TYPE_UNKNOWN || ftyp2 == FILE_TYPE_UNKNOWN) || ftyp1 == FILE_TYPE_UNKNOWN || ftyp2 == FILE_TYPE_UNKNOWN)
return 0; return 0;
else if (ftyp1 == FILE_TYPE_CHAR) else if (ftyp1 == FILE_TYPE_CHAR)
{ {
/* For character devices, check if they both refer to a /* For character devices, check if they both refer to a
console. This loses if both handles refer to the console. This loses if both handles refer to the
null device (FIXME!), but in that case we don't care null device (FIXME!), but in that case we don't care
in the context of Make. */ in the context of Make. */
DWORD conmode1, conmode2; DWORD conmode1, conmode2;
/* Each process on Windows can have at most 1 console, /* Each process on Windows can have at most 1 console,
so if both handles are for the console device, they so if both handles are for the console device, they
are the same. We also compare the console mode to are the same. We also compare the console mode to
distinguish between stdin and stdout/stderr. */ distinguish between stdin and stdout/stderr. */
if (GetConsoleMode (fh1, &conmode1) if (GetConsoleMode (fh1, &conmode1)
&& GetConsoleMode (fh2, &conmode2) && GetConsoleMode (fh2, &conmode2)
&& conmode1 == conmode2) && conmode1 == conmode2)
return 1; return 1;
} }
else else
{ {
/* For disk files and pipes, compare their unique /* For disk files and pipes, compare their unique
attributes. */ attributes. */
BY_HANDLE_FILE_INFORMATION bhfi1, bhfi2; BY_HANDLE_FILE_INFORMATION bhfi1, bhfi2;
/* Pipes get zero in the volume serial number, but do /* Pipes get zero in the volume serial number, but do
appear to have meaningful information in file index appear to have meaningful information in file index
attributes. We test file attributes as well, for a attributes. We test file attributes as well, for a
good measure. */ good measure. */
if (GetFileInformationByHandle (fh1, &bhfi1) if (GetFileInformationByHandle (fh1, &bhfi1)
&& GetFileInformationByHandle (fh2, &bhfi2)) && GetFileInformationByHandle (fh2, &bhfi2))
return (bhfi1.dwVolumeSerialNumber == bhfi2.dwVolumeSerialNumber return (bhfi1.dwVolumeSerialNumber == bhfi2.dwVolumeSerialNumber
&& bhfi1.nFileIndexLow == bhfi2.nFileIndexLow && bhfi1.nFileIndexLow == bhfi2.nFileIndexLow
&& bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh && bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh
&& bhfi1.dwFileAttributes == bhfi2.dwFileAttributes); && bhfi1.dwFileAttributes == bhfi2.dwFileAttributes);
} }
} }
} }
return 0; return 0;
} }
@ -304,18 +304,18 @@ tmpfile (void)
HANDLE h; HANDLE h;
sprintf (temp_path + path_size, sprintf (temp_path + path_size,
"%s%s%u-%x.tmp", "%s%s%u-%x.tmp",
temp_path[path_size - 1] == '\\' ? "" : "\\", temp_path[path_size - 1] == '\\' ? "" : "\\",
base, pid, uniq); base, pid, uniq);
h = CreateFile (temp_path, /* file name */ h = CreateFile (temp_path, /* file name */
GENERIC_READ | GENERIC_WRITE | DELETE, /* desired access */ GENERIC_READ | GENERIC_WRITE | DELETE, /* desired access */
FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */
NULL, /* default security attributes */ NULL, /* default security attributes */
CREATE_NEW, /* creation disposition */ CREATE_NEW, /* creation disposition */
FILE_ATTRIBUTE_NORMAL | /* flags and attributes */ FILE_ATTRIBUTE_NORMAL | /* flags and attributes */
FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_TEMPORARY |
FILE_FLAG_DELETE_ON_CLOSE, FILE_FLAG_DELETE_ON_CLOSE,
NULL); /* no template file */ NULL); /* no template file */
if (h == INVALID_HANDLE_VALUE) if (h == INVALID_HANDLE_VALUE)
{ {
@ -332,8 +332,8 @@ tmpfile (void)
} }
/* The temporary path is not guaranteed to exist, or might /* The temporary path is not guaranteed to exist, or might
not be writable by user. Use the current directory as not be writable by user. Use the current directory as
fallback. */ fallback. */
else if (path_is_dot == 0) else if (path_is_dot == 0)
{ {
path_size = GetCurrentDirectory (sizeof temp_path, temp_path); path_size = GetCurrentDirectory (sizeof temp_path, temp_path);
@ -341,10 +341,10 @@ tmpfile (void)
} }
else else
{ {
errno = EACCES; errno = EACCES;
break; break;
} }
} }
else else
{ {
@ -359,7 +359,7 @@ tmpfile (void)
return NULL; return NULL;
} }
#endif /* !NO_OUTPUT_SYNC */ #endif /* !NO_OUTPUT_SYNC */
#if MAKE_LOAD #if MAKE_LOAD
@ -388,8 +388,8 @@ dlopen (const char *file, int mode)
/* MSDN says to be sure to use backslashes in the DLL file name. */ /* MSDN says to be sure to use backslashes in the DLL file name. */
strcpy (dllfn, file); strcpy (dllfn, file);
for (p = dllfn; *p; p++) for (p = dllfn; *p; p++)
if (*p == '/') if (*p == '/')
*p = '\\'; *p = '\\';
dllhandle = LoadLibrary (dllfn); dllhandle = LoadLibrary (dllfn);
} }
@ -409,8 +409,8 @@ dlerror (void)
return NULL; return NULL;
ret = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM ret = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS, | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, last_err, 0, errbuf, sizeof (errbuf), NULL); NULL, last_err, 0, errbuf, sizeof (errbuf), NULL);
while (ret > 0 && (errbuf[ret - 1] == '\n' || errbuf[ret - 1] == '\r')) while (ret > 0 && (errbuf[ret - 1] == '\n' || errbuf[ret - 1] == '\r'))
--ret; --ret;
@ -452,5 +452,5 @@ dlclose (void *handle)
} }
#endif /* MAKE_LOAD */ #endif /* MAKE_LOAD */