cctools
[darwin-xtools/darwin-xtools-svp.git] / xar-additions / xar-additions.c
blobdef39ab453b4cff1f845a9a0a0ee6dd4f3b83cec
1 #include <xar/xar.h>
3 extern int32_t xar_arcmod_extract(xar_t x, xar_file_t f, const char *file, char *buffer, size_t len);
5 /* xar_extract_tobuffer
6 * x: archive to extract from
7 * buffer: buffer to extract to
8 * size: On return, this will contain the size of the memory pointed to by buffer
9 * Returns 0 on success, -1 on failure.
10 * Summary: This is the entry point for extraction to a buffer.
11 * On success, a buffer is allocated with the contents of the file
12 * specified. The caller is responsible for freeing the returend buffer.
13 * Example: xar_extract_tobuffer(x, "foo/bar/blah",&buffer)
15 int32_t xar_extract_tobuffersz(xar_t x, xar_file_t f, char **buffer, size_t *size) {
16 const char *sizestring = NULL;
17 int32_t ret;
19 if(0 != xar_prop_get(f,"data/size",&sizestring)){
20 if(0 != xar_prop_get(f, "type", &sizestring))
21 return -1;
22 if(strcmp(sizestring, "file") == 0) {
23 *size = 0;
24 return 0;
26 return -1;
29 *size = strtoull(sizestring, (char **)NULL, 10);
30 *buffer = malloc(*size);
32 if(!(*buffer)){
33 return -1;
36 ret = xar_arcmod_extract(x,f,NULL,*buffer,*size);
37 if( ret ) {
38 *size = 0;
39 free(*buffer);
40 *buffer = NULL;
43 return ret;