Cleanup calls to CreateFile throughout.

* dcrt0.cc (__api_fatal): Correctly check for failing return from CreateFile.
* assert.cc (__assert): Don't check return value from CreateFile for NULL.
* fhandler_console.cc (set_console_state_for_spawn): Ditto.
* fork.cc (fork_parent): Ditto.
This commit is contained in:
Christopher Faylor 2002-09-19 15:12:48 +00:00
parent 776044d554
commit 580e99a151
11 changed files with 56 additions and 65 deletions

View File

@ -1,3 +1,11 @@
2002-09-19 Christopher Faylor <cgf@redhat.com>
Cleanup calls to CreateFile throughout.
* dcrt0.cc (__api_fatal): Correctly check for failing return from CreateFile.
* assert.cc (__assert): Don't check return value from CreateFile for NULL.
* fhandler_console.cc (set_console_state_for_spawn): Ditto.
* fork.cc (fork_parent): Ditto.
2002-09-18 Christopher Faylor <cgf@redhat.com> 2002-09-18 Christopher Faylor <cgf@redhat.com>
* cygthread.cc (cygthread::initialized): Avoid copying on fork or some * cygthread.cc (cygthread::initialized): Avoid copying on fork or some

View File

@ -28,9 +28,9 @@ __assert (const char *file, int line, const char *failedexpr)
/* If we don't have a console in a Windows program, then bring up a /* If we don't have a console in a Windows program, then bring up a
message box for the assertion failure. */ message box for the assertion failure. */
h = CreateFileA ("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, &sec_none_nih, h = CreateFile ("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, &sec_none_nih,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE || h == 0) if (h == INVALID_HANDLE_VALUE)
{ {
char *buf; char *buf;

View File

@ -1057,10 +1057,10 @@ __api_fatal (const char *fmt, ...)
a serious error. */ a serious error. */
if (GetFileType (GetStdHandle (STD_ERROR_HANDLE)) != FILE_TYPE_CHAR) if (GetFileType (GetStdHandle (STD_ERROR_HANDLE)) != FILE_TYPE_CHAR)
{ {
HANDLE h = CreateFileA ("CONOUT$", GENERIC_READ|GENERIC_WRITE, HANDLE h = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_WRITE | FILE_SHARE_WRITE, &sec_none, FILE_SHARE_WRITE | FILE_SHARE_WRITE,
OPEN_EXISTING, 0, 0); &sec_none, OPEN_EXISTING, 0, 0);
if (h) if (h != INVALID_HANDLE_VALUE)
(void) WriteFile (h, buf, len, &done, 0); (void) WriteFile (h, buf, len, &done, 0);
} }

View File

@ -436,7 +436,7 @@ fhandler_base::open (path_conv *pc, int flags, mode_t mode)
x = CreateFile (get_win32_name (), access, shared, &sa, creation_distribution, x = CreateFile (get_win32_name (), access, shared, &sa, creation_distribution,
file_attributes, 0); file_attributes, 0);
syscall_printf ("%p = CreateFileA (%s, %p, %p, %p, %p, %p, 0)", syscall_printf ("%p = CreateFile (%s, %p, %p, %p, %p, %p, 0)",
x, get_win32_name (), access, shared, &sa, x, get_win32_name (), access, shared, &sa,
creation_distribution, file_attributes); creation_distribution, file_attributes);

View File

@ -135,11 +135,11 @@ tty_list::get_tty (int n)
int __stdcall int __stdcall
set_console_state_for_spawn () set_console_state_for_spawn ()
{ {
HANDLE h = CreateFileA ("CONIN$", GENERIC_READ, FILE_SHARE_WRITE, HANDLE h = CreateFile ("CONIN$", GENERIC_READ, FILE_SHARE_WRITE,
&sec_none_nih, OPEN_EXISTING, &sec_none_nih, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
FILE_ATTRIBUTE_NORMAL, NULL); NULL);
if (h == INVALID_HANDLE_VALUE || h == NULL) if (h == INVALID_HANDLE_VALUE)
return 0; return 0;
if (shared_console_info != NULL) if (shared_console_info != NULL)
@ -547,7 +547,7 @@ fhandler_console::open (path_conv *, int flags, mode_t)
set_flags ((flags & ~O_TEXT) | O_BINARY); set_flags ((flags & ~O_TEXT) | O_BINARY);
/* Open the input handle as handle_ */ /* Open the input handle as handle_ */
h = CreateFileA ("CONIN$", GENERIC_READ|GENERIC_WRITE, h = CreateFile ("CONIN$", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, &sec_none, FILE_SHARE_READ | FILE_SHARE_WRITE, &sec_none,
OPEN_EXISTING, 0, 0); OPEN_EXISTING, 0, 0);
@ -559,7 +559,7 @@ fhandler_console::open (path_conv *, int flags, mode_t)
set_io_handle (h); set_io_handle (h);
set_r_no_interrupt (1); // Handled explicitly in read code set_r_no_interrupt (1); // Handled explicitly in read code
h = CreateFileA ("CONOUT$", GENERIC_READ|GENERIC_WRITE, h = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, &sec_none, FILE_SHARE_READ | FILE_SHARE_WRITE, &sec_none,
OPEN_EXISTING, 0, 0); OPEN_EXISTING, 0, 0);

View File

@ -362,12 +362,12 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
/* If we don't have a console, then don't create a console for the /* If we don't have a console, then don't create a console for the
child either. */ child either. */
HANDLE console_handle = CreateFileA ("CONOUT$", GENERIC_WRITE, HANDLE console_handle = CreateFile ("CONOUT$", GENERIC_WRITE,
FILE_SHARE_WRITE, &sec_none_nih, FILE_SHARE_WRITE, &sec_none_nih,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
NULL); NULL);
if (console_handle != INVALID_HANDLE_VALUE && console_handle != 0) if (console_handle != INVALID_HANDLE_VALUE)
CloseHandle (console_handle); CloseHandle (console_handle);
else else
c_flags |= DETACHED_PROCESS; c_flags |= DETACHED_PROCESS;

View File

@ -95,8 +95,7 @@ NTReadEA (const char *file, const char *attrname, char *attrbuf, int len)
&sec_none_nih, // sa &sec_none_nih, // sa
OPEN_EXISTING, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS, FILE_FLAG_BACKUP_SEMANTICS,
NULL NULL);
);
if (hFileSource == INVALID_HANDLE_VALUE) if (hFileSource == INVALID_HANDLE_VALUE)
return 0; return 0;

View File

@ -60,13 +60,9 @@ open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, void *addr)
TRUE, mapname); TRUE, mapname);
} }
if (!shared_h && if (!shared_h &&
!(shared_h = CreateFileMappingA (INVALID_HANDLE_VALUE, !(shared_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_all,
&sec_all, PAGE_READWRITE, 0, size, mapname)))
PAGE_READWRITE, api_fatal ("CreateFileMapping, %E. Terminating.");
0,
size,
mapname)))
api_fatal ("CreateFileMappingA, %E. Terminating.");
} }
shared = (shared_info *) MapViewOfFileEx (shared_h, shared = (shared_info *) MapViewOfFileEx (shared_h,

View File

@ -420,13 +420,10 @@ spawn_guts (const char * prog_arg, const char *const *argv,
that it is NOT a script file */ that it is NOT a script file */
while (*ext == '\0') while (*ext == '\0')
{ {
HANDLE hnd = CreateFileA (real_path, HANDLE hnd = CreateFile (real_path, GENERIC_READ,
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
&sec_none_nih, &sec_none_nih, OPEN_EXISTING,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
FILE_ATTRIBUTE_NORMAL,
0);
if (hnd == INVALID_HANDLE_VALUE) if (hnd == INVALID_HANDLE_VALUE)
{ {
__seterrno (); __seterrno ();

View File

@ -648,15 +648,10 @@ _link (const char *a, const char *b)
BOOL bSuccess; BOOL bSuccess;
hFileSource = CreateFile ( hFileSource = CreateFile (real_a, FILE_WRITE_ATTRIBUTES,
real_a,
FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE /*| FILE_SHARE_DELETE*/, FILE_SHARE_READ | FILE_SHARE_WRITE /*| FILE_SHARE_DELETE*/,
&sec_none_nih, // sa &sec_none_nih, // sa
OPEN_EXISTING, OPEN_EXISTING, 0, NULL);
0,
NULL
);
if (hFileSource == INVALID_HANDLE_VALUE) if (hFileSource == INVALID_HANDLE_VALUE)
{ {
@ -2435,10 +2430,8 @@ logout (char *line)
ut_fd = CreateFile (win32_path.get_win32 (), ut_fd = CreateFile (win32_path.get_win32 (),
GENERIC_READ | GENERIC_WRITE, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
&sec_none_nih, &sec_none_nih, OPEN_EXISTING,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
FILE_ATTRIBUTE_NORMAL,
NULL);
if (ut_fd != INVALID_HANDLE_VALUE) if (ut_fd != INVALID_HANDLE_VALUE)
{ {
struct utmp *ut; struct utmp *ut;

View File

@ -471,11 +471,9 @@ utimes (const char *path, struct timeval *tvp)
the times of directories. */ the times of directories. */
/* Note: It's not documented in MSDN that FILE_WRITE_ATTRIBUTES is /* Note: It's not documented in MSDN that FILE_WRITE_ATTRIBUTES is
sufficient to change the timestamps... */ sufficient to change the timestamps... */
HANDLE h = CreateFileA (win32.get_win32 (), HANDLE h = CreateFile (win32, FILE_WRITE_ATTRIBUTES,
FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
&sec_none_nih, &sec_none_nih, OPEN_EXISTING,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS,
0); 0);