POSIX.1 National Language Support API for MinGW
Revisión | bc03c176d28c38725ebca9a47b53417fd4d92d80 (tree) |
---|---|
Tiempo | 2007-05-12 04:56:17 |
Autor | Keith Marshall <keithmarshall@user...> |
Commiter | Keith Marshall |
Avoid attempt to read input again, after EOF detected.
@@ -1,5 +1,15 @@ | ||
1 | 1 | 2007-05-11 Keith Marshall <keithmarshall@users.sourceforge.net> |
2 | 2 | |
3 | + Avoid attempt to read input again, after EOF detected; this caused | |
4 | + strange behaviour if processing an interactive input stream. | |
5 | + | |
6 | + * mcsource.c (mc_source): New local variable `input_fd'; assign it as | |
7 | + a duplicate of `fd'. Set `fd' to -1, when EOF detected; don't do any | |
8 | + more reads, after `fd' set to this invalid value. Call `close' on | |
9 | + `input_fd', before return. | |
10 | + | |
11 | +2007-05-11 Keith Marshall <keithmarshall@users.sourceforge.net> | |
12 | + | |
3 | 13 | Avoid calling `iconv' with unintialised codeset converter. |
4 | 14 | |
5 | 15 | * mcsource.c (mc_default_codeset): New static function. |
@@ -204,8 +204,8 @@ struct msgdict *mc_source( const char *input ) | ||
204 | 204 | { |
205 | 205 | # define CODESET_DECLARED codeset_decl_src, codeset_decl_lineno |
206 | 206 | |
207 | - int fd, count; | |
208 | 207 | long accumulator; |
208 | + int fd, input_fd, count; | |
209 | 209 | char buf[BUFSIZ], keyword[64]; |
210 | 210 | char *id; |
211 | 211 |
@@ -230,11 +230,11 @@ struct msgdict *mc_source( const char *input ) | ||
230 | 230 | const char *dev_stdin = "/dev/stdin"; |
231 | 231 | if( (strcmp( input, "-") == 0) || (strcmp( input, dev_stdin ) == 0) ) |
232 | 232 | { |
233 | - fd = STDIN_FILENO; | |
233 | + input_fd = fd = STDIN_FILENO; | |
234 | 234 | input = dev_stdin; |
235 | 235 | } |
236 | 236 | |
237 | - else if( (fd = open( input, O_RDONLY | O_BINARY )) < 0 ) | |
237 | + else if( (input_fd = fd = open( input, O_RDONLY | O_BINARY )) < 0 ) | |
238 | 238 | return NULL; |
239 | 239 | |
240 | 240 | dfprintf(( stderr, "\n%s:new source file\n%s:", input, input )); |
@@ -242,7 +242,7 @@ struct msgdict *mc_source( const char *input ) | ||
242 | 242 | return NULL; |
243 | 243 | |
244 | 244 | msgloc = (off_t)(0); |
245 | - while( (count = read( fd, buf, sizeof( buf ) )) > 0 ) | |
245 | + while( (fd >= 0) && ((count = read( fd, buf, sizeof( buf ) )) > 0) ) | |
246 | 246 | { |
247 | 247 | char *p = buf; |
248 | 248 | int high_water_mark = count - ( count >> 2 ); |
@@ -795,12 +795,15 @@ struct msgdict *mc_source( const char *input ) | ||
795 | 795 | */ |
796 | 796 | if( (p - buf) > high_water_mark ) |
797 | 797 | { |
798 | + int ref; | |
798 | 799 | char *copyptr; |
799 | 800 | for( copyptr = buf; count; count-- ) |
800 | 801 | *copyptr++ = *p++; |
801 | - p = buf; count = copyptr - p; | |
802 | + p = buf; ref = count = copyptr - p; | |
802 | 803 | dfprintf(( stderr, "\n%s:%u:input count depleted: %u byte%s remaining", input, linenum, count, count == 1 ? "" : "s" )); |
803 | - count += read( fd, copyptr, sizeof( buf ) - count ); | |
804 | + if( (fd >= 0) | |
805 | + && (ref == (count += read( fd, copyptr, sizeof( buf ) - count ))) ) | |
806 | + fd = -1; | |
804 | 807 | dfprintf(( stderr, "; read new input: count adjusted to %u byte%s", count, count == 1 ? "" : "s" )); |
805 | 808 | high_water_mark = count - ( count >> 2 ); |
806 | 809 | } |
@@ -872,7 +875,11 @@ struct msgdict *mc_source( const char *input ) | ||
872 | 875 | } |
873 | 876 | dfputc(( L'\n', stderr )); |
874 | 877 | |
878 | + /* We are done with the current input source; | |
879 | + * close its file descriptor, and return the message list. | |
880 | + */ | |
881 | + close( input_fd ); | |
875 | 882 | return head; |
876 | 883 | } |
877 | 884 | |
878 | -/* $RCSfile$Revision: 1.2 $: end of file */ | |
885 | +/* $RCSfile$Revision: 1.3 $: end of file */ |