Просмотр исходного кода

libdpkg: Add new dpkg_ar_member_get_size()

Guillem Jover лет назад: 15
Родитель
Сommit
e36ca74003
3 измененных файлов с 29 добавлено и 0 удалено
  1. 25 0
      lib/dpkg/ar.c
  2. 3 0
      lib/dpkg/ar.h
  3. 1 0
      lib/dpkg/libdpkg.Versions

+ 25 - 0
lib/dpkg/ar.c

@@ -47,6 +47,31 @@ dpkg_ar_normalize_name(struct ar_hdr *arh)
 		name[i] = '\0';
 }
 
+off_t
+dpkg_ar_member_get_size(const char *ar_name, struct ar_hdr *arh)
+{
+	const char *str = arh->ar_size;
+	int len = sizeof(arh->ar_size);
+	off_t size = 0;
+
+	while (len && *str == ' ')
+		str++, len--;
+
+	while (len--) {
+		if (*str == ' ')
+			break;
+		if (*str < '0' || *str > '9')
+			ohshit(_("invalid character '%c' in archive '%.250s' "
+			         "member '%.16s' size"),
+			       *str, arh->ar_name, ar_name);
+
+		size *= 10;
+		size += *str++ - '0';
+	}
+
+	return size;
+}
+
 void
 dpkg_ar_put_magic(const char *ar_name, int ar_fd)
 {

+ 3 - 0
lib/dpkg/ar.h

@@ -21,6 +21,8 @@
 #ifndef LIBDPKG_AR_H
 #define LIBDPKG_AR_H
 
+#include <sys/types.h>
+
 #include <ar.h>
 
 #include <dpkg/macros.h>
@@ -38,6 +40,7 @@ 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);
+off_t dpkg_ar_member_get_size(const char *ar_name, struct ar_hdr *arh);
 
 DPKG_END_DECLS
 

+ 1 - 0
lib/dpkg/libdpkg.Versions

@@ -123,6 +123,7 @@ LIBDPKG_PRIVATE {
 	dpkg_ar_member_put_header;
 	dpkg_ar_member_put_file;
 	dpkg_ar_member_put_mem;
+	dpkg_ar_member_get_size;
 
 	# Configuration and command line handling
 	loadcfgfile;