• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

POSIX.1 National Language Support API for MinGW


Commit MetaInfo

Revisionbc03c176d28c38725ebca9a47b53417fd4d92d80 (tree)
Zeit2007-05-12 04:56:17
AutorKeith Marshall <keithmarshall@user...>
CommiterKeith Marshall

Log Message

Avoid attempt to read input again, after EOF detected.

Ändern Zusammenfassung

Diff

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
11 2007-05-11 Keith Marshall <keithmarshall@users.sourceforge.net>
22
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+
313 Avoid calling `iconv' with unintialised codeset converter.
414
515 * mcsource.c (mc_default_codeset): New static function.
--- a/mcsource.c
+++ b/mcsource.c
@@ -204,8 +204,8 @@ struct msgdict *mc_source( const char *input )
204204 {
205205 # define CODESET_DECLARED codeset_decl_src, codeset_decl_lineno
206206
207- int fd, count;
208207 long accumulator;
208+ int fd, input_fd, count;
209209 char buf[BUFSIZ], keyword[64];
210210 char *id;
211211
@@ -230,11 +230,11 @@ struct msgdict *mc_source( const char *input )
230230 const char *dev_stdin = "/dev/stdin";
231231 if( (strcmp( input, "-") == 0) || (strcmp( input, dev_stdin ) == 0) )
232232 {
233- fd = STDIN_FILENO;
233+ input_fd = fd = STDIN_FILENO;
234234 input = dev_stdin;
235235 }
236236
237- else if( (fd = open( input, O_RDONLY | O_BINARY )) < 0 )
237+ else if( (input_fd = fd = open( input, O_RDONLY | O_BINARY )) < 0 )
238238 return NULL;
239239
240240 dfprintf(( stderr, "\n%s:new source file\n%s:", input, input ));
@@ -242,7 +242,7 @@ struct msgdict *mc_source( const char *input )
242242 return NULL;
243243
244244 msgloc = (off_t)(0);
245- while( (count = read( fd, buf, sizeof( buf ) )) > 0 )
245+ while( (fd >= 0) && ((count = read( fd, buf, sizeof( buf ) )) > 0) )
246246 {
247247 char *p = buf;
248248 int high_water_mark = count - ( count >> 2 );
@@ -795,12 +795,15 @@ struct msgdict *mc_source( const char *input )
795795 */
796796 if( (p - buf) > high_water_mark )
797797 {
798+ int ref;
798799 char *copyptr;
799800 for( copyptr = buf; count; count-- )
800801 *copyptr++ = *p++;
801- p = buf; count = copyptr - p;
802+ p = buf; ref = count = copyptr - p;
802803 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;
804807 dfprintf(( stderr, "; read new input: count adjusted to %u byte%s", count, count == 1 ? "" : "s" ));
805808 high_water_mark = count - ( count >> 2 );
806809 }
@@ -872,7 +875,11 @@ struct msgdict *mc_source( const char *input )
872875 }
873876 dfputc(( L'\n', stderr ));
874877
878+ /* We are done with the current input source;
879+ * close its file descriptor, and return the message list.
880+ */
881+ close( input_fd );
875882 return head;
876883 }
877884
878-/* $RCSfile$Revision: 1.2 $: end of file */
885+/* $RCSfile$Revision: 1.3 $: end of file */