]> err.no Git - dpkg/commitdiff
* main/help.c, main/processarc.c, main/filesdb.c, main/configure.c,
authorAdam Heath <doogie@debian.org>
Sat, 21 Apr 2001 22:22:42 +0000 (22:22 +0000)
committerAdam Heath <doogie@debian.org>
Sat, 21 Apr 2001 22:22:42 +0000 (22:22 +0000)
    main/archives.c, lib/parse.c: Fix int/pointer casting warnings.
  * include/dpkg.h.in, lib/mlib.c: Rewrote buffer_copy_setup, to avoid
    int/pointer casting warnings.  These means there are several
    variations of buffer_copy_setup.  Also, converted the desc parameter
    to const.

ChangeLog
include/dpkg.h.in
lib/mlib.c
lib/parse.c
main/archives.c
main/configure.c
main/filesdb.c
main/help.c
main/processarc.c

index 9f0724b10e023569c7af2507278fe06be47792e0..4fb8afd058d64f1069f11e4e143b428ece72d34e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Apr 21 17:16:28 CDT 2001 Adam Heath <doogie@debian.org>
+
+  * main/help.c, main/processarc.c, main/filesdb.c,  main/configure.c,
+    main/archives.c, lib/parse.c: Fix int/pointer casting warnings.
+  * include/dpkg.h.in, lib/mlib.c: Rewrote buffer_copy_setup, to avoid
+    int/pointer casting warnings.  These means there are several
+    variations of buffer_copy_setup.  Also, converted the desc parameter
+    to const.
+
 Sun Apr 22 00:09:58 CEST 2001 Wichert Akkerman <wakkerma@debian.org>
 
   * optlib/long-options.c, lib/showcright.c: include stdlib.h to get
index 417f0d3d795249ac070e02c44f963912f11ef0ac..14e5eab2d6d462bcd2ba9b0d3e6bbb859c1bf7b0 100644 (file)
@@ -213,56 +213,72 @@ int waitsubproc(pid_t pid, const char *description, int sigpipeok, int warn);
 #define BUFFER_READ_SHUTDOWN 1 << 19
 
 typedef struct buffer_data *buffer_data_t;
-typedef ssize_t (*buffer_proc_t)(buffer_data_t data, void *buf, ssize_t size, char *desc);
+typedef ssize_t (*buffer_proc_t)(buffer_data_t data, void *buf, ssize_t size, const char *desc);
+typedef union buffer_arg {
+  void *ptr;
+  int i;
+} buffer_arg;
+
 struct buffer_data {
   buffer_proc_t proc;
-  void *data;
+  buffer_arg data;
   int type;
 };
 
 #define fd_md5(fd, hash, limit, desc...)\
-       buffer_copy_setup((void *)fd, BUFFER_READ_FD, NULL, \
-                          hash, BUFFER_WRITE_MD5, NULL, \
-                          limit, desc)
+       buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
+                                hash, BUFFER_WRITE_MD5, NULL, \
+                                limit, desc)
 #define stream_md5(file, hash, limit, desc...)\
-       buffer_copy_setup((void *)file, BUFFER_READ_STREAM, NULL, \
-                          hash, BUFFER_WRITE_MD5, NULL, \
-                          limit, desc)
-
+       buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
+                                hash, BUFFER_WRITE_MD5, NULL, \
+                                limit, desc)
 #define fd_fd_copy(fd1, fd2, limit, desc...)\
-       buffer_copy_setup((void *)fd1, BUFFER_READ_FD, NULL, \
-                         (void *)fd2, BUFFER_WRITE_FD, NULL, \
-                         limit, desc)
+       buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \
+                                fd2, BUFFER_WRITE_FD, NULL, \
+                                limit, desc)
 #define fd_buf_copy(fd, buf, limit, desc...)\
-       buffer_copy_setup((void *)fd, BUFFER_READ_FD, NULL, \
-                         buf, BUFFER_WRITE_BUF, NULL, \
-                         limit, desc)
+       buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
+                                buf, BUFFER_WRITE_BUF, NULL, \
+                                limit, desc)
 #define fd_vbuf_copy(fd, buf, limit, desc...)\
-       buffer_copy_setup((void *)fd, BUFFER_READ_FD, NULL, \
-                         buf, BUFFER_WRITE_VBUF, NULL, \
-                         limit, desc)
+       buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
+                                buf, BUFFER_WRITE_VBUF, NULL, \
+                                limit, desc)
 #define fd_null_copy(fd, limit, desc...) \
        if (lseek(fd, limit, SEEK_CUR) == -1) { \
            if(errno != ESPIPE) ohshite(desc); \
-           buffer_copy_setup((void *)fd, BUFFER_READ_FD, NULL, \
-                             0, BUFFER_WRITE_NULL, NULL, \
-                             limit, desc);\
+           buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
+                                    0, BUFFER_WRITE_NULL, NULL, \
+                                    limit, desc);\
        }
 #define stream_null_copy(file, limit, desc...) \
        if (fseek(file, limit, SEEK_CUR) == -1) { \
            if(errno != EBADF) ohshite(desc); \
-           buffer_copy_setup((void *)file, BUFFER_READ_STREAM, NULL, \
-                             0, BUFFER_WRITE_NULL, NULL, \
-                             limit, desc);\
+           buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
+                                    0, BUFFER_WRITE_NULL, NULL, \
+                                    limit, desc);\
        }
 #define stream_fd_copy(file, fd, limit, desc...)\
-       buffer_copy_setup((void *)file, BUFFER_READ_STREAM, NULL, \
-                         (void *)fd, BUFFER_WRITE_FD, NULL, \
-                         limit, desc)
-ssize_t buffer_copy_setup(void *argIn, int typeIn, void *procIn,
-                      void *argOut, int typeOut, void *procOut,
-                      ssize_t limit, const char *desc, ...);
-ssize_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, ssize_t limit, char *desc);
+       buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \
+                                fd, BUFFER_WRITE_FD, NULL, \
+                                limit, desc)
+inline ssize_t buffer_copy_setup_PtrInt(void *p, int typeIn, void *procIn,
+                                       int i, int typeOut, void *procOut,
+                                       ssize_t limit, const char *desc, ...);
+inline ssize_t buffer_copy_setup_PtrPtr(void *p1, int typeIn, void *procIn,
+                                       void *p2, int typeOut, void *procOut,
+                                       ssize_t limit, const char *desc, ...);
+inline ssize_t buffer_copy_setup_IntPtr(int i, int typeIn, void *procIn,
+                                       void *p, int typeOut, void *procOut,
+                                       ssize_t limit, const char *desc, ...);
+inline ssize_t buffer_copy_setup_IntInt(int i1, int typeIn, void *procIn,
+                                       int i2, int typeOut, void *procOut,
+                                       ssize_t limit, const char *desc, ...);
+ssize_t buffer_copy_setup(buffer_arg argIn, int typeIn, void *procIn,
+                      buffer_arg argOut, int typeOut, void *procOut,
+                      ssize_t limit, const char *desc);
+ssize_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, ssize_t limit, const char *desc);
 
 extern volatile int onerr_abort;
 
index b7b8cca503e88438153e56d891a4c53c8157e71a..a0f10e5bd18be610c4540fa7c4dca808366ccc29 100644 (file)
@@ -133,15 +133,15 @@ int waitsubproc(pid_t pid, const char *description, int sigpipeok, int warn) {
   return checksubprocerr(status,description,sigpipeok, warn);
 }
 
-ssize_t buffer_write(buffer_data_t data, void *buf, ssize_t length, char *desc) {
+ssize_t buffer_write(buffer_data_t data, void *buf, ssize_t length, const char *desc) {
   ssize_t ret= length;
   if(data->type & BUFFER_WRITE_SETUP) {
     switch(data->type ^ BUFFER_WRITE_SETUP) {
       case BUFFER_WRITE_MD5:
        {
-         unsigned char *hash= data->data;
+         unsigned char *hash= data->data.ptr;
          void ** array= malloc(sizeof(void *) * 2);
-         data->data= array;
+         data->data.ptr= array;
          array[0]= hash;
          array[1]= malloc(sizeof(struct MD5Context));
          MD5Init((struct MD5Context *)array[1]);
@@ -156,8 +156,8 @@ ssize_t buffer_write(buffer_data_t data, void *buf, ssize_t length, char *desc)
        {
          int i;
          unsigned char digest[16], *p = digest;
-         unsigned char *hash= (unsigned char *)((void **)data->data)[0];
-         MD5Final(digest, (struct MD5Context *)((void **)data->data)[1]);
+         unsigned char *hash= (unsigned char *)((void **)data->data.ptr)[0];
+         MD5Final(digest, (struct MD5Context *)((void **)data->data.ptr)[1]);
          for (i = 0; i < 16; ++i) {
            sprintf(hash, "%02x", *p++);
            hash += 2;
@@ -169,27 +169,27 @@ ssize_t buffer_write(buffer_data_t data, void *buf, ssize_t length, char *desc)
   }
   switch(data->type) {
     case BUFFER_WRITE_BUF:
-      memcpy(data->data, buf, length);
-      (char*)data->data += length;
+      memcpy(data->data.ptr, buf, length);
+      (char*)data->data.ptr += length;
       break;
     case BUFFER_WRITE_VBUF:
-      varbufaddbuf((struct varbuf *)data->data, buf, length);
+      varbufaddbuf((struct varbuf *)data->data.ptr, buf, length);
       break;
     case BUFFER_WRITE_FD:
-      if((ret= write((int)data->data, buf, length)) < 0 && errno != EINTR)
-       ohshite(_("failed in buffer_write(fd) (%i, ret=%i, %s)"), (int)data->data, ret, desc);
+      if((ret= write(data->data.i, buf, length)) < 0 && errno != EINTR)
+       ohshite(_("failed in buffer_write(fd) (%i, ret=%zi %s)"), data->data.i, ret, desc);
       break;
     case BUFFER_WRITE_NULL:
       break;
     case BUFFER_WRITE_STREAM:
-      ret= fwrite(buf, 1, length, (FILE *)data->data);
-      if(feof((FILE *)data->data))
+      ret= fwrite(buf, 1, length, (FILE *)data->data.ptr);
+      if(feof((FILE *)data->data.ptr))
        ohshite(_("eof in buffer_write(stream): %s"), desc);
-      if(ferror((FILE *)data->data))
+      if(ferror((FILE *)data->data.ptr))
        ohshite(_("error in buffer_write(stream): %s"), desc);
       break;
     case BUFFER_WRITE_MD5:
-      MD5Update((struct MD5Context *)((void **)data->data)[1], buf, length);
+      MD5Update((struct MD5Context *)((void **)data->data.ptr)[1], buf, length);
       break;
     default:
       fprintf(stderr, _("unknown data type `%i' in buffer_write\n"), data->type);
@@ -197,7 +197,7 @@ ssize_t buffer_write(buffer_data_t data, void *buf, ssize_t length, char *desc)
    return ret;
 }
 
-ssize_t buffer_read(buffer_data_t data, void *buf, ssize_t length, char *desc) {
+ssize_t buffer_read(buffer_data_t data, void *buf, ssize_t length, const char *desc) {
   ssize_t ret= length;
   if(data->type & BUFFER_READ_SETUP) {
     return 0;
@@ -207,14 +207,14 @@ ssize_t buffer_read(buffer_data_t data, void *buf, ssize_t length, char *desc) {
   }
   switch(data->type) {
     case BUFFER_READ_FD:
-      if((ret= read((int)data->data, buf, length)) < 0 && errno != EINTR)
+      if((ret= read(data->data.i, buf, length)) < 0 && errno != EINTR)
        ohshite(_("failed in buffer_read(fd): %s"), desc);
       break;
     case BUFFER_READ_STREAM:
-      ret= fread(buf, 1, length, (FILE *)data->data);
-      if(feof((FILE *)data->data))
+      ret= fread(buf, 1, length, (FILE *)data->data.ptr);
+      if(feof((FILE *)data->data.ptr))
        return ret;
-      if(ferror((FILE *)data->data))
+      if(ferror((FILE *)data->data.ptr))
        ohshite(_("error in buffer_read(stream): %s"), desc);
       break;
     default:
@@ -223,42 +223,59 @@ ssize_t buffer_read(buffer_data_t data, void *buf, ssize_t length, char *desc) {
    return ret;
 }
 
-ssize_t buffer_copy_setup(void *argIn, int typeIn, void *procIn,
-                      void *argOut, int typeOut, void *procOut,
-                      ssize_t limit, const char *desc, ...)
+#define buffer_copy_setup_dual(name, type1, name1, type2, name2) \
+inline ssize_t buffer_copy_setup_##name(type1 n1, int typeIn, void *procIn,\
+                                       type2 n2, int typeOut, void *procOut,\
+                                       ssize_t limit, const char *desc, ...)\
+{\
+  va_list al;\
+  buffer_arg a1, a2;\
+  struct varbuf v;\
+  ssize_t ret;\
+  a1.name1 = n1; a2.name2 = n2;\
+  varbufinit(&v);\
+  va_start(al,desc);\
+  varbufvprintf(&v, desc, al);\
+  va_end(al);\
+  ret = buffer_copy_setup(a1, typeIn, procIn,\
+                          a2, typeOut, procOut,\
+                          limit, v.buf);\
+  varbuffree(&v);\
+  return ret;\
+}
+
+buffer_copy_setup_dual(IntInt, int, i, int, i);
+buffer_copy_setup_dual(IntPtr, int, i, void *, ptr);
+buffer_copy_setup_dual(PtrInt, void *, ptr, int, i);
+buffer_copy_setup_dual(PtrPtr, void *, ptr, void *, ptr);
+
+ssize_t buffer_copy_setup(buffer_arg argIn, int typeIn, void *procIn,
+                      buffer_arg argOut, int typeOut, void *procOut,
+                      ssize_t limit, const char *desc)
 {
   struct buffer_data read_data = { procIn, argIn, typeIn },
                     write_data = { procOut, argOut, typeOut };
-  va_list al;
-  struct varbuf v;
   ssize_t ret;
 
-  varbufinit(&v);
-
-  va_start(al,desc);
-  varbufvprintf(&v, desc, al);
-  va_end(al);
-
   if ( procIn == NULL )
     read_data.proc = buffer_read;
   if ( procOut == NULL )
     write_data.proc = buffer_write;
   read_data.type |= BUFFER_READ_SETUP;
-  read_data.proc(&read_data, NULL, 0, v.buf);
+  read_data.proc(&read_data, NULL, 0, desc);
   read_data.type = typeIn;
   write_data.type |= BUFFER_WRITE_SETUP;
-  write_data.proc(&write_data, NULL, 0, v.buf);
+  write_data.proc(&write_data, NULL, 0, desc);
   write_data.type = typeOut;
-  ret = buffer_copy(&read_data, &write_data, limit, v.buf);
+  ret = buffer_copy(&read_data, &write_data, limit, desc);
   write_data.type |= BUFFER_WRITE_SHUTDOWN;
-  write_data.proc(&write_data, NULL, 0, v.buf);
+  write_data.proc(&write_data, NULL, 0, desc);
   read_data.type |= BUFFER_READ_SHUTDOWN;
-  read_data.proc(&read_data, NULL, 0, v.buf);
-  varbuffree(&v);
+  read_data.proc(&read_data, NULL, 0, desc);
   return ret;
 }
 
-ssize_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, ssize_t limit, char *desc) {
+ssize_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, ssize_t limit, const char *desc) {
   char *buf, *writebuf;
   long bytesread= 0, byteswritten= 0;
   int bufsize= 32768;
index 4e0d3d824cb0d837f368741cda2c1fd067575b39..98b231e8305a6154914bd3a7360c49fb4f8a0da5 100644 (file)
@@ -74,7 +74,7 @@ const struct fieldinfo fieldinfos[]= {
 #define NFIELDS (sizeof(fieldinfos)/sizeof(struct fieldinfo))
 const int nfields= NFIELDS;
 
-static void cu_parsedb(int argc, void **argv) { close((int)*argv); }
+static void cu_parsedb(int argc, void **argv) { close(*(int *)argv); }
 
 int parsedb(const char *filename, enum parsedbflags flags,
             struct pkginfo **donep, FILE *warnto, int *warncount) {
@@ -103,7 +103,7 @@ int parsedb(const char *filename, enum parsedbflags flags,
   fd= open(filename, O_RDONLY);
   if (fd == -1) ohshite(_("failed to open package info file `%.255s' for reading"),filename);
 
-  push_cleanup(cu_parsedb,~0, 0,0, 1,(void*)fd);
+  push_cleanup(cu_parsedb,~0, 0,0, 1,&fd);
 
   if (fstat(fd, &stat) == -1)
     ohshite(_("can't stat package info file `%.255s'"),filename);
index 0b601c273e653430e8196069b77e1e8629e7d19a..ce91b63a8400e8efeba2a38cac9268109d840ef8 100644 (file)
@@ -461,7 +461,7 @@ int tarobject(struct TarInfo *ti) {
      */
     fd= open(fnamenewvb.buf, (O_CREAT|O_EXCL|O_WRONLY), 0);
     if (fd < 0) ohshite(_("unable to create `%.255s'"),ti->Name);
-    push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,(void*)fd);
+    push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,&fd);
     debug(dbg_eachfiledetail,"tarobject NormalFile[01] open size=%lu",
           (unsigned long)ti->Size);
     { char fnamebuf[256];
index 2b83eb69798eb311e149cb1bb7ee4dfafbfa3b0a..a1c2e1f01fef57e9278ec4b6aea23db0e5e2a29c 100644 (file)
@@ -539,7 +539,7 @@ static void md5hash(struct pkginfo *pkg, char hashbuf[33], const char *fn) {
   
   fd= open(fn,O_RDONLY);
   if (fd >= 0) {
-    push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,(void*)&fd);
+    push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,&fd);
     fd_md5(fd, hashbuf, -1, _("md5hash"));
     pop_cleanup(ehflag_normaltidy); /* fd= open(cdr.buf) */
     close(fd);
index 996c4bf7762066e9cf83f20ba5e8f89bd8531624..342aa6e81cd8c32411474f8d70f257d7dcf497b0 100644 (file)
@@ -135,7 +135,7 @@ void ensure_packagefiles_available(struct pkginfo *pkg) {
     return;
   }
 
-  push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,(void*)fd);
+  push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,&fd);
   
    if(fstat(fd, &stat_buf))
      ohshite("unable to stat files list file for package `%.250s'",pkg->name);
index 5f5f4912de36ca55dbbd4af10eb9b4d638830504..5919dadf1019856e6f5125c7879814d157396db9 100644 (file)
@@ -135,8 +135,8 @@ void cu_closedir(int argc, void **argv) {
 }
 
 void cu_closefd(int argc, void **argv) {
-  int *ip= (int*)(argv[0]);
-  close(*ip);
+  int ip= *(int*)argv;
+  close(ip);
 }
 
 int ignore_depends(struct pkginfo *pkg) {
index 516a4c528c39d0a1a4cc00557aa85a8df06f318f..2f649d209a6287942c441518d94b97ce4c473896 100644 (file)
@@ -539,7 +539,7 @@ void process_archive(const char *filename) {
   push_cleanup(cu_fileslist,~0, 0, 0, 0);
   tc.pkg= pkg;
   tc.backendpipe= p1[0];
-  push_cleanup(cu_closefd,~ehflag_bombout, 0,0, 1,(void*)&tc.backendpipe);
+  push_cleanup(cu_closefd,~ehflag_bombout, 0,0, 1,&tc.backendpipe);
 
   r= TarExtractor((void*)&tc, &tf);
   if (r) {