The following commit has been merged in the master branch:
commit 9200eb93dfc61363336d7a29f6ba7a35bb2ac174
Author: Guillem Jover <guil...@debian.org>
Date:   Thu Jul 1 12:25:44 2010 +0200

    libdpkg: Add new dpkg ar support functions

diff --git a/lib/dpkg/ar.c b/lib/dpkg/ar.c
index a62ede6..e33e78f 100644
--- a/lib/dpkg/ar.c
+++ b/lib/dpkg/ar.c
@@ -21,6 +21,15 @@
 #include <config.h>
 #include <compat.h>
 
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <time.h>
+#include <unistd.h>
+
+#include <dpkg/i18n.h>
+#include <dpkg/dpkg.h>
+#include <dpkg/buffer.h>
 #include <dpkg/ar.h>
 
 void
@@ -37,3 +46,57 @@ dpkg_ar_normalize_name(struct ar_hdr *arh)
        if (name[i] == '/')
                name[i] = '\0';
 }
+
+void
+dpkg_ar_put_magic(const char *ar_name, int ar_fd)
+{
+       if (write(ar_fd, DPKG_AR_MAGIC, strlen(DPKG_AR_MAGIC)) < 0)
+               ohshite(_("unable to write file '%s'"), ar_name);
+}
+
+void
+dpkg_ar_member_put_header(const char *ar_name, int ar_fd,
+                          const char *name, size_t size)
+{
+       char header[sizeof(struct ar_hdr)];
+
+       sprintf(header, "%-16s%-12lu0     0     100644  %-10lu`\n",
+               name, time(NULL), (unsigned long)size);
+
+       if (write(ar_fd, header, sizeof(header)) < 0)
+               ohshite(_("unable to write file '%s'"), ar_name);
+}
+
+void
+dpkg_ar_member_put_mem(const char *ar_name, int ar_fd,
+                       const char *name, const void *data, size_t size)
+{
+       dpkg_ar_member_put_header(ar_name, ar_fd, name, size);
+
+       /* Copy data contents. */
+       if (write(ar_fd, data, size) < 0)
+               ohshite(_("unable to write file '%s'"), ar_name);
+
+       if (size & 1)
+               if (write(ar_fd, "\n", 1) < 0)
+                       ohshite(_("unable to write file '%s'"), ar_name);
+}
+
+void
+dpkg_ar_member_put_file(const char *ar_name, int ar_fd,
+                        const char *name, int fd)
+{
+       struct stat st;
+
+       if (fstat(fd, &st))
+               ohshite(_("failed to fstat ar member file (%s)"), name);
+
+       dpkg_ar_member_put_header(ar_name, ar_fd, name, st.st_size);
+
+       /* Copy data contents. */
+       fd_fd_copy(fd, ar_fd, -1, name);
+
+       if (st.st_size & 1)
+               if (write(ar_fd, "\n", 1) < 0)
+                       ohshite(_("unable to write file '%s'"), ar_name);
+}
diff --git a/lib/dpkg/ar.h b/lib/dpkg/ar.h
index 80ea478..f3ccd65 100644
--- a/lib/dpkg/ar.h
+++ b/lib/dpkg/ar.h
@@ -31,6 +31,14 @@ DPKG_BEGIN_DECLS
 
 void dpkg_ar_normalize_name(struct ar_hdr *arh);
 
+void dpkg_ar_put_magic(const char *ar_name, int ar_fd);
+void dpkg_ar_member_put_header(const char *ar_name, int ar_fd,
+                               const char *name, size_t size);
+void dpkg_ar_member_put_file(const char *ar_name, int ar_fd, const char *name,
+                             int fd);
+void dpkg_ar_member_put_mem(const char *ar_name, int ar_fd, const char *name,
+                            const void *data, size_t size);
+
 DPKG_END_DECLS
 
 #endif /* LIBDPKG_AR_H */
diff --git a/lib/dpkg/libdpkg.Versions b/lib/dpkg/libdpkg.Versions
index 2caf3f6..11cd126 100644
--- a/lib/dpkg/libdpkg.Versions
+++ b/lib/dpkg/libdpkg.Versions
@@ -108,6 +108,12 @@ LIBDPKG_PRIVATE {
        compress_filter;
        decompress_filter;
 
+       # Ar support
+       dpkg_ar_put_magic;
+       dpkg_ar_member_put_header;
+       dpkg_ar_member_put_file;
+       dpkg_ar_member_put_mem;
+
        # Configuration and command line handling
        loadcfgfile;
        myopt;

-- 
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