12 #define _IOSM_INTERNAL
39 buf = (
char *)
alloca(num + 1);
40 strncpy(buf, str, num);
43 ret = strtoul(buf, &end, base);
46 *endptr = ((
char *)str) + (end - buf);
48 *endptr = ((
char *)str) + strlen(buf);
55 #define _IOSMRC(_rc) \
56 if ((_rc) <= 0) return ((_rc) ? (int) -rc : IOSMERR_HDR_TRAILER)
58 static ssize_t
cpioRead(
void * _iosm,
void * buf,
size_t count)
63 char * t = (
char *) buf;
68 fprintf(stderr,
" cpioRead(%p, %p[%u])\n", iosm, buf, (
unsigned)count);
80 rc = (count > iosm->
rdnb ? iosm->
rdnb : count);
81 if (buf != iosm->
wrbuf)
82 memcpy(t + nb, iosm->
wrbuf, rc);
89 #define GET_NUM_FIELD(phys, log) \
90 log = strntoul(phys, &end, 16, sizeof(phys)); \
91 if ( (end - phys) != sizeof(phys) ) return IOSMERR_BAD_HEADER;
92 #define SET_NUM_FIELD(phys, val, space) \
93 sprintf(space, "%8.8lx", (unsigned long) (val)); \
94 memcpy(phys, space, 8)
106 fprintf(stderr,
" cpioHeaderRead(%p, %p)\n", iosm, st);
139 if (nb <= 0 || nb >= iosm->
wrsize)
143 {
char * t = (
char *)
xmalloc(nb + 1);
161 if (rc)
return (
int) -rc;
163 nb = (size_t) st->st_size;
180 fprintf(stderr,
"\t %06o%3d (%4d,%4d)%12lu %s\n\t-> %s\n",
181 (
unsigned)st->st_mode, (
int)st->st_nlink,
182 (
int)st->st_uid, (
int)st->st_gid, (
unsigned long)st->st_size,
189 static ssize_t
cpioWrite(
void * _iosm,
const void *buf,
size_t count)
194 const char * s = (
const char *) buf;
199 fprintf(stderr,
"\t cpioWrite(%p, %p[%u])\n", iosm, buf, (
unsigned)count);
205 if (s != iosm->
rdbuf)
206 memmove(iosm->
rdbuf, s + nb, iosm->
rdnb);
209 if (!rc && iosm->
rdnb != iosm->
wrnb)
217 #if defined(JBJ_WRITEPAD)
229 const char * path = (iosm && iosm->
path ? iosm->
path :
"");
230 const char * lpath = (iosm && iosm->
lpath ? iosm->
lpath :
"");
237 fprintf(stderr,
" cpioHeaderWrite(%p, %p)\n", iosm, st);
254 memcpy(hdr->
checksum,
"00000000", 8);
263 #if !defined(JBJ_WRITEPAD)
265 if (rc)
return (
int) rc;
273 #if !defined(JBJ_WRITEPAD)
288 fprintf(stderr,
" cpioTrailerWrite(%p)\n", iosm);
292 memcpy(hdr->
nlink,
"00000001", 8);
293 memcpy(hdr->
namesize,
"0000000b", 8);
307 #if !defined(JBJ_WRITEPAD)
const char const char * field
#define Makedev(x, y)
makedev() on QNX takes three parameters the additional one (first place) specifies the node for QNET ...
#define GET_NUM_FIELD(phys, log)
int cpioHeaderWrite(void *_iosm, struct stat *st)
Write cpio header.
Structures used for cpio(1) archives.
int(* _iosmNext)(IOSM_t iosm, iosmFileStage nstage)
Vector to iosmNext.
struct iosm_s * IOSM_t
File state machine data.
static ssize_t cpioRead(void *_iosm, void *buf, size_t count)
#define SET_NUM_FIELD(phys, val, space)
static int strntoul(const char *str, char **endptr, int base, size_t num)
Convert string to unsigned integer (with buffer size check).
static ssize_t cpioWrite(void *_iosm, const void *buf, size_t count)
struct cpioCrcPhysicalHeader_s * cpioHeader
int cpioHeaderRead(void *_iosm, struct stat *st)
Read cpio header.
int cpioTrailerWrite(void *_iosm)
Write cpio trailer.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
File state machine to handle archive I/O and system call's.
File name and stat information.
const char const bson int num