MCPcopy Create free account
hub / github.com/KhronosGroup/OpenCOLLADA / xmlShellSave

Function xmlShellSave

Externals/LibXML/debugXML.c:2572–2617  ·  view source on GitHub ↗

* xmlShellSave: * @ctxt: the shell context * @filename: the file name (optional) * @node: unused * @node2: unused * * Implements the XML shell function "save" * Write the current document to the filename, or it's original name * * Returns 0 or -1 in case of error */

Source from the content-addressed store, hash-verified

2570 * Returns 0 or -1 in case of error
2571 */
2572int
2573xmlShellSave(xmlShellCtxtPtr ctxt, char *filename,
2574 xmlNodePtr node ATTRIBUTE_UNUSED,
2575 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2576{
2577 if ((ctxt == NULL) || (ctxt->doc == NULL))
2578 return (-1);
2579 if ((filename == NULL) || (filename[0] == 0))
2580 filename = ctxt->filename;
2581 if (filename == NULL)
2582 return (-1);
2583#ifdef W_OK
2584 if (access((char *) filename, W_OK)) {
2585 xmlGenericError(xmlGenericErrorContext,
2586 "Cannot save to %s\n", filename);
2587 return (-1);
2588 }
2589#endif
2590 switch (ctxt->doc->type) {
2591 case XML_DOCUMENT_NODE:
2592 if (xmlSaveFile((char *) filename, ctxt->doc) < 0) {
2593 xmlGenericError(xmlGenericErrorContext,
2594 "Failed to save to %s\n", filename);
2595 }
2596 break;
2597 case XML_HTML_DOCUMENT_NODE:
2598#ifdef LIBXML_HTML_ENABLED
2599 if (htmlSaveFile((char *) filename, ctxt->doc) < 0) {
2600 xmlGenericError(xmlGenericErrorContext,
2601 "Failed to save to %s\n", filename);
2602 }
2603#else
2604 if (xmlSaveFile((char *) filename, ctxt->doc) < 0) {
2605 xmlGenericError(xmlGenericErrorContext,
2606 "Failed to save to %s\n", filename);
2607 }
2608#endif /* LIBXML_HTML_ENABLED */
2609 break;
2610 default:
2611 xmlGenericError(xmlGenericErrorContext,
2612 "To save to subparts of a document use the 'write' command\n");
2613 return (-1);
2614
2615 }
2616 return (0);
2617}
2618#endif /* LIBXML_OUTPUT_ENABLED */
2619
2620#ifdef LIBXML_VALID_ENABLED

Callers 2

test_xmlShellSaveFunction · 0.85
xmlShellFunction · 0.85

Calls 2

xmlSaveFileFunction · 0.85
htmlSaveFileFunction · 0.85

Tested by 1

test_xmlShellSaveFunction · 0.68