RPM Package Manager, CVS Repository
http://rpm5.org/cvs/
____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson
Root: /v/rpm/cvs Email: [EMAIL PROTECTED]
Module: rpm Date: 10-Mar-2008 20:18:57
Branch: HEAD Handle: 2008031019185601
Modified files:
rpm CHANGES
rpm/rpmio poptIO.c rpmio.c rpmlua.c tar.c
Log:
- jbj: keep tar.c parallel to ar.c coding conventions. cpio.c next.
- jbj: clean up most rpmio gcc -W warnings.
Summary:
Revision Changes Path
1.2233 +2 -0 rpm/CHANGES
1.19 +4 -5 rpm/rpmio/poptIO.c
1.125 +1 -1 rpm/rpmio/rpmio.c
2.49 +2 -2 rpm/rpmio/rpmlua.c
1.8 +112 -90 rpm/rpmio/tar.c
____________________________________________________________________________
patch -p0 <<'@@ .'
Index: rpm/CHANGES
============================================================================
$ cvs diff -u -r1.2232 -r1.2233 CHANGES
--- rpm/CHANGES 10 Mar 2008 19:15:45 -0000 1.2232
+++ rpm/CHANGES 10 Mar 2008 19:18:56 -0000 1.2233
@@ -1,4 +1,6 @@
5.0.0 -> 5.1a1:
+ - jbj: keep tar.c parallel to ar.c coding conventions. cpio.c next.
+ - jbj: clean up most rpmio gcc -W warnings.
- jbj: clean up iosm/fsm gcc -W warnings.
- jbj: enable gcc -W warnings, fix most of the no-brainers.
- jbj: iosm: init file contexts during setup, not with missing dirs.
@@ .
patch -p0 <<'@@ .'
Index: rpm/rpmio/poptIO.c
============================================================================
$ cvs diff -u -r1.18 -r1.19 poptIO.c
--- rpm/rpmio/poptIO.c 10 Mar 2008 04:46:19 -0000 1.18
+++ rpm/rpmio/poptIO.c 10 Mar 2008 19:18:57 -0000 1.19
@@ -36,9 +36,6 @@
/[EMAIL PROTECTED]@*/
int __debug = 0;
-/[EMAIL PROTECTED]@*/
-extern int _rpmsq_debug;
-
/[EMAIL PROTECTED]@*/
/[EMAIL PROTECTED]@*/
/[EMAIL PROTECTED]@*/
@@ -58,6 +55,8 @@
/[EMAIL PROTECTED]@*/
extern int _rpmio_debug;
/[EMAIL PROTECTED]@*/
+extern int _rpmsq_debug;
+/[EMAIL PROTECTED]@*/
extern int _tar_debug;
/[EMAIL PROTECTED]@*/
extern int _xar_debug;
@@ -171,10 +170,10 @@
const struct poptOption * opt, const char * arg,
/[EMAIL PROTECTED]@*/ UNUSED(const void * data))
/[EMAIL PROTECTED] pgpImplVecs,
- rpmCLIMacroContext, rpmGlobalMacroContext, h_errno,
+ rpmGlobalMacroContext, h_errno,
fileSystem, internalState @*/
/[EMAIL PROTECTED] con, pgpImplVecs,
- rpmCLIMacroContext, rpmGlobalMacroContext,
+ rpmGlobalMacroContext,
fileSystem, internalState @*/
{
@@ .
patch -p0 <<'@@ .'
Index: rpm/rpmio/rpmio.c
============================================================================
$ cvs diff -u -r1.124 -r1.125 rpmio.c
--- rpm/rpmio/rpmio.c 10 Mar 2008 04:46:20 -0000 1.124
+++ rpm/rpmio/rpmio.c 10 Mar 2008 19:18:57 -0000 1.125
@@ -289,7 +289,7 @@
return -2;
}
-#ifdef UNUSED
+#ifdef NOTUSED
FILE *fdFdopen(void * cookie, const char *fmode)
{
FD_t fd = c2f(cookie);
@@ .
patch -p0 <<'@@ .'
Index: rpm/rpmio/rpmlua.c
============================================================================
$ cvs diff -u -r2.48 -r2.49 rpmlua.c
--- rpm/rpmio/rpmlua.c 17 Feb 2008 17:24:04 -0000 2.48
+++ rpm/rpmio/rpmlua.c 10 Mar 2008 19:18:57 -0000 2.49
@@ -934,7 +934,7 @@
return luaL_error(L, "`tostring' must return a string to `print'");
if (lua->storeprint) {
size_t sl = lua_strlen(L, -1);
- if (lua->printbufused+sl+1 > lua->printbufsize) {
+ if ((size_t)(lua->printbufused+sl+1) > lua->printbufsize) {
lua->printbufsize += sl+512;
lua->printbuf = xrealloc(lua->printbuf, lua->printbufsize);
}
@@ -952,7 +952,7 @@
if (!lua->storeprint) {
(void) fputs("\n", stdout);
} else {
- if (lua->printbufused+1 > lua->printbufsize) {
+ if ((size_t)(lua->printbufused+1) > lua->printbufsize) {
lua->printbufsize += 512;
lua->printbuf = xrealloc(lua->printbuf, lua->printbufsize);
}
@@ .
patch -p0 <<'@@ .'
Index: rpm/rpmio/tar.c
============================================================================
$ cvs diff -u -r1.7 -r1.8 tar.c
--- rpm/rpmio/tar.c 10 Mar 2008 04:46:20 -0000 1.7
+++ rpm/rpmio/tar.c 10 Mar 2008 19:18:57 -0000 1.8
@@ -24,12 +24,13 @@
/**
* Convert string to unsigned integer (with buffer size check).
* @param str input string
- * @retval endptr address of 1st character not processed
+ * @retval *endptr 1st character not processed
* @param base numerical conversion base
* @param num max no. of bytes to read
* @return converted integer
*/
-static int strntoul(const char *str, /[EMAIL PROTECTED]@*/char **endptr, int
base, int num)
+static int strntoul(const char *str, /[EMAIL PROTECTED]@*/ /[EMAIL
PROTECTED]@*/char **endptr,
+ int base, size_t num)
/[EMAIL PROTECTED] *endptr @*/
/[EMAIL PROTECTED] maxSet(endptr) >= 0 @*/
{
@@ -51,42 +52,64 @@
return ret;
}
+static ssize_t tarRead(void * _iosm, void * buf, size_t count)
+ /[EMAIL PROTECTED] fileSystem @*/
+ /[EMAIL PROTECTED] _iosm, *buf, fileSystem @*/
+{
+ IOSM_t iosm = _iosm;
+ char * t = buf;
+ size_t nb = 0;
+
+if (_tar_debug)
+fprintf(stderr, " tarRead(%p, %p[%u])\n", iosm, buf,
(unsigned)count);
+
+ while (count > 0) {
+ size_t rc;
+
+ /* Read next tar block. */
+ iosm->wrlen = count;
+ rc = _iosmNext(iosm, IOSM_DREAD);
+ if (!rc && iosm->rdnb != iosm->wrlen)
+ rc = IOSMERR_READ_FAILED;
+ if (rc) return -rc;
+
+ /* Append to buffer. */
+ rc = (count > iosm->rdnb ? iosm->rdnb : count);
+ if (buf != iosm->wrbuf)
+ memcpy(t + nb, iosm->wrbuf, rc);
+ nb += rc;
+ count -= rc;
+ }
+ return nb;
+}
+
/**
* Read long file/link name from tar archive.
* @param _iosm file state machine
* @param len no. bytes of name
* @retval *fnp long file/link name
- * @return 0 on success
+ * @return no. bytes read (rc < 0 on error)
*/
-static int tarHeaderReadName(void * _iosm, size_t len,
+static ssize_t tarHeaderReadName(void * _iosm, size_t len,
/[EMAIL PROTECTED]@*/ const char ** fnp)
- /[EMAIL PROTECTED] internalState @*/
- /[EMAIL PROTECTED] _iosm, *fnp, internalState @*/
+ /[EMAIL PROTECTED] fileSystem, internalState @*/
+ /[EMAIL PROTECTED] _iosm, *fnp, fileSystem, internalState @*/
{
IOSM_t iosm = _iosm;
- char * t;
- int nb;
- int rc = 0;
+ size_t nb = len + 1;
+ char * t = xmalloc(nb);
+ ssize_t rc = tarRead(iosm, t, nb);
+
+ if (rc > 0) /* success */
+ t[rc] = '\0';
+ else /* failure */
+ t = _free(t);
+ if (fnp != NULL)
+ *fnp = t;
- *fnp = t = xmalloc(len + 1);
- while (len > 0) {
- /* Read next tar block. */
- iosm->wrlen = TAR_BLOCK_SIZE;
- rc = _iosmNext(iosm, IOSM_DREAD);
- if (!rc && iosm->rdnb != iosm->wrlen)
- rc = IOSMERR_READ_FAILED;
- if (rc) break;
-
- /* Append to name. */
- nb = (len > iosm->rdnb ? iosm->rdnb : len);
- memcpy(t, iosm->wrbuf, nb);
- t += nb;
- len -= nb;
- }
- *t = '\0';
+if (_tar_debug)
+fprintf(stderr, "\ttarHeaderReadName(%p, %u, %p) rc 0x%x\n", _iosm,
(unsigned)len, fnp, (unsigned)rc);
- if (rc)
- *fnp = _free(*fnp);
return rc;
}
@@ -96,9 +119,9 @@
IOSM_t iosm = _iosm;
tarHeader hdr = (tarHeader) iosm->wrbuf;
char * t;
- int nb;
+ size_t nb;
int major, minor;
- int rc = 0;
+ ssize_t rc = 0;
int zblk = 0;
if (_tar_debug)
@@ -107,11 +130,8 @@
top:
do {
/* Read next tar block. */
- iosm->wrlen = TAR_BLOCK_SIZE;
- rc = _iosmNext(iosm, IOSM_DREAD);
- if (!rc && iosm->rdnb != iosm->wrlen)
- rc = IOSMERR_READ_FAILED;
- if (rc) return rc;
+ rc = tarRead(_iosm, hdr, TAR_BLOCK_SIZE);
+ if (rc < 0) return (int) -rc;
/* Look for end-of-archive, i.e. 2 (or more) zero blocks. */
if (hdr->name[0] == '\0' && hdr->checksum[0] == '\0') {
@@ -133,13 +153,6 @@
for (i = 0; i < TAR_BLOCK_SIZE; i++)
sum += (long)*hp++;
-#if 0
- for (i = 0; i < sizeof(hdr->checksum) - 1; i++)
- sum += (' ' - hdr->checksum[i]);
-fprintf(stderr, "\tsum %ld\n", sum);
- if (sum != 0)
- return IOSMERR_BAD_HEADER;
-#else
memset(checksum, (int)' ', sizeof(checksum));
sprintf(checksum, "%06o", (unsigned) (sum & 07777777));
if (_tar_debug)
@@ -147,7 +160,6 @@
if (memcmp(hdrchecksum, checksum, sizeof(hdrchecksum)))
if (!nochksum)
return IOSMERR_BAD_HEADER;
-#endif
}
@@ -205,12 +217,12 @@
#endif
case 'K': /* GNU long (>100 chars) link name */
rc = tarHeaderReadName(iosm, st->st_size, &iosm->lpath);
- if (rc) return rc;
+ if (rc < 0) return (int) -rc;
goto top;
/[EMAIL PROTECTED]@*/ break;
case 'L': /* GNU long (>100 chars) file name */
rc = tarHeaderReadName(iosm, st->st_size, &iosm->path);
- if (rc) return rc;
+ if (rc < 0) return (int) -rc;
goto top;
/[EMAIL PROTECTED]@*/ break;
}
@@ -254,44 +266,58 @@
(int)st->st_uid, (int)st->st_gid, (unsigned long)st->st_size,
(iosm->path ? iosm->path : ""), (iosm->lpath ? iosm->lpath :
""));
- return rc;
+ return (int) rc;
}
-/**
- * Write long file/link name into tar archive.
- * @param _iosm file state machine
- * @param path long file/link name
- * @return 0 on success
- */
-static int tarHeaderWriteName(void * _iosm, const char * path)
- /[EMAIL PROTECTED] fileSystem, internalState @*/
- /[EMAIL PROTECTED] _iosm, fileSystem, internalState @*/
+static ssize_t tarWrite(void * _iosm, const void *buf, size_t count)
+ /[EMAIL PROTECTED] fileSystem @*/
+ /[EMAIL PROTECTED] _iosm, fileSystem @*/
{
IOSM_t iosm = _iosm;
- const char * s = path;
- int nb = strlen(s);
- int rc = 0;
+ const char * s = buf;
+ size_t nb = 0;
if (_tar_debug)
-fprintf(stderr, "\ttarHeaderWriteName(%p, %s) nb %d\n", iosm, path, nb);
+fprintf(stderr, " tarWrite(%p, %p[%u])\n", iosm, buf, (unsigned)count);
- while (nb > 0) {
- memset(iosm->rdbuf, 0, TAR_BLOCK_SIZE);
+ while (count > 0) {
+ size_t rc;
/* XXX DWRITE uses rdnb for I/O length. */
- iosm->rdnb = (nb < TAR_BLOCK_SIZE) ? nb : TAR_BLOCK_SIZE;
- memmove(iosm->rdbuf, s, iosm->rdnb);
+ iosm->rdnb = count;
+ if (s != iosm->rdbuf)
+ memmove(iosm->rdbuf, s + nb, iosm->rdnb);
+
rc = _iosmNext(iosm, IOSM_DWRITE);
if (!rc && iosm->rdnb != iosm->wrnb)
rc = IOSMERR_WRITE_FAILED;
+ if (rc) return -rc;
- if (rc) break;
- s += iosm->rdnb;
- nb -= iosm->rdnb;
+ nb += iosm->rdnb;
+ count -= iosm->rdnb;
}
+ return nb;
+}
- if (!rc)
- rc = _iosmNext(iosm, IOSM_PAD);
+/**
+ * Write long file/link name into tar archive.
+ * @param _iosm file state machine
+ * @param path long file/link name
+ * @return no. bytes written (rc < 0 on error)
+ */
+static ssize_t tarHeaderWriteName(void * _iosm, const char * path)
+ /[EMAIL PROTECTED] fileSystem, internalState @*/
+ /[EMAIL PROTECTED] _iosm, fileSystem, internalState @*/
+{
+ ssize_t rc = tarWrite(_iosm, path, strlen(path));
+
+ if (rc >= 0) {
+ rc = _iosmNext(_iosm, IOSM_PAD);
+ if (rc) rc = -rc;
+ }
+
+if (_tar_debug)
+fprintf(stderr, "\ttarHeaderWriteName(%p, %s) rc 0x%x\n", _iosm, path,
(unsigned)rc);
return rc;
}
@@ -301,14 +327,14 @@
* @param _iosm file state machine
* @param st file info
* @param hdr tar header block
- * @return 0 on success
+ * @return no. bytes written (rc < 0 on error)
*/
-static int tarHeaderWriteBlock(void * _iosm, struct stat * st, tarHeader hdr)
+static ssize_t tarHeaderWriteBlock(void * _iosm, struct stat * st, tarHeader
hdr)
/[EMAIL PROTECTED] fileSystem, internalState @*/
/[EMAIL PROTECTED] _iosm, hdr, fileSystem, internalState @*/
{
IOSM_t iosm = _iosm;
- int rc;
+ ssize_t rc;
if (_tar_debug)
fprintf(stderr, "\ttarHeaderWriteBlock(%p, %p) type %c\n", iosm, hdr,
hdr->typeflag);
@@ -334,11 +360,7 @@
fprintf(stderr, "\thdrchksum \"%s\"\n", hdr->checksum);
}
- /* XXX DWRITE uses rdnb for I/O length. */
- iosm->rdnb = TAR_BLOCK_SIZE;
- rc = _iosmNext(iosm, IOSM_DWRITE);
- if (!rc && iosm->rdnb != iosm->wrnb)
- rc = IOSMERR_WRITE_FAILED;
+ rc = tarWrite(_iosm, hdr, TAR_BLOCK_SIZE);
return rc;
}
@@ -351,47 +373,47 @@
tarHeader hdr = (tarHeader) iosm->rdbuf;
char * t;
dev_t dev;
- int rc = 0;
- size_t len;
+ size_t nb;
+ ssize_t rc = 0;
if (_tar_debug)
fprintf(stderr, " tarHeaderWrite(%p, %p)\n", iosm, st);
- len = strlen(iosm->path);
- if (len > sizeof(hdr->name)) {
+ nb = strlen(iosm->path);
+ if (nb > sizeof(hdr->name)) {
memset(hdr, 0, sizeof(*hdr));
strcpy(hdr->name, llname);
sprintf(hdr->mode, "%07o", 0);
sprintf(hdr->uid, "%07o", 0);
sprintf(hdr->gid, "%07o", 0);
- sprintf(hdr->filesize, "%011o", (unsigned) (len & 037777777777));
+ sprintf(hdr->filesize, "%011o", (unsigned) (nb & 037777777777));
sprintf(hdr->mtime, "%011o", 0);
hdr->typeflag = 'L';
strncpy(hdr->uname, "root", sizeof(hdr->uname));
strncpy(hdr->gname, "root", sizeof(hdr->gname));
rc = tarHeaderWriteBlock(iosm, st, hdr);
- if (rc) return rc;
+ if (rc < 0) return (int) -rc;
rc = tarHeaderWriteName(iosm, iosm->path);
- if (rc) return rc;
+ if (rc < 0) return (int) -rc;
}
if (iosm->lpath && iosm->lpath[0] != '0') {
- len = strlen(iosm->lpath);
- if (len > sizeof(hdr->name)) {
+ nb = strlen(iosm->lpath);
+ if (nb > sizeof(hdr->name)) {
memset(hdr, 0, sizeof(*hdr));
strcpy(hdr->linkname, llname);
sprintf(hdr->mode, "%07o", 0);
sprintf(hdr->uid, "%07o", 0);
sprintf(hdr->gid, "%07o", 0);
- sprintf(hdr->filesize, "%011o", (unsigned) (len & 037777777777));
+ sprintf(hdr->filesize, "%011o", (unsigned) (nb & 037777777777));
sprintf(hdr->mtime, "%011o", 0);
hdr->typeflag = 'K';
strncpy(hdr->uname, "root", sizeof(hdr->uname));
strncpy(hdr->gname, "root", sizeof(hdr->gname));
rc = tarHeaderWriteBlock(iosm, st, hdr);
- if (rc) return rc;
+ if (rc < 0) return (int) -rc;
rc = tarHeaderWriteName(iosm, iosm->lpath);
- if (rc) return rc;
+ if (rc < 0) return (int) -rc;
}
}
@@ -442,12 +464,12 @@
sprintf(hdr->devMinor, "%07o", (unsigned) (dev & 07777777));
rc = tarHeaderWriteBlock(iosm, st, hdr);
+ if (rc < 0) return (int) -rc;
/* XXX Padding is unnecessary but shouldn't hurt. */
- if (!rc)
- rc = _iosmNext(iosm, IOSM_PAD);
+ rc = _iosmNext(iosm, IOSM_PAD);
- return rc;
+ return (int) rc;
}
int tarTrailerWrite(void * _iosm)
@@ .
______________________________________________________________________
RPM Package Manager http://rpm5.org
CVS Sources Repository [email protected]