diff --git a/library/changes b/library/changes index 2c54e86..c844268 100644 --- a/library/changes +++ b/library/changes @@ -130,15 +130,12 @@ be pulled in only if something references the HUGE_VAL constant. -- The thread-safe system() call now blocks all standard I/O operations - until the function has returned. Which is harsh, but there is no - elegant solution to the issue of keeping the same dos.library - file handles from concurrent use which SystemTagList() might just - end up using. - - Activated the dormant thread-safe standard input/output/error handling code. +- Small fixes to fcntl() and select() to cover the thread-safe + fd->fd_DefaultFile == ZERO case. + c.lib 1.189 (5.3.2005) diff --git a/library/fcntl_fcntl.c b/library/fcntl_fcntl.c index a597d49..6e55f31 100644 --- a/library/fcntl_fcntl.c +++ b/library/fcntl_fcntl.c @@ -1,5 +1,5 @@ /* - * $Id: fcntl_fcntl.c,v 1.13 2005-03-16 09:28:37 obarthel Exp $ + * $Id: fcntl_fcntl.c,v 1.14 2005-03-25 08:50:59 obarthel Exp $ * * :ts=4 * @@ -90,6 +90,12 @@ fcntl(int file_descriptor, int cmd, ... /* int arg */ ) goto out; } + if(fd->fd_DefaultFile == ZERO) + { + __set_errno(EBADF); + goto out; + } + va_start(arg,cmd); l = va_arg(arg,struct flock *); va_end(arg); @@ -140,6 +146,12 @@ fcntl(int file_descriptor, int cmd, ... /* int arg */ ) SHOWMSG("cmd=F_SETFL"); + if(fd->fd_DefaultFile == ZERO) + { + __set_errno(EBADF); + goto out; + } + va_start(arg,cmd); flags = va_arg(arg,int); va_end(arg); diff --git a/library/socket_select.c b/library/socket_select.c index 38fb37a..f560f57 100644 --- a/library/socket_select.c +++ b/library/socket_select.c @@ -1,5 +1,5 @@ /* - * $Id: socket_select.c,v 1.8 2005-03-18 12:38:23 obarthel Exp $ + * $Id: socket_select.c,v 1.9 2005-03-25 08:50:59 obarthel Exp $ * * :ts=4 * @@ -309,7 +309,7 @@ map_descriptor_sets( else { /* We only watch files bound to console streams. */ - if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_INTERACTIVE)) + if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_INTERACTIVE) || fd->fd_DefaultFile == ZERO) { SHOWMSG("this is a file"); continue; @@ -761,7 +761,7 @@ select(int num_fds,fd_set *read_fds,fd_set *write_fds,fd_set *except_fds,struct { if(FLAG_IS_SET(fd->fd_Flags,FDF_READ)) { - assert( FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_SOCKET) ); + assert( FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_SOCKET) && fd->fd_DefaultFile != ZERO ); /* Does this one have input? */ PROFILE_OFF(); @@ -921,7 +921,7 @@ select(int num_fds,fd_set *read_fds,fd_set *write_fds,fd_set *except_fds,struct { if(FLAG_IS_SET(fd->fd_Flags,FDF_READ)) { - assert( FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_SOCKET) ); + assert( FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_SOCKET) && fd->fd_DefaultFile != ZERO ); PROFILE_OFF(); diff --git a/library/stdlib_constructor_begin.c b/library/stdlib_constructor_begin.c index cf10f06..a63e60c 100644 --- a/library/stdlib_constructor_begin.c +++ b/library/stdlib_constructor_begin.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_constructor_begin.c,v 1.9 2005-03-20 12:14:09 obarthel Exp $ + * $Id: stdlib_constructor_begin.c,v 1.10 2005-03-25 08:50:59 obarthel Exp $ * * :ts=4 * @@ -52,7 +52,12 @@ extern void (* __far __dtors[])(void); /* With SAS/C this function is placed in front of the first constructor table entry. It will invoke all following constructors and - finally all the destructors. We don't use this approach here. */ + finally all the destructors. We don't use this approach here and + we can't because the naming scheme we use for the constructor and + destructor functions differs from the default SAS/C usage. With + SAS/C the default behaviour is to invoke the constructors in + ascending order of priority. We invoke them in descending order of + priority (highest first). */ void __construct(void) { @@ -71,6 +76,7 @@ _init(void) int num_constructors; int i; + /* Count the number of constructors we have to deal with. */ num_constructors = 0; while(__ctors[num_constructors] != NULL) @@ -98,6 +104,7 @@ _fini(void) int num_destructors; + /* Count the number of destructors we have to deal with. */ num_destructors = 0; while(__dtors[num_destructors] != NULL) diff --git a/library/stdlib_system.c b/library/stdlib_system.c index a73ad05..344a98b 100644 --- a/library/stdlib_system.c +++ b/library/stdlib_system.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_system.c,v 1.6 2005-03-24 15:31:16 obarthel Exp $ + * $Id: stdlib_system.c,v 1.7 2005-03-25 08:50:59 obarthel Exp $ * * :ts=4 * @@ -177,17 +177,13 @@ system(const char * command) PROFILE_OFF(); - /* In thread-safe mode, system() operation can interfere with - regular file I/O if the same dos.library file handles are - involved. Because we really cannot predict which file handles - will be associated with the current Output() and Input() - streams, we play it safe and just block everything. */ - __stdio_lock(); + /* Push all currently buffered output towards the file handles, + in case the program to be launched writes to these files + or the console, too. */ + __flush_all_files(-1); result = SystemTagList((STRPTR)command, (struct TagItem *)system_tags); - __stdio_unlock(); - PROFILE_ON(); }