15 #define _IOSM_INTERNAL
33 static int strntoul(
const char *str,
char **endptr,
40 buf = (
char *)
alloca(num + 1);
44 ret = strtoul(buf, &end, base);
47 *endptr = ((
char *)str) + (end -
buf);
49 *endptr = ((
char *)str) + strlen(buf);
56 #define _IOSMRC(_rc) \
57 if ((_rc) <= 0) return ((_rc) ? (int) -rc : IOSMERR_HDR_TRAILER)
64 char *
t = (
char *) buf;
69 fprintf(stderr,
"\t arRead(%p, %p[%u])\n", iosm, buf, (
unsigned)count);
84 if (buf != iosm->
wrbuf)
85 memcpy(t + nb, iosm->
wrbuf, rc);
100 fprintf(stderr,
" arHeaderRead(%p, %p)\n", iosm, st);
115 if (
rc)
return (
int)
rc;
117 rc =
arRead(iosm, hdr,
sizeof(*hdr));
120 fprintf(stderr,
"==> %p[%u] \"%.*s\"\n", hdr, (
unsigned)
rc, (
int)
sizeof(*hdr)-2, (
char *)hdr);
129 if (hdr->
name[0] ==
'/') {
131 if (hdr->
name[1] ==
'/' && hdr->
name[2] ==
' ') {
143 for (i = 1; i < iosm->
lmtablen; i++) {
145 if (t[0] !=
'\n')
continue;
148 if (t[-1] ==
'/') t[-1] =
'\0';
153 if (hdr->
name[1] ==
' ') {
166 if (hdr->
name[0] !=
' ') {
167 size_t nb =
sizeof(hdr->
name);
168 char t[
sizeof(hdr->
name)+1];
169 memcpy(
t, hdr->
name, nb);
171 while (nb > 0 &&
t[nb-1] ==
' ')
174 if (nb > 0 &&
t[nb - 1] ==
'/')
180 st->st_ctime = st->st_atime = st->st_mtime;
191 fprintf(stderr,
"\t %06o%3d (%4d,%4d)%12lu %s\n",
192 (
unsigned)st->st_mode, (
int)st->st_nlink,
193 (
int)st->st_uid, (
int)st->st_gid, (
unsigned long)st->st_size,
204 const char *
s = (
const char *) buf;
209 fprintf(stderr,
"\tarWrite(%p, %p[%u])\n", iosm, buf, (
unsigned)count);
215 if (s != iosm->
rdbuf)
216 memmove(iosm->
rdbuf, s + nb, iosm->
rdnb);
219 if (!rc && iosm->
rdnb != iosm->
wrnb)
227 #if defined(JBJ_WRITEPAD)
239 const char *
path = (iosm && iosm->
path ? iosm->
path :
"");
244 fprintf(stderr,
" arHeaderWrite(%p, %p)\n", iosm, st);
253 memset(hdr, (
int)
' ',
sizeof(*hdr));
259 rc =
arWrite(iosm, hdr,
sizeof(*hdr));
263 #if !defined(JBJ_WRITEPAD)
265 if (rc)
return (
int)
rc;
270 memset(hdr, (
int)
' ',
sizeof(*hdr));
273 if (nb >=
sizeof(hdr->
name)) {
278 te = strchr(t,
'\n');
289 sprintf(hdr->
mtime,
"%-12u", (
unsigned) (st->st_mtime & 037777777777));
290 sprintf(hdr->
uid,
"%-6u", (
unsigned int)(st->st_uid & 07777777));
291 sprintf(hdr->
gid,
"%-6u", (
unsigned int)(st->st_gid & 07777777));
293 sprintf(hdr->
mode,
"%-8o", (
unsigned int)(st->st_mode & 07777777));
294 sprintf(hdr->
filesize,
"%-10u", (
unsigned) (st->st_size & 037777777777));
298 rc = (
int)
sizeof(*hdr);
300 fprintf(stderr,
"==> %p[%u] \"%.*s\"\n", hdr, (
unsigned)rc, (
int)
sizeof(*hdr), (
char *)hdr);
302 rc =
arWrite(iosm, hdr,
sizeof(*hdr));
315 fprintf(stderr,
" arTrailerWrite(%p)\n", iosm);
317 #if defined(JBJ_WRITEPAD)
int arHeaderRead(void *_iosm, struct stat *st)
Read ar(1) header.
static unsigned long long fdGetCpioPos(FD_t fd)
char * xstrdup(const char *str)
static char *size_t nb
fgets(3) analogue that reads \ continuations.
static ssize_t arRead(void *_iosm, void *buf, size_t count)
Structures used for ar(1) archives.
sprintf(t," (%u)",(unsigned) dig->nbytes)
memset(_r, 0, sizeof(*_r))
assert(key->size==sizeof(hdrNum))
fprintf(stderr,"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp)
int(* _iosmNext)(IOSM_t iosm, iosmFileStage nstage)
Vector to iosmNext.
struct arHeader_s * arHeader
static int strntoul(const char *str, char **endptr, int base, size_t num)
Convert string to unsigned integer (with buffer size check).
static int xisdigit(int c)
static int snprintf(char *buf, int nb, const char *fmt,...)
int arHeaderWrite(void *_iosm, struct stat *st)
Write ar(1) header.
struct iosm_s * IOSM_t
File state machine data.
int arTrailerWrite(void *_iosm)
Write ar(1) trailer.
static ssize_t arWrite(void *_iosm, const void *buf, size_t count)
char * buf
Parse (and execute) macro undefinition.
File state machine to handle archive I/O and system call's.
int
Save source and expand field into target.
File name and stat information.