-
Notifications
You must be signed in to change notification settings - Fork 84
API_xar_file_first
Rob Braun edited this page Jan 11, 2007
·
2 revisions
Obtain a reference to the first file in a xarchive
libxar uses iterators for browsing through the files in a xarchive, or propertie s associated with files. xar_file_first() takes a xar_t as returned by a call to xar_open() and an iterator previously allocated with a call to xar_iter_new(). xar_file_first() will then return a reference to the first file associated with the xarchive represented by the passed xar_t.
Upon success, xar_file_first() will return a reference to the first file in the xarchive. On failure, NULL will be returned.
#include <xar/xar.h>
int main(int argc, char *argv[]) {
xar_t x;
xar_file_t f;
xar_iter_t i;
x = xar_open(argv[1], READ);
if( x == NULL ) {
fprintf(stderr, "Error opening xarchive: %s\n", argv[1]);
exit(1);
}
i = xar_iter_new(x);
if( !i ) {
fprintf(stderr, "Error obtaining a new iterator\n");
exit(1);
}
f = xar_file_first(x, i);
if( f ) {
if( xar_extract(x, f) != 0 ) {
fprintf(stderr, "Error adding /path/to/file to the xarchive\n");
}
}
...
xar_iter_free(i);
xar_close(x);
...
}