2 ** Copyright 1998-2003 University of Illinois Board of Trustees
3 ** Copyright 1998-2003 Mark D. Roth
4 ** All rights reserved.
6 ** wrapper.c - libtar high-level wrapper code
8 ** Mark D. Roth <roth@uiuc.edu>
9 ** Campus Information Technologies and Educational Services
10 ** University of Illinois at Urbana-Champaign
17 #include <sys/param.h>
27 tar_extract_glob(TAR
*t
, char *globname
, char *prefix
)
33 while ((i
= th_read(t
)) == 0)
35 filename
= th_get_pathname(t
);
36 if (fnmatch(globname
, filename
, FNM_PATHNAME
| FNM_PERIOD
))
38 if (TH_ISREG(t
) && tar_skip_regfile(t
))
42 if (t
->options
& TAR_VERBOSE
)
45 snprintf(buf
, sizeof(buf
), "%s/%s", prefix
, filename
);
47 strlcpy(buf
, filename
, sizeof(buf
));
48 if (tar_extract_file(t
, buf
) != 0)
52 return (i
== 1 ? 0 : -1);
57 tar_extract_all(TAR
*t
, char *prefix
)
64 printf("==> tar_extract_all(TAR *t, \"%s\")\n",
65 (prefix
? prefix
: "(null)"));
68 while ((i
= th_read(t
)) == 0)
71 puts(" tar_extract_all(): calling th_get_pathname()");
73 filename
= th_get_pathname(t
);
74 if (t
->options
& TAR_VERBOSE
)
77 snprintf(buf
, sizeof(buf
), "%s/%s", prefix
, filename
);
79 strlcpy(buf
, filename
, sizeof(buf
));
81 printf(" tar_extract_all(): calling tar_extract_file(t, "
84 if (tar_extract_file(t
, buf
) != 0)
88 return (i
== 1 ? 0 : -1);
93 tar_append_tree(TAR
*t
, char *realdir
, char *savedir
)
95 char realpath
[MAXPATHLEN
];
96 char savepath
[MAXPATHLEN
];
102 printf("==> tar_append_tree(0x%lx, \"%s\", \"%s\")\n",
103 t
, realdir
, (savedir
? savedir
: "[NULL]"));
106 if (tar_append_file(t
, realdir
, savedir
) != 0)
110 puts(" tar_append_tree(): done with tar_append_file()...");
113 dp
= opendir(realdir
);
116 if (errno
== ENOTDIR
)
120 while ((dent
= readdir(dp
)) != NULL
)
122 if (strcmp(dent
->d_name
, ".") == 0 ||
123 strcmp(dent
->d_name
, "..") == 0)
126 snprintf(realpath
, MAXPATHLEN
, "%s/%s", realdir
,
129 snprintf(savepath
, MAXPATHLEN
, "%s/%s", savedir
,
132 if (lstat(realpath
, &s
) != 0)
135 if (S_ISDIR(s
.st_mode
))
137 if (tar_append_tree(t
, realpath
,
138 (savedir
? savepath
: NULL
)) != 0)
143 if (tar_append_file(t
, realpath
,
144 (savedir
? savepath
: NULL
)) != 0)