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