From 773035a695a45d5b39c637d5f49e2aa7dfa478dd Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Mon, 15 Aug 2005 10:17:48 +0000 Subject: [PATCH] - Modified select() to support plain files, too. The new code now compares the current file position against the current file size, if that file is on a file system, or simply checks if there is any data in the file (which works for the default PIPE: device). - The raw file descriptor structure member fd_Position is now always updated, regardless of whether the file supports random access or not. - The wildcard escape character used in __wildcard_expand_init() was wrong. It should have been "'" but it was "`". Fixed. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15015 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/changes | 14 +++++- library/socket_select.c | 80 ++++++++++++++++++++++++++++---- library/stdio_fdhookentry.c | 16 ++----- library/unistd_wildcard_expand.c | 6 +-- 4 files changed, 93 insertions(+), 23 deletions(-) diff --git a/library/changes b/library/changes index df02176..79e708d 100644 --- a/library/changes +++ b/library/changes @@ -1,6 +1,18 @@ - In __time_delay() the CheckIO() test was wrong and should have tested for a request still in progress. Fixed. +- Modified select() to support plain files, too. The new code now + compares the current file position against the current file size, + if that file is on a file system, or simply checks if there is + any data in the file (which works for the default PIPE: device). + +- The raw file descriptor structure member fd_Position is now + always updated, regardless of whether the file supports random + access or not. + +- The wildcard escape character used in __wildcard_expand_init() was + wrong. It should have been "'" but it was "`". Fixed. + c.lib 1.194 (15.7.2005) @@ -24,7 +36,7 @@ c.lib 1.194 (15.7.2005) - The pattern matching code which expands command line arguments, as part of libunix.a, now translates the "*" wildcard into "#?" unless you prefix - it with a backtick ("`"), which is the wildcard pattern escape character + it with a backtick ("'"), which is the wildcard pattern escape character used on AmigaOS. - Repaired the pattern matching code which expands command line arguments: diff --git a/library/socket_select.c b/library/socket_select.c index 5d4b067..6979a1f 100644 --- a/library/socket_select.c +++ b/library/socket_select.c @@ -1,5 +1,5 @@ /* - * $Id: socket_select.c,v 1.11 2005-04-24 08:46:37 obarthel Exp $ + * $Id: socket_select.c,v 1.12 2005-08-15 10:17:47 obarthel Exp $ * * :ts=4 * @@ -308,14 +308,30 @@ map_descriptor_sets( } else { - /* We only watch files bound to console streams. */ - if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_INTERACTIVE) || FLAG_IS_SET(fd->fd_Flags,FDF_STDIO)) + /* We watch files bound to console streams and disk + files which may have data stored in them. */ + if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO)) { SHOWMSG("this is a file, or otherwise unsuitable"); continue; } - SHOWMSG("this is an interactive stream"); + if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE)) + { + SHOWMSG("this is an interactive stream"); + } + else + { + D_S(struct FileInfoBlock,fib); + + /* Let's see if we can examine the file. Some file systems + may not support this. */ + if(CANNOT __safe_examine_file_handle(fd->fd_DefaultFile,fib)) + { + SHOWMSG("file is unusable; we cannot examine the file."); + continue; + } + } if(file_fds != NULL && file_fd < num_file_fds) { @@ -766,8 +782,35 @@ select(int num_fds,fd_set *read_fds,fd_set *write_fds,fd_set *except_fds,struct /* Does this one have input? */ PROFILE_OFF(); - if(WaitForChar(fd->fd_DefaultFile,1)) - got_input = TRUE; + if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE)) + { + /* For an interactive stream, we simply ask. */ + if(WaitForChar(fd->fd_DefaultFile,1)) + got_input = TRUE; + } + else + { + D_S(struct FileInfoBlock,fib); + + /* For a file we check how much data is now in the file and + compare it against the current file position. If there's + unread data in the file, we will be able to read from it. + For pipes, any data reported to be in the "file" indicates + that there is something worth reading available. */ + if(__safe_examine_file_handle(fd->fd_DefaultFile,fib)) + { + if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) + { + if((ULONG)fib->fib_FileSize > fd->fd_Position) + got_input = TRUE; + } + else + { + if(fib->fib_FileSize != 0) + got_input = TRUE; + } + } + } PROFILE_ON(); } @@ -925,8 +968,29 @@ select(int num_fds,fd_set *read_fds,fd_set *write_fds,fd_set *except_fds,struct PROFILE_OFF(); - if(WaitForChar(fd->fd_DefaultFile,1)) - got_input = TRUE; + if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE)) + { + if(WaitForChar(fd->fd_DefaultFile,1)) + got_input = TRUE; + } + else + { + D_S(struct FileInfoBlock,fib); + + if(__safe_examine_file_handle(fd->fd_DefaultFile,fib)) + { + if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) + { + if((ULONG)fib->fib_FileSize > fd->fd_Position) + got_input = TRUE; + } + else + { + if(fib->fib_FileSize != 0) + got_input = TRUE; + } + } + } PROFILE_ON(); } diff --git a/library/stdio_fdhookentry.c b/library/stdio_fdhookentry.c index 61245b7..27408d3 100644 --- a/library/stdio_fdhookentry.c +++ b/library/stdio_fdhookentry.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_fdhookentry.c,v 1.30 2005-04-24 09:53:11 obarthel Exp $ + * $Id: stdio_fdhookentry.c,v 1.31 2005-08-15 10:17:48 obarthel Exp $ * * :ts=4 * @@ -172,8 +172,7 @@ __fd_hook_entry( goto out; } - if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) - fd->fd_Position += (ULONG)result; + fd->fd_Position += (ULONG)result; break; @@ -197,10 +196,7 @@ __fd_hook_entry( overflow. */ position = Seek(file,0,OFFSET_END); if(position != SEEK_ERROR || IoErr() == OK) - { - if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) - fd->fd_Position = Seek(file,0,OFFSET_CURRENT); - } + fd->fd_Position = Seek(file,0,OFFSET_CURRENT); PROFILE_ON(); @@ -229,8 +225,7 @@ __fd_hook_entry( goto out; } - if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) - fd->fd_Position += (ULONG)result; + fd->fd_Position += (ULONG)result; break; @@ -537,8 +532,7 @@ __fd_hook_entry( #endif /* UNIX_PATH_SEMANTICS */ } - if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) - fd->fd_Position = new_position; + fd->fd_Position = new_position; } result = new_position; diff --git a/library/unistd_wildcard_expand.c b/library/unistd_wildcard_expand.c index dffe8d3..7147fb8 100644 --- a/library/unistd_wildcard_expand.c +++ b/library/unistd_wildcard_expand.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_wildcard_expand.c,v 1.14 2005-06-26 10:23:05 obarthel Exp $ + * $Id: unistd_wildcard_expand.c,v 1.15 2005-08-15 10:17:48 obarthel Exp $ * * :ts=4 * @@ -249,7 +249,7 @@ __wildcard_expand_init(void) for(j = 0 ; j < arg_len ; j++) { - if(arg[j] == '*' && last_c != '`') + if(arg[j] == '*' && last_c != '\'') star_count++; last_c = arg[j]; @@ -275,7 +275,7 @@ __wildcard_expand_init(void) /* Replace each "*" with "#?". */ for(j = k = 0 ; j < arg_len ; j++) { - if(arg[j] == '*' && last_c != '`') + if(arg[j] == '*' && last_c != '\'') { replacement_arg[k++] = '#'; replacement_arg[k++] = '?';