3 #include <libxml/tree.h> /* For xmlDoc and xmlNodePtr */
4 #include <libxml/xpath.h>
6 /* Open file and return descriptor. Return -1 in case of error. */
7 int open_file_for_writing(const char *file
, _Bool truncate
, _Bool overwrite
);
9 /* Return 0, -1 in case of error */
10 int mmap_file(const char *file
, int *fd
, void **buffer
, size_t *length
);
12 /* Return 0, -1 in case of error */
13 int munmap_file(int fd
, void *buffer
, size_t length
);
15 /* Return 0, -1 in case of error.
16 * @length and @mime_type are optional. */
17 int load_data_from_file(const char *file
, void **data
, size_t *length
,
20 /* Save @data to file specified by descriptor @fd. If @fd is negative, @file
21 * file will be opened first. Descriptor is closed at the end of this
22 * function. Supply @file name even if @fd is positive, the name could be used
24 int save_data_to_file(const char *file
, int fd
, const void *data
,
25 const size_t length
, const char *mime_type
, _Bool overwrite
);
27 /* Parse @buffer as XML document and return @node_list specified by
29 * @node_list is weak copy that must be non-recursively freed by caller. Caller
30 * must free XML document (accessible through @node_list member) on its own.
31 * In case of error @node_list value will be invalid.
32 * If @node_list is returned empty, function freed parsed document already.
33 * @xpat_expr is UTF-8 encoded XPath expression */
34 int load_xml_subtree_from_memory(const void *buffer
, size_t length
,
35 xmlNodePtr
*node_list
, const char *xpath_expr
);
37 /* Deallocate struct isds_document with embedded XML recursively and NULL it */
38 void free_document_with_xml_node_list(struct isds_document
**document
);
40 /* Serialize XML @node_list to automatically rellaocated libxml @buffer */
41 int serialize_xml_to_buffer(xmlBufferPtr
*buffer
, const xmlNodePtr node_list
);
43 /* Save @node_list to file specified by descriptor @fd. If @fd is negative, @file
44 * file will be opened first. Descriptor is closed at the end of this
45 * function. Supply @file name even if @fd is positive, the name could be used
47 int save_xml_to_file(const char *file
, int fd
, const xmlNodePtr node_list
,
48 const char *mime_type
, _Bool overwrite
);
50 /* Return 0 if @path is directory, 1 if not, -1 if error occurred */
51 int is_directory(const char *path
);