Mercurial > noffle
comparison src/protocol.c @ 250:93d5d8b098da noffle
[svn] *** empty log message ***
author | mirkol |
---|---|
date | Wed, 05 Jun 2002 23:03:44 +0100 |
parents | 0340b9c17edc |
children | 030c41dfd9ba |
comparison
equal
deleted
inserted
replaced
249:0340b9c17edc | 250:93d5d8b098da |
---|---|
1 /* | 1 /* |
2 protocol.c | 2 protocol.c |
3 | 3 |
4 $Id: protocol.c 381 2002-05-14 14:25:45Z mirkol $ | 4 $Id: protocol.c 382 2002-06-05 22:03:44Z mirkol $ |
5 */ | 5 */ |
6 | 6 |
7 #if HAVE_CONFIG_H | 7 #if HAVE_CONFIG_H |
8 #include <config.h> | 8 #include <config.h> |
9 #endif | 9 #endif |
35 Prt_getLn( Str line, FILE *f, int timeoutSeconds ) | 35 Prt_getLn( Str line, FILE *f, int timeoutSeconds ) |
36 { | 36 { |
37 size_t len; | 37 size_t len; |
38 char *ret; | 38 char *ret; |
39 sig_t oldHandler = NULL; | 39 sig_t oldHandler = NULL; |
40 int line_too_long; | |
40 | 41 |
41 if ( timeoutSeconds >= 0 ) | 42 if ( timeoutSeconds >= 0 ) |
42 { | 43 { |
43 oldHandler = Utl_installSignalHandler( SIGALRM, readAlarm ); | 44 oldHandler = Utl_installSignalHandler( SIGALRM, readAlarm ); |
44 if ( oldHandler == SIG_ERR ) | 45 if ( oldHandler == SIG_ERR ) |
60 Utl_installSignalHandler( SIGALRM, oldHandler ); | 61 Utl_installSignalHandler( SIGALRM, oldHandler ); |
61 } | 62 } |
62 if ( ret == NULL ) | 63 if ( ret == NULL ) |
63 return FALSE; | 64 return FALSE; |
64 len = strlen( line ); | 65 len = strlen( line ); |
65 if ( len > 0 && line[ len - 1 ] == '\n' ) | 66 if ( len > 0 ) |
66 { | 67 { |
67 line[ len - 1 ] = '\0'; | 68 if ( line[ len - 1 ] == '\n' ) |
68 if ( len > 1 && line[ len - 2 ] == '\r' ) | 69 { |
69 line[ len - 2 ] = '\0'; | 70 line[ len - 1 ] = '\0'; |
71 if ( len > 1 && line[ len - 2 ] == '\r' ) | |
72 line[ len - 2 ] = '\0'; | |
73 } | |
74 else | |
75 { | |
76 /* line too long, skip the rest */ | |
77 if( len == MAXCHAR ) | |
78 { | |
79 Log_err( "Line too long:" ); | |
80 do | |
81 { | |
82 line_too_long = fgetc( f ); | |
83 } | |
84 while( line_too_long == EOF || line_too_long == '\n' ); | |
85 } | |
86 else | |
87 /* EOF occured in line, skip line. */ | |
88 { | |
89 Log_err( "Ignoring incomplete line %s", line); | |
90 return FALSE; | |
91 } | |
92 } | |
70 } | 93 } |
71 Log_dbg( LOG_DBG_PROTOCOL, "[R] %s", line ); | 94 Log_dbg( LOG_DBG_PROTOCOL, "[R] %s", line ); |
72 return TRUE; | 95 return TRUE; |
73 } | 96 } |
74 | 97 |