static int resetProlog(int clear_stacks) { GET_LD IOSTREAM *in = Suser_input; if ( Sferror(in) ) { Sclearerr(in); LD->prompt.next = TRUE; } Scurin = in; Scurout = Suser_output; PL_clear_exception(); resetTracer(); if ( clear_stacks ) { if ( !LD->gvar.nb_vars ) /* we would loose nb_setval/2 vars */ emptyStacks(); gc_status.blocked = 0; LD->shift_status.blocked = 0; LD->in_arithmetic = 0; LD->in_print_message = 0; } #ifdef O_LIMIT_DEPTH depth_limit = (uintptr_t)DEPTH_NO_LIMIT; #endif updateAlerted(LD); return TRUE; }
term_destination (j_compress_ptr cinfo) { my_dest_ptr dest = (my_dest_ptr) cinfo->dest; size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer; /* Write any data remaining in the buffer */ if (datacount > 0) { if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount) ERREXIT(cinfo, JERR_FILE_WRITE); } Sflush(dest->outfile); /* Make sure we wrote the output file OK */ if (Sferror(dest->outfile)) ERREXIT(cinfo, JERR_FILE_WRITE); }
static ssize_t /* decode */ chunked_read(void *handle, char *buf, size_t size) { chunked_context *ctx = handle; if ( ctx->eof_seen ) return 0; 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 ) { ctx->eof_seen = TRUE; return 0; } Sseterr(ctx->chunked_stream, 0, "Bad end-of-stream"); return -1; } ctx->avail = len; /*continue*/ } else { if ( !Sferror(ctx->stream) ) Sseterr(ctx->chunked_stream, 0, "Unexpected EOF in chunked header"); return -1; } } } }