static status loadSyntaxTable(SyntaxTable t, IOSTREAM *fd, ClassDef def) { TRY(loadSlotsObject(t, fd, def)); t->table = alloc(FLAGS_SIZE(t)); t->context = alloc(CONTEXT_SIZE(t)); Sfread(t->table, sizeof(char), FLAGS_SIZE(t), fd); Sfread(t->context, sizeof(char), CONTEXT_SIZE(t), fd); swapBytesTable(t); succeed; }
XImage * readImageFile(Image image, IOSTREAM *fd) { unsigned char *data; int w, h; XImage *img=NULL; char hdr[64]; int hdrlen; long offset = Stell(fd); int fmt; hdrlen = Sfread(hdr, 1, sizeof(hdr), fd); Sseek(fd, offset, SIO_SEEK_SET); switch((fmt=image_type_from_data(hdr, hdrlen))) { case IMG_IS_UNKNOWN: case IMG_IS_XBM: case IMG_IS_SUNICON: if ( (data = read_bitmap_data(fd, &w, &h)) != NULL ) return CreateXImageFromData(data, w, h); if ( fmt != IMG_IS_UNKNOWN ) break; #ifdef HAVE_LIBJPEG case IMG_IS_JPEG: switch(staticColourReadJPEGFile(image, fd, &img)) { case IMG_OK: return img; case IMG_NOMEM: return NULL; default: break; } if ( (img=readJPEGFile(image, fd)) ) return img; if ( fmt != IMG_IS_UNKNOWN ) break; #endif #ifdef HAVE_LIBXPM #ifdef O_GIFTOXPM case IMG_IS_GIF: if ( (img=readGIFFile(image, fd)) ) return img; if ( fmt != IMG_IS_UNKNOWN ) break; #endif case IMG_IS_XPM: if ( (img=readXpmFile(image, fd)) ) return img; if ( fmt != IMG_IS_UNKNOWN ) break; #endif default: if ( fmt != IMG_IS_UNKNOWN ) { DEBUG(NAME_image, Cprintf("Image format %d not supported\n", fmt)); } } return NULL; }
static ssize_t /* decode */ chunked_read(void *handle, char *buf, size_t size) { chunked_context *ctx = handle; for(;;) { if ( ctx->avail > 0 ) /* data waiting */ { size_t max_rd = ctx->avail < size ? ctx->avail : size; ssize_t rc; if ( (rc = Sfread(buf, sizeof(char), max_rd, ctx->stream)) > 0 ) { ctx->avail -= rc; if ( ctx->avail == 0 ) { if ( Sgetc(ctx->stream) != '\r' || Sgetc(ctx->stream) != '\n' ) { Sseterr(ctx->chunked_stream, 0, "Chunk not followed by \\r\\n"); return -1; } } return rc; } else if ( rc == 0 ) { Sseterr(ctx->chunked_stream, 0, "Unexpected EOF in chunked data"); return -1; } else { return -1; } } else { char hdr[MAXHDR]; char *s; if ( (s = Sfgets(hdr, sizeof(hdr), ctx->stream)) ) { char *ehdr; long len; errno = 0; len = strtol(hdr, &ehdr, 16); if ( errno || len < 0 ) { Sseterr(ctx->chunked_stream, 0, "Bad chunk length"); return -1; } if ( len == 0 ) { do { s = Sfgets(hdr, sizeof(hdr), ctx->stream); } while ( s && strcmp(s, "\r\n") != 0 ); if ( s ) return 0; Sseterr(ctx->chunked_stream, 0, "Bad end-of-stream"); return -1; } ctx->avail = len; /*continue*/ } } } }
static ssize_t /* range-limited read */ range_read(void *handle, char *buf, size_t size) { range_context *ctx = handle; size_t max_rd; ssize_t rd; if ( ctx->read == ctx->size ) return 0; if ( ctx->size - ctx->read < size ) max_rd = ctx->size - ctx->read; else max_rd = size; if ( (rd = Sfread(buf, sizeof(char), max_rd, ctx->stream)) >= 0 ) { ctx->read += rd; return rd; } return rd; }