Mercurial > hg > xemacs-beta
comparison src/lstream.c @ 5795:d2c0ff38ad5c
Report lstream errors when encoding/decoding.
See <CAHCOHQ=FAieD-2nP303fMvwkii8HK2z+X7gRZ2+4PH1CA5_-NA@mail.gmail.com> in
xemacs-patches.
author | Jerry James <james@xemacs.org> |
---|---|
date | Wed, 14 May 2014 14:16:24 -0600 |
parents | 7343a186a475 |
children | a216b3c2b09e |
comparison
equal
deleted
inserted
replaced
5794:2d20d57d4e7b | 5795:d2c0ff38ad5c |
---|---|
740 Lstream_read (Lstream *lstr, void *data, Bytecount size) | 740 Lstream_read (Lstream *lstr, void *data, Bytecount size) |
741 { | 741 { |
742 return Lstream_read_1 (lstr, data, size, 0); | 742 return Lstream_read_1 (lstr, data, size, 0); |
743 } | 743 } |
744 | 744 |
745 int | |
746 Lstream_errno (Lstream *lstr) | |
747 { | |
748 return (lstr->imp->error) ? (lstr->imp->error) (lstr) : 0; | |
749 } | |
750 | |
745 Charcount | 751 Charcount |
746 Lstream_character_tell (Lstream *lstr) | 752 Lstream_character_tell (Lstream *lstr) |
747 { | 753 { |
748 Charcount ctell = lstr->imp->character_tell ? | 754 Charcount ctell = lstr->imp->character_tell ? |
749 lstr->imp->character_tell (lstr) : -1; | 755 lstr->imp->character_tell (lstr) : -1; |
1116 Ibyte eof_char; | 1122 Ibyte eof_char; |
1117 int starting_pos; | 1123 int starting_pos; |
1118 int current_pos; | 1124 int current_pos; |
1119 int end_pos; | 1125 int end_pos; |
1120 int chars_sans_newline; | 1126 int chars_sans_newline; |
1127 int saved_errno; | |
1121 unsigned int closing :1; | 1128 unsigned int closing :1; |
1122 unsigned int allow_quit :1; | 1129 unsigned int allow_quit :1; |
1123 unsigned int blocked_ok :1; | 1130 unsigned int blocked_ok :1; |
1124 unsigned int pty_flushing :1; | 1131 unsigned int pty_flushing :1; |
1125 unsigned int blocking_error_p :1; | 1132 unsigned int blocking_error_p :1; |
1144 fstr->allow_quit = !!(flags & LSTR_ALLOW_QUIT); | 1151 fstr->allow_quit = !!(flags & LSTR_ALLOW_QUIT); |
1145 fstr->blocked_ok = !!(flags & LSTR_BLOCKED_OK); | 1152 fstr->blocked_ok = !!(flags & LSTR_BLOCKED_OK); |
1146 fstr->pty_flushing = !!(flags & LSTR_PTY_FLUSHING); | 1153 fstr->pty_flushing = !!(flags & LSTR_PTY_FLUSHING); |
1147 fstr->blocking_error_p = 0; | 1154 fstr->blocking_error_p = 0; |
1148 fstr->chars_sans_newline = 0; | 1155 fstr->chars_sans_newline = 0; |
1156 fstr->saved_errno = 0; | |
1149 fstr->starting_pos = lseek (filedesc, offset, SEEK_CUR); | 1157 fstr->starting_pos = lseek (filedesc, offset, SEEK_CUR); |
1150 fstr->current_pos = max (fstr->starting_pos, 0); | 1158 fstr->current_pos = max (fstr->starting_pos, 0); |
1151 if (count < 0) | 1159 if (count < 0) |
1152 fstr->end_pos = -1; | 1160 fstr->end_pos = -1; |
1153 else | 1161 else |
1190 static Bytecount | 1198 static Bytecount |
1191 filedesc_reader (Lstream *stream, unsigned char *data, Bytecount size) | 1199 filedesc_reader (Lstream *stream, unsigned char *data, Bytecount size) |
1192 { | 1200 { |
1193 Bytecount nread; | 1201 Bytecount nread; |
1194 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream); | 1202 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream); |
1203 str->saved_errno = 0; | |
1195 if (str->end_pos >= 0) | 1204 if (str->end_pos >= 0) |
1196 size = min (size, (Bytecount) (str->end_pos - str->current_pos)); | 1205 size = min (size, (Bytecount) (str->end_pos - str->current_pos)); |
1197 nread = str->allow_quit ? | 1206 nread = str->allow_quit ? |
1198 read_allowing_quit (str->fd, data, size) : | 1207 read_allowing_quit (str->fd, data, size) : |
1199 retry_read (str->fd, data, size); | 1208 retry_read (str->fd, data, size); |
1200 if (nread > 0) | 1209 if (nread > 0) |
1201 str->current_pos += nread; | 1210 str->current_pos += nread; |
1202 if (nread == 0) | 1211 if (nread == 0) |
1203 return 0; /* LSTREAM_EOF; */ | 1212 return 0; /* LSTREAM_EOF; */ |
1204 if (nread < 0) | 1213 if (nread < 0) |
1205 return LSTREAM_ERROR; | 1214 { |
1215 str->saved_errno = errno; | |
1216 return LSTREAM_ERROR; | |
1217 } | |
1206 return nread; | 1218 return nread; |
1207 } | 1219 } |
1208 | 1220 |
1209 static int | 1221 static int |
1210 errno_would_block_p (int val) | 1222 errno_would_block_p (int val) |
1225 Bytecount size) | 1237 Bytecount size) |
1226 { | 1238 { |
1227 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream); | 1239 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream); |
1228 Bytecount retval; | 1240 Bytecount retval; |
1229 int need_newline = 0; | 1241 int need_newline = 0; |
1242 | |
1243 str->saved_errno = 0; | |
1230 | 1244 |
1231 /* This function would be simple if it were not for the blasted | 1245 /* This function would be simple if it were not for the blasted |
1232 PTY max-bytes stuff. Why the hell can't they just have written | 1246 PTY max-bytes stuff. Why the hell can't they just have written |
1233 the PTY drivers right so this problem doesn't exist? | 1247 the PTY drivers right so this problem doesn't exist? |
1234 | 1248 |
1264 str->blocking_error_p = 1; | 1278 str->blocking_error_p = 1; |
1265 return 0; | 1279 return 0; |
1266 } | 1280 } |
1267 str->blocking_error_p = 0; | 1281 str->blocking_error_p = 0; |
1268 if (retval < 0) | 1282 if (retval < 0) |
1269 return LSTREAM_ERROR; | 1283 { |
1284 str->saved_errno = errno; | |
1285 return LSTREAM_ERROR; | |
1286 } | |
1270 /**** end non-PTY-crap ****/ | 1287 /**** end non-PTY-crap ****/ |
1271 | 1288 |
1272 if (str->pty_flushing) | 1289 if (str->pty_flushing) |
1273 { | 1290 { |
1274 str->chars_sans_newline += retval; | 1291 str->chars_sans_newline += retval; |
1296 { | 1313 { |
1297 str->blocking_error_p = 1; | 1314 str->blocking_error_p = 1; |
1298 return 0; | 1315 return 0; |
1299 } | 1316 } |
1300 else | 1317 else |
1301 return LSTREAM_ERROR; | 1318 { |
1319 str->saved_errno = errno; | |
1320 return LSTREAM_ERROR; | |
1321 } | |
1302 } | 1322 } |
1303 else | 1323 else |
1304 return retval; | 1324 return retval; |
1305 } | 1325 } |
1306 } | 1326 } |
1332 { | 1352 { |
1333 str->blocking_error_p = 1; | 1353 str->blocking_error_p = 1; |
1334 return 0; | 1354 return 0; |
1335 } | 1355 } |
1336 else | 1356 else |
1337 return LSTREAM_ERROR; | 1357 { |
1358 str->saved_errno = errno; | |
1359 return LSTREAM_ERROR; | |
1360 } | |
1338 } | 1361 } |
1339 else | 1362 else |
1340 return retval; | 1363 return retval; |
1341 } | 1364 } |
1342 } | 1365 } |
1343 | 1366 |
1344 return retval; | 1367 return retval; |
1368 } | |
1369 | |
1370 static int | |
1371 filedesc_error (Lstream *stream) | |
1372 { | |
1373 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream); | |
1374 return str->saved_errno; | |
1345 } | 1375 } |
1346 | 1376 |
1347 static int | 1377 static int |
1348 filedesc_rewinder (Lstream *stream) | 1378 filedesc_rewinder (Lstream *stream) |
1349 { | 1379 { |
1924 LSTREAM_HAS_METHOD (stdio, flusher); | 1954 LSTREAM_HAS_METHOD (stdio, flusher); |
1925 LSTREAM_HAS_METHOD (stdio, closer); | 1955 LSTREAM_HAS_METHOD (stdio, closer); |
1926 | 1956 |
1927 LSTREAM_HAS_METHOD (filedesc, reader); | 1957 LSTREAM_HAS_METHOD (filedesc, reader); |
1928 LSTREAM_HAS_METHOD (filedesc, writer); | 1958 LSTREAM_HAS_METHOD (filedesc, writer); |
1959 LSTREAM_HAS_METHOD (filedesc, error); | |
1929 LSTREAM_HAS_METHOD (filedesc, was_blocked_p); | 1960 LSTREAM_HAS_METHOD (filedesc, was_blocked_p); |
1930 LSTREAM_HAS_METHOD (filedesc, rewinder); | 1961 LSTREAM_HAS_METHOD (filedesc, rewinder); |
1931 LSTREAM_HAS_METHOD (filedesc, seekable_p); | 1962 LSTREAM_HAS_METHOD (filedesc, seekable_p); |
1932 LSTREAM_HAS_METHOD (filedesc, closer); | 1963 LSTREAM_HAS_METHOD (filedesc, closer); |
1933 | 1964 |