comparison src/lstream.c @ 440:8de8e3f6228a r21-2-28

Import from CVS: tag r21-2-28
author cvs
date Mon, 13 Aug 2007 11:33:38 +0200
parents a5df635868b2
children abe6d1db359e
comparison
equal deleted inserted replaced
439:357dd071b03c 440:8de8e3f6228a
470 } 470 }
471 471
472 /* If the stream is not line-buffered, then we can just call 472 /* If the stream is not line-buffered, then we can just call
473 Lstream_write_1(), which writes in chunks. Otherwise, we 473 Lstream_write_1(), which writes in chunks. Otherwise, we
474 repeatedly call Lstream_putc(), which knows how to handle 474 repeatedly call Lstream_putc(), which knows how to handle
475 line buffering. */ 475 line buffering. Returns number of bytes written. */
476 476
477 ssize_t 477 ssize_t
478 Lstream_write (Lstream *lstr, CONST void *data, size_t size) 478 Lstream_write (Lstream *lstr, CONST void *data, size_t size)
479 { 479 {
480 size_t i; 480 size_t i;
487 for (i = 0; i < size; i++) 487 for (i = 0; i < size; i++)
488 { 488 {
489 if (Lstream_putc (lstr, p[i]) < 0) 489 if (Lstream_putc (lstr, p[i]) < 0)
490 break; 490 break;
491 } 491 }
492 return i == 0 ? -1 : 0; 492 return i == 0 ? -1 : (ssize_t) i;
493 } 493 }
494 494
495 int 495 int
496 Lstream_was_blocked_p (Lstream *lstr) 496 Lstream_was_blocked_p (Lstream *lstr)
497 { 497 {
1253 1253
1254 DEFINE_LSTREAM_IMPLEMENTATION ("fixed-buffer", lstream_fixed_buffer, 1254 DEFINE_LSTREAM_IMPLEMENTATION ("fixed-buffer", lstream_fixed_buffer,
1255 sizeof (struct fixed_buffer_stream)); 1255 sizeof (struct fixed_buffer_stream));
1256 1256
1257 Lisp_Object 1257 Lisp_Object
1258 make_fixed_buffer_input_stream (CONST unsigned char *buf, size_t size) 1258 make_fixed_buffer_input_stream (CONST void *buf, size_t size)
1259 { 1259 {
1260 Lisp_Object obj; 1260 Lisp_Object obj;
1261 Lstream *lstr = Lstream_new (lstream_fixed_buffer, "r"); 1261 Lstream *lstr = Lstream_new (lstream_fixed_buffer, "r");
1262 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (lstr); 1262 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (lstr);
1263 str->inbuf = buf; 1263 str->inbuf = (const unsigned char *) buf;
1264 str->size = size; 1264 str->size = size;
1265 XSETLSTREAM (obj, lstr); 1265 XSETLSTREAM (obj, lstr);
1266 return obj; 1266 return obj;
1267 } 1267 }
1268 1268
1269 Lisp_Object 1269 Lisp_Object
1270 make_fixed_buffer_output_stream (unsigned char *buf, size_t size) 1270 make_fixed_buffer_output_stream (void *buf, size_t size)
1271 { 1271 {
1272 Lisp_Object obj; 1272 Lisp_Object obj;
1273 Lstream *lstr = Lstream_new (lstream_fixed_buffer, "w"); 1273 Lstream *lstr = Lstream_new (lstream_fixed_buffer, "w");
1274 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (lstr); 1274 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (lstr);
1275 str->outbuf = buf; 1275 str->outbuf = (unsigned char *) buf;
1276 str->size = size; 1276 str->size = size;
1277 XSETLSTREAM (obj, lstr); 1277 XSETLSTREAM (obj, lstr);
1278 return obj; 1278 return obj;
1279 } 1279 }
1280 1280