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
18
nanohttp.c
18
nanohttp.c
@ -1615,7 +1615,8 @@ xmlNanoHTTPFetch(const char *URL, const char *filename, char **contentType) {
|
|||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
int fd;
|
int fd;
|
||||||
int len;
|
int len;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
if (filename == NULL) return(-1);
|
if (filename == NULL) return(-1);
|
||||||
ctxt = xmlNanoHTTPOpen(URL, contentType);
|
ctxt = xmlNanoHTTPOpen(URL, contentType);
|
||||||
if (ctxt == NULL) return(-1);
|
if (ctxt == NULL) return(-1);
|
||||||
@ -1636,12 +1637,14 @@ xmlNanoHTTPFetch(const char *URL, const char *filename, char **contentType) {
|
|||||||
|
|
||||||
xmlNanoHTTPFetchContent( ctxt, &buf, &len );
|
xmlNanoHTTPFetchContent( ctxt, &buf, &len );
|
||||||
if ( len > 0 ) {
|
if ( len > 0 ) {
|
||||||
write(fd, buf, len);
|
if (write(fd, buf, len) == -1) {
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlNanoHTTPClose(ctxt);
|
xmlNanoHTTPClose(ctxt);
|
||||||
close(fd);
|
close(fd);
|
||||||
return(0);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LIBXML_OUTPUT_ENABLED
|
#ifdef LIBXML_OUTPUT_ENABLED
|
||||||
@ -1660,7 +1663,8 @@ xmlNanoHTTPSave(void *ctxt, const char *filename) {
|
|||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
int fd;
|
int fd;
|
||||||
int len;
|
int len;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
if ((ctxt == NULL) || (filename == NULL)) return(-1);
|
if ((ctxt == NULL) || (filename == NULL)) return(-1);
|
||||||
|
|
||||||
if (!strcmp(filename, "-"))
|
if (!strcmp(filename, "-"))
|
||||||
@ -1675,12 +1679,14 @@ xmlNanoHTTPSave(void *ctxt, const char *filename) {
|
|||||||
|
|
||||||
xmlNanoHTTPFetchContent( ctxt, &buf, &len );
|
xmlNanoHTTPFetchContent( ctxt, &buf, &len );
|
||||||
if ( len > 0 ) {
|
if ( len > 0 ) {
|
||||||
write(fd, buf, len);
|
if (write(fd, buf, len) == -1) {
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlNanoHTTPClose(ctxt);
|
xmlNanoHTTPClose(ctxt);
|
||||||
close(fd);
|
close(fd);
|
||||||
return(0);
|
return(ret);
|
||||||
}
|
}
|
||||||
#endif /* LIBXML_OUTPUT_ENABLED */
|
#endif /* LIBXML_OUTPUT_ENABLED */
|
||||||
|
|
||||||
|
@ -104,8 +104,10 @@ test_c14n(const char* xml_filename, int with_comments, int mode,
|
|||||||
with_comments, &result);
|
with_comments, &result);
|
||||||
if(ret >= 0) {
|
if(ret >= 0) {
|
||||||
if(result != NULL) {
|
if(result != NULL) {
|
||||||
write(1, result, ret);
|
if (write(STDOUT_FILENO, result, ret) == -1) {
|
||||||
xmlFree(result);
|
fprintf(stderr, "Can't write data\n");
|
||||||
|
}
|
||||||
|
xmlFree(result);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,"Error: failed to canonicalize XML file \"%s\" (ret=%d)\n", xml_filename, ret);
|
fprintf(stderr,"Error: failed to canonicalize XML file \"%s\" (ret=%d)\n", xml_filename, ret);
|
||||||
|
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);
|
size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_1_0, NULL, 1, &result);
|
||||||
if (size >= 0) {
|
if (size >= 0) {
|
||||||
write(1, result, size);
|
if (write(1, result, size) == -1) {
|
||||||
|
fprintf(stderr, "Can't write data\n");
|
||||||
|
}
|
||||||
xmlFree(result);
|
xmlFree(result);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to canonicalize\n");
|
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);
|
size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_1_1, NULL, 1, &result);
|
||||||
if (size >= 0) {
|
if (size >= 0) {
|
||||||
write(1, result, size);
|
if (write(1, result, size) == -1) {
|
||||||
|
fprintf(stderr, "Can't write data\n");
|
||||||
|
}
|
||||||
xmlFree(result);
|
xmlFree(result);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to canonicalize\n");
|
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);
|
size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_EXCLUSIVE_1_0, NULL, 1, &result);
|
||||||
if (size >= 0) {
|
if (size >= 0) {
|
||||||
write(1, result, size);
|
if (write(1, result, size) == -1) {
|
||||||
|
fprintf(stderr, "Can't write data\n");
|
||||||
|
}
|
||||||
xmlFree(result);
|
xmlFree(result);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to canonicalize\n");
|
fprintf(stderr, "Failed to canonicalize\n");
|
||||||
@ -2604,7 +2610,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
|
|||||||
fprintf(stderr, "Failed to save\n");
|
fprintf(stderr, "Failed to save\n");
|
||||||
progresult = XMLLINT_ERR_OUT;
|
progresult = XMLLINT_ERR_OUT;
|
||||||
} else {
|
} else {
|
||||||
write(1, result, len);
|
if (write(1, result, len) == -1) {
|
||||||
|
fprintf(stderr, "Can't write data\n");
|
||||||
|
}
|
||||||
xmlFree(result);
|
xmlFree(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user