mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-12-25 23:21:26 +03:00
various: handle return values of write calls
This commit is contained in:
parent
4ea1866f7d
commit
dff8d0f726
14
nanohttp.c
14
nanohttp.c
@ -1615,6 +1615,7 @@ xmlNanoHTTPFetch(const char *URL, const char *filename, char **contentType) {
|
||||
char *buf = NULL;
|
||||
int fd;
|
||||
int len;
|
||||
int ret = 0;
|
||||
|
||||
if (filename == NULL) return(-1);
|
||||
ctxt = xmlNanoHTTPOpen(URL, contentType);
|
||||
@ -1636,12 +1637,14 @@ xmlNanoHTTPFetch(const char *URL, const char *filename, char **contentType) {
|
||||
|
||||
xmlNanoHTTPFetchContent( ctxt, &buf, &len );
|
||||
if ( len > 0 ) {
|
||||
write(fd, buf, len);
|
||||
if (write(fd, buf, len) == -1) {
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
xmlNanoHTTPClose(ctxt);
|
||||
close(fd);
|
||||
return(0);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
#ifdef LIBXML_OUTPUT_ENABLED
|
||||
@ -1660,6 +1663,7 @@ xmlNanoHTTPSave(void *ctxt, const char *filename) {
|
||||
char *buf = NULL;
|
||||
int fd;
|
||||
int len;
|
||||
int ret = 0;
|
||||
|
||||
if ((ctxt == NULL) || (filename == NULL)) return(-1);
|
||||
|
||||
@ -1675,12 +1679,14 @@ xmlNanoHTTPSave(void *ctxt, const char *filename) {
|
||||
|
||||
xmlNanoHTTPFetchContent( ctxt, &buf, &len );
|
||||
if ( len > 0 ) {
|
||||
write(fd, buf, len);
|
||||
if (write(fd, buf, len) == -1) {
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
xmlNanoHTTPClose(ctxt);
|
||||
close(fd);
|
||||
return(0);
|
||||
return(ret);
|
||||
}
|
||||
#endif /* LIBXML_OUTPUT_ENABLED */
|
||||
|
||||
|
@ -104,7 +104,9 @@ test_c14n(const char* xml_filename, int with_comments, int mode,
|
||||
with_comments, &result);
|
||||
if(ret >= 0) {
|
||||
if(result != NULL) {
|
||||
write(1, result, ret);
|
||||
if (write(STDOUT_FILENO, result, ret) == -1) {
|
||||
fprintf(stderr, "Can't write data\n");
|
||||
}
|
||||
xmlFree(result);
|
||||
}
|
||||
} else {
|
||||
|
16
xmllint.c
16
xmllint.c
@ -2550,7 +2550,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
|
||||
|
||||
size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_1_0, NULL, 1, &result);
|
||||
if (size >= 0) {
|
||||
write(1, result, size);
|
||||
if (write(1, result, size) == -1) {
|
||||
fprintf(stderr, "Can't write data\n");
|
||||
}
|
||||
xmlFree(result);
|
||||
} else {
|
||||
fprintf(stderr, "Failed to canonicalize\n");
|
||||
@ -2562,7 +2564,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
|
||||
|
||||
size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_1_1, NULL, 1, &result);
|
||||
if (size >= 0) {
|
||||
write(1, result, size);
|
||||
if (write(1, result, size) == -1) {
|
||||
fprintf(stderr, "Can't write data\n");
|
||||
}
|
||||
xmlFree(result);
|
||||
} else {
|
||||
fprintf(stderr, "Failed to canonicalize\n");
|
||||
@ -2575,7 +2579,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
|
||||
|
||||
size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_EXCLUSIVE_1_0, NULL, 1, &result);
|
||||
if (size >= 0) {
|
||||
write(1, result, size);
|
||||
if (write(1, result, size) == -1) {
|
||||
fprintf(stderr, "Can't write data\n");
|
||||
}
|
||||
xmlFree(result);
|
||||
} else {
|
||||
fprintf(stderr, "Failed to canonicalize\n");
|
||||
@ -2604,7 +2610,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
|
||||
fprintf(stderr, "Failed to save\n");
|
||||
progresult = XMLLINT_ERR_OUT;
|
||||
} else {
|
||||
write(1, result, len);
|
||||
if (write(1, result, len) == -1) {
|
||||
fprintf(stderr, "Can't write data\n");
|
||||
}
|
||||
xmlFree(result);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user