MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlOutputDefaultOpen

Function xmlOutputDefaultOpen

ThirdParty/libxml2/vtklibxml2/xmlIO.c:1286–1331  ·  view source on GitHub ↗

* xmlOutputDefaultOpen: * @buf: input buffer to be filled * @filename: filename or URI * @compression: compression level or 0 * @is_file_uri: whether filename is a file URI * * Returns an xmlParserErrors code. */

Source from the content-addressed store, hash-verified

1284 * Returns an xmlParserErrors code.
1285 */
1286static int
1287xmlOutputDefaultOpen(xmlOutputBufferPtr buf, const char *filename,
1288 int compression) {
1289 int fd;
1290
1291 (void) compression;
1292
1293 if (!strcmp(filename, "-")) {
1294 fd = dup(STDOUT_FILENO);
1295
1296 if (fd < 0)
1297 return(xmlIOErr(0, "dup()"));
1298 } else {
1299 int ret;
1300
1301 ret = xmlFdOpen(filename, /* write */ 1, &fd);
1302 if (ret != XML_ERR_OK)
1303 return(ret);
1304 }
1305
1306#ifdef LIBXML_ZLIB_ENABLED
1307 if ((compression > 0) && (compression <= 9)) {
1308 gzFile gzStream;
1309 char mode[15];
1310
1311 snprintf(mode, sizeof(mode), "wb%d", compression);
1312 gzStream = gzdopen(fd, mode);
1313
1314 if (gzStream == NULL) {
1315 close(fd);
1316 return(xmlIOErr(XML_IO_UNKNOWN, "gzdopen()"));
1317 }
1318
1319 buf->context = gzStream;
1320 buf->writecallback = xmlGzfileWrite;
1321 buf->closecallback = xmlGzfileClose;
1322
1323 return(XML_ERR_OK);
1324 }
1325#endif /* LIBXML_ZLIB_ENABLED */
1326
1327 buf->context = (void *) (ptrdiff_t) fd;
1328 buf->writecallback = xmlFdWrite;
1329 buf->closecallback = xmlFdClose;
1330 return(XML_ERR_OK);
1331}
1332#endif
1333
1334/**

Callers 1

Calls 4

xmlIOErrFunction · 0.85
xmlFdOpenFunction · 0.85
gzdopenFunction · 0.85
closeFunction · 0.85

Tested by

no test coverage detected