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
16 #include <sys/param.h>
26 tar_extract_glob(TAR
*t
, char *globname
, char *prefix
)
32 while ((i
= th_read(t
)) == 0)
34 filename
= th_get_pathname(t
);
35 if (fnmatch(globname
, filename
, FNM_PATHNAME
| FNM_PERIOD
))
37 if (TH_ISREG(t
) && tar_skip_regfile(t
))
41 if (t
->options
& TAR_VERBOSE
)
44 snprintf(buf
, sizeof(buf
), "%s/%s", prefix
, filename
);
46 strlcpy(buf
, filename
, sizeof(buf
));
47 if (tar_extract_file(t
, filename
) != 0)
51 return (i
== 1 ? 0 : -1);
56 tar_extract_all(TAR
*t
, char *prefix
)
63 printf("==> tar_extract_all(TAR *t, \"%s\")\n",
64 (prefix
? prefix
: "(null)"));
67 while ((i
= th_read(t
)) == 0)
70 puts(" tar_extract_all(): calling th_get_pathname()");
72 filename
= th_get_pathname(t
);
73 if (t
->options
& TAR_VERBOSE
)
76 snprintf(buf
, sizeof(buf
), "%s/%s", prefix
, filename
);
78 strlcpy(buf
, filename
, sizeof(buf
));
80 printf(" tar_extract_all(): calling tar_extract_file(t, "
83 if (tar_extract_file(t
, buf
) != 0)
87 return (i
== 1 ? 0 : -1);
92 tar_append_tree(TAR
*t
, char *realdir
, char *savedir
)
94 char realpath
[MAXPATHLEN
];
95 char savepath
[MAXPATHLEN
];
101 printf("==> tar_append_tree(0x%lx, \"%s\", \"%s\")\n",
102 t
, realdir
, (savedir
? savedir
: "[NULL]"));
105 if (tar_append_file(t
, realdir
, savedir
) != 0)
109 puts(" tar_append_tree(): done with tar_append_file()...");
112 dp
= opendir(realdir
);
115 if (errno
== ENOTDIR
)
119 while ((dent
= readdir(dp
)) != NULL
)
121 if (strcmp(dent
->d_name
, ".") == 0 ||
122 strcmp(dent
->d_name
, "..") == 0)
125 snprintf(realpath
, MAXPATHLEN
, "%s/%s", realdir
,
128 snprintf(savepath
, MAXPATHLEN
, "%s/%s", savedir
,
131 if (lstat(realpath
, &s
) != 0)
134 if (S_ISDIR(s
.st_mode
))
136 if (tar_append_tree(t
, realpath
,
137 (savedir
? savepath
: NULL
)) != 0)
142 if (tar_append_file(t
, realpath
,
143 (savedir
? savepath
: NULL
)) != 0)