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.
+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
#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;
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]);
{
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;
}
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);
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;
}
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:
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;
#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) {
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);
*/
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];
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);
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);
}
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) {
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) {