瀏覽代碼

libdpkg: Add a new ar module

For now include a dpkg_ar_normalize_name() function to fix up the
ar_name member in an ar_hdr structure.
Guillem Jover 16 年之前
父節點
當前提交
889375f085
共有 7 個文件被更改,包括 123 次插入0 次删除
  1. 1 0
      lib/dpkg/Makefile.am
  2. 39 0
      lib/dpkg/ar.c
  3. 37 0
      lib/dpkg/ar.h
  4. 1 0
      lib/dpkg/test/.gitignore
  5. 2 0
      lib/dpkg/test/Makefile.am
  6. 42 0
      lib/dpkg/test/t-ar.c
  7. 1 0
      po/POTFILES.in

+ 1 - 0
lib/dpkg/Makefile.am

@@ -19,6 +19,7 @@ libdpkg_a_SOURCES = \
 	dpkg.h \
 	dpkg-db.h \
 	dlist.h \
+	ar.c ar.h \
 	buffer.c buffer.h \
 	cleanup.c \
 	compress.c compress.h \

+ 39 - 0
lib/dpkg/ar.c

@@ -0,0 +1,39 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * ar.c - primitives for ar handling
+ *
+ * Copyright © 2010 Guillem Jover <guillem@debian.org>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <compat.h>
+
+#include <dpkg/ar.h>
+
+void
+dpkg_ar_normalize_name(struct ar_hdr *arh)
+{
+	char *name = arh->ar_name;
+	int i;
+
+	/* Remove trailing spaces from the member name. */
+	for (i = sizeof(arh->ar_name) - 1; i >= 0 && name[i] == ' '; i--)
+		name[i] = '\0';
+
+	/* Remove optional slash terminator (on GNU-style archives). */
+	if (name[i] == '/')
+		name[i] = '\0';
+}

+ 37 - 0
lib/dpkg/ar.h

@@ -0,0 +1,37 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * ar.c - primitives for ar handling
+ *
+ * Copyright © 2010 Guillem Jover <guillem@debian.org>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LIBDPKG_AR_H
+#define LIBDPKG_AR_H
+
+#include <config.h>
+#include <compat.h>
+
+#include <ar.h>
+
+#include <dpkg/macros.h>
+
+DPKG_BEGIN_DECLS
+
+void dpkg_ar_normalize_name(struct ar_hdr *arh);
+
+DPKG_END_DECLS
+
+#endif /* LIBDPKG_AR_H */

+ 1 - 0
lib/dpkg/test/.gitignore

@@ -1,3 +1,4 @@
+t-ar
 t-buffer
 t-macros
 t-path

+ 2 - 0
lib/dpkg/test/Makefile.am

@@ -14,11 +14,13 @@ check_PROGRAMS = \
 	t-buffer \
 	t-path \
 	t-varbuf \
+	t-ar \
 	t-version \
 	t-pkginfo
 
 CHECK_LDADD = ../libdpkg.a
 
+t_ar_LDADD = $(CHECK_LDADD)
 t_macros_LDADD = $(CHECK_LDADD)
 t_path_LDADD = $(CHECK_LDADD)
 t_pkginfo_LDADD = $(CHECK_LDADD)

+ 42 - 0
lib/dpkg/test/t-ar.c

@@ -0,0 +1,42 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * t-ar.c - test ar implementation
+ *
+ * Copyright © 2010 Guillem Jover <guillem@debian.org>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <dpkg/test.h>
+#include <dpkg/ar.h>
+
+static void
+test_ar_normalize_name(void)
+{
+	struct ar_hdr arh;
+
+	strcpy(arh.ar_name, "member-name/     ");
+	dpkg_ar_normalize_name(&arh);
+	test_str(arh.ar_name, ==, "member-name");
+
+	strcpy(arh.ar_name, "member-name      ");
+	dpkg_ar_normalize_name(&arh);
+	test_str(arh.ar_name, ==, "member-name");
+}
+
+void
+test(void)
+{
+	test_ar_normalize_name();
+}

+ 1 - 0
po/POTFILES.in

@@ -1,5 +1,6 @@
 # This is the list of all source files with translatable strings.
 
+lib/dpkg/ar.c
 lib/dpkg/buffer.c
 lib/dpkg/cleanup.c
 lib/dpkg/compression.c