diff options
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 69 |
1 files changed, 39 insertions, 30 deletions
@@ -677,6 +677,7 @@ readHeader(URLFile *uf, Buffer *newBuf, int thru, ParsedURL *pu) #endif init_stream(&f, SCM_LOCAL, newStrStream(src)); loadHTMLstream(&f, newBuf, NULL, TRUE); + UFclose(&f); for (l = newBuf->lastLine; l && l->real_linenumber; l = l->prev) l->real_linenumber = 0; @@ -2267,10 +2268,11 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, if (header_string) header_string = NULL; #ifdef USE_NNTP - if (f.scheme == SCM_NNTP || f.scheme == SCM_NEWS) + if (b && b != NO_BUFFER && (f.scheme == SCM_NNTP || f.scheme == SCM_NEWS)) reAnchorNewsheader(b); #endif - preFormUpdateBuffer(b); + if (b && b != NO_BUFFER) + preFormUpdateBuffer(b); TRAP_OFF; return b; } @@ -4339,15 +4341,15 @@ getMetaRefreshParam(char *q, Str *refresh_uri) while (*q) { if (!strncasecmp(q, "url=", 4)) { q += 4; - if (*q == '\"') /* " */ + if (*q == '\"' || *q == '\'') /* " or ' */ q++; r = q; while (*r && !IS_SPACE(*r) && *r != ';') r++; s_tmp = Strnew_charp_n(q, r - q); - if (s_tmp->ptr[s_tmp->length - 1] == '\"') { /* " - */ + if (s_tmp->ptr[s_tmp->length - 1] == '\"' /* " */ + || s_tmp->ptr[s_tmp->length - 1] == '\'') { /* ' */ s_tmp->length--; s_tmp->ptr[s_tmp->length] = '\0'; } @@ -7237,16 +7239,17 @@ loadHTMLString(Str page) MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL; Buffer *newBuf; + init_stream(&f, SCM_LOCAL, newStrStream(page)); + newBuf = newBuffer(INIT_BUFFER_WIDTH); if (SETJMP(AbortLoading) != 0) { TRAP_OFF; discardBuffer(newBuf); + UFclose(&f); return NULL; } TRAP_ON; - init_stream(&f, SCM_LOCAL, newStrStream(page)); - #ifdef USE_M17N newBuf->document_charset = InnerCharset; #endif @@ -7256,6 +7259,7 @@ loadHTMLString(Str page) #endif TRAP_OFF; + UFclose(&f); newBuf->topLine = newBuf->firstLine; newBuf->lastLine = newBuf->currentLine; newBuf->currentLine = newBuf->firstLine; @@ -7485,15 +7489,13 @@ loadImageBuffer(URLFile *uf, Buffer *newBuf) !stat(cache->file, &st)) goto image_buffer; - TRAP_ON; if (IStype(uf->stream) != IST_ENCODED) uf->stream = newEncodedStream(uf->stream, uf->encoding); + TRAP_ON; if (save2tmp(*uf, cache->file) < 0) { - UFclose(uf); TRAP_OFF; return NULL; } - UFclose(uf); TRAP_OFF; cache->loaded = IMG_FLAG_LOADED; @@ -7513,6 +7515,7 @@ loadImageBuffer(URLFile *uf, Buffer *newBuf) init_stream(&f, SCM_LOCAL, newStrStream(tmp)); loadHTMLstream(&f, newBuf, src, TRUE); + UFclose(&f); if (src) fclose(src); @@ -7908,6 +7911,8 @@ save2tmp(URLFile uf, char *tmpf) clen_t linelen = 0, trbyte = 0; MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL; static JMP_BUF env_bak; + volatile int retval = 0; + char *volatile buf = NULL; ff = fopen(tmpf, "wb"); if (ff == NULL) { @@ -7944,25 +7949,25 @@ save2tmp(URLFile uf, char *tmpf) else #endif /* USE_NNTP */ { - Str buf = Strnew_size(SAVE_BUF_SIZE); - while (UFread(&uf, buf, SAVE_BUF_SIZE)) { - if (Strfputs(buf, ff) != buf->length) { - bcopy(env_bak, AbortLoading, sizeof(JMP_BUF)); - TRAP_OFF; - fclose(ff); - current_content_length = 0; - return -2; + int count; + + buf = NewWithoutGC_N(char, SAVE_BUF_SIZE); + while ((count = ISread_n(uf.stream, buf, SAVE_BUF_SIZE)) > 0) { + if (fwrite(buf, 1, count, ff) != count) { + retval = -2; + goto _end; } - linelen += buf->length; + linelen += count; showProgress(&linelen, &trbyte); } } _end: bcopy(env_bak, AbortLoading, sizeof(JMP_BUF)); TRAP_OFF; + xfree(buf); fclose(ff); current_content_length = 0; - return 0; + return retval; } Buffer * @@ -8073,7 +8078,8 @@ _MoveFile(char *path1, char *path2) FILE *f2; int is_pipe; clen_t linelen = 0, trbyte = 0; - Str buf; + char *buf = NULL; + int count; f1 = openIS(path1); if (f1 == NULL) @@ -8091,12 +8097,13 @@ _MoveFile(char *path1, char *path2) return -1; } current_content_length = 0; - buf = Strnew_size(SAVE_BUF_SIZE); - while (ISread(f1, buf, SAVE_BUF_SIZE)) { - Strfputs(buf, f2); - linelen += buf->length; + buf = NewWithoutGC_N(char, SAVE_BUF_SIZE); + while ((count = ISread_n(f1, buf, SAVE_BUF_SIZE)) > 0) { + fwrite(buf, 1, count, f2); + linelen += count; showProgress(&linelen, &trbyte); } + xfree(buf); ISclose(f1); if (is_pipe) pclose(f2); @@ -8455,21 +8462,23 @@ uncompress_stream(URLFile *uf, char **src) } if (pid2 == 0) { /* child2 */ - Str buf = Strnew_size(SAVE_BUF_SIZE); + char *buf = NewWithoutGC_N(char, SAVE_BUF_SIZE); + int count; FILE *f = NULL; setup_child(TRUE, 2, UFfileno(uf)); if (tmpf) f = fopen(tmpf, "wb"); - while (UFread(uf, buf, SAVE_BUF_SIZE)) { - if (Strfputs(buf, stdout) < 0) + while ((count = ISread_n(uf->stream, buf, SAVE_BUF_SIZE)) > 0) { + if (fwrite(buf, 1, count, stdout) != count) + break; + if (f && fwrite(buf, 1, count, f) != count) break; - if (f) - Strfputs(buf, f); } UFclose(uf); if (f) fclose(f); + xfree(buf); exit(0); } /* child1 */ |