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
13 #include <libtarint/internal.h>
18 #include <libtar/compat.h>
19 #if defined(HAVE_SYS_PARAM_H)
20 #include <sys/param.h>
22 #if defined(HAVE_DIRENT_H)
25 #include <libtarint/filesystem.h>
39 tar_extract_glob(TAR
*t
, char *globname
, char *prefix
)
42 char buf
[TAR_MAXPATHLEN
];
46 while ((i
= th_read(t
)) == 0)
48 pathname
= th_get_pathname(t
);
51 if (fnmatch(globname
, filename
, FNM_PATHNAME
| FNM_PERIOD
))
58 if (TH_ISREG(t
) && tar_skip_regfile(t
))
63 if (t
->options
& TAR_VERBOSE
)
67 snprintf(buf
, sizeof(buf
), "%s/%s", prefix
, filename
);
69 strlcpy(buf
, filename
, sizeof(buf
));
71 if (tar_extract_file(t
, filename
) != 0)
86 return (i
== 1 ? 0 : -1);
91 tar_extract_all(TAR
*t
, char *prefix
)
94 char buf
[TAR_MAXPATHLEN
];
99 printf("==> tar_extract_all(TAR *t, \"%s\")\n",
100 (prefix
? prefix
: "(null)"));
103 while ((i
= th_read(t
)) == 0)
106 puts(" tar_extract_all(): calling th_get_pathname()");
109 pathname
= th_get_pathname(t
);
112 if (t
->options
& TAR_VERBOSE
)
115 snprintf(buf
, sizeof(buf
), "%s/%s", prefix
, filename
);
117 strlcpy(buf
, filename
, sizeof(buf
));
125 printf(" tar_extract_all(): calling tar_extract_file(t, "
129 if (tar_extract_file(t
, buf
) != 0)
133 return (i
== 1 ? 0 : -1);
138 tar_append_tree(TAR
*t
, char *realdir
, char *savedir
)
140 char realpath
[TAR_MAXPATHLEN
];
141 char savepath
[TAR_MAXPATHLEN
];
143 #if defined(HAVE_DIRENT_H)
151 strncpy(realpath
, realdir
, sizeof(realpath
));
152 realpath
[sizeof(realpath
)-1] = 0;
153 plen
= strlen(realpath
);
154 if ( realpath
[plen
-1] == '/' )
156 realpath
[plen
-1] = 0;
161 printf("==> tar_append_tree(0x%lx, \"%s\", \"%s\")\n",
162 t
, realdir
, (savedir
? savedir
: "[NULL]"));
165 if (tar_append_file(t
, realdir
, savedir
) != 0)
169 puts(" tar_append_tree(): done with tar_append_file()...");
172 if ( stat(realpath
, &s
) != 0 )
177 #if defined(_WIN32) && !defined(__CYGWIN__)
178 (s
.st_mode
& _S_IFDIR
) == 0
184 #if defined(HAVE_DIRENT_H)
185 dp
= opendir(realdir
);
187 dp
= kwOpenDir(realdir
);
192 if (errno
== ENOTDIR
)
196 #if defined(HAVE_DIRENT_H)
197 while ((dent
= readdir(dp
)) != NULL
)
199 while ((dent
= kwReadDir(dp
)) != NULL
)
202 if (strcmp(dent
->d_name
, ".") == 0 ||
203 strcmp(dent
->d_name
, "..") == 0)
206 snprintf(realpath
, TAR_MAXPATHLEN
, "%s/%s", realdir
,
209 snprintf(savepath
, TAR_MAXPATHLEN
, "%s/%s", savedir
,
213 if (lstat(realpath
, &s
) != 0)
216 if (stat(realpath
, &s
) != 0)
219 if (S_ISDIR(s
.st_mode
))
221 if (tar_append_tree(t
, realpath
,
222 (savedir
? savepath
: NULL
)) != 0)
227 if (tar_append_file(t
, realpath
,
228 (savedir
? savepath
: NULL
)) != 0)
232 #if defined(HAVE_DIRENT_H)