The following commit has been merged in the master branch:
commit e8c1a5863572eac719e36b2e409002871e6eee4a
Author: Guillem Jover <guil...@debian.org>
Date:   Sun May 1 08:06:53 2011 +0200

    libdpkg: Add new buffer_skip_Int() and switch fd_null_copy() to it
    
    Add a new buffer_skip() function and the externally visible
    buffer_skip_Int(), this way we hide the implementation details
    of fd_null_copy().

diff --git a/lib/dpkg/buffer.c b/lib/dpkg/buffer.c
index 3654f4f..c99af0f 100644
--- a/lib/dpkg/buffer.c
+++ b/lib/dpkg/buffer.c
@@ -25,6 +25,7 @@
 
 #include <sys/types.h>
 
+#include <errno.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -247,3 +248,45 @@ buffer_copy_IntPtr(int Iin, int Tin,
 
        return ret;
 }
+
+static off_t
+buffer_skip(struct buffer_data *input, off_t limit, const char *desc)
+{
+       struct buffer_data output;
+
+       switch (input->type) {
+       case BUFFER_READ_FD:
+               if (lseek(input->arg.i, limit, SEEK_CUR) != -1)
+                       return limit;
+               if (errno != ESPIPE)
+                       ohshite(_("failed to seek %s"), desc);
+               break;
+       default:
+               internerr("unknown data type '%i' in buffer_skip\n",
+                         input->type);
+       }
+
+       output.type = BUFFER_WRITE_NULL;
+       output.arg.ptr = NULL;
+
+       return buffer_copy(input, &output, limit, desc);
+}
+
+off_t
+buffer_skip_Int(int I, int T, off_t limit, const char *desc_fmt, ...)
+{
+       va_list args; \
+       struct buffer_data input = { .type = T, .arg.i = I };
+       struct varbuf v = VARBUF_INIT;
+       off_t ret;
+
+       va_start(args, desc_fmt);
+       varbuf_vprintf(&v, desc_fmt, args);
+       va_end(args);
+
+       ret = buffer_skip(&input, limit, v.buf);
+
+       varbuf_destroy(&v);
+
+       return ret;
+}
diff --git a/lib/dpkg/buffer.h b/lib/dpkg/buffer.h
index 071c08e..c81ef1c 100644
--- a/lib/dpkg/buffer.h
+++ b/lib/dpkg/buffer.h
@@ -26,8 +26,6 @@
 
 #include <sys/types.h>
 
-#include <errno.h>
-
 #include <dpkg/macros.h>
 
 DPKG_BEGIN_DECLS
@@ -60,13 +58,7 @@ struct buffer_data {
        buffer_copy_IntPtr(fd, BUFFER_READ_FD, buf, BUFFER_WRITE_VBUF, \
                           limit, __VA_ARGS__)
 # define fd_null_copy(fd, limit, ...) \
-       if (lseek(fd, limit, SEEK_CUR) == -1) { \
-               if (errno != ESPIPE) \
-                       ohshite(__VA_ARGS__); \
-               buffer_copy_IntPtr(fd, BUFFER_READ_FD, \
-                                  NULL, BUFFER_WRITE_NULL, \
-                                  limit, __VA_ARGS__); \
-       }
+       buffer_skip_Int(fd, BUFFER_READ_FD, limit, __VA_ARGS__)
 
 off_t buffer_copy_IntPtr(int i, int typeIn, void *p, int typeOut,
                          off_t limit, const char *desc,
@@ -74,6 +66,8 @@ off_t buffer_copy_IntPtr(int i, int typeIn, void *p, int 
typeOut,
 off_t buffer_copy_IntInt(int i1, int typeIn, int i2, int typeOut,
                          off_t limit, const char *desc,
                          ...) DPKG_ATTR_PRINTF(6);
+off_t buffer_skip_Int(int I, int T, off_t limit, const char *desc_fmt, ...)
+                      DPKG_ATTR_PRINTF(4);
 off_t buffer_hash(const void *buf, void *hash, int typeOut, off_t length);
 
 DPKG_END_DECLS

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to debian-dpkg-cvs-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to