PERFORCE change 179633 for review

Julien Laffaye jlaffaye at FreeBSD.org
Tue Jun 15 03:54:14 UTC 2010


http://p4web.freebsd.org/@@179633?ac=10

Change 179633 by jlaffaye at jlaffaye-chulak on 2010/06/15 03:54:11

	API cleanup: switch unpack_to_buffer return type from size_t to ssize_t.
	The function now makes the difference between error and unpacking a file
	without data.
	Suggested by: gcooper

Affected files ...

.. //depot/projects/soc2010/pkg_complete/lib/libpkg/file.c#7 edit
.. //depot/projects/soc2010/pkg_complete/lib/libpkg/pkg.h#6 edit
.. //depot/projects/soc2010/pkg_complete/lib/libpkg/plist.c#5 edit
.. //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/complete/perform.c#3 edit

Differences ...

==== //depot/projects/soc2010/pkg_complete/lib/libpkg/file.c#7 (text+ko) ====

@@ -335,9 +335,10 @@
  * Unpack a single file, denoted by file, to a buffer. It proceeds to read it
  * into the buffer which will need to be freed by the user at a later date.
  *
- * Returns the size of the buffer if successful, or returns 0 on failure.
+ * Returns the size of the buffer if successful, or returns -1 on failure.
+ * The buffer is only allocated when the size of the file is superior to 0.
  */
-size_t
+ssize_t
 unpack_to_buffer(const char *pkg, const char *file, char **buf)
 {
 
@@ -345,8 +346,8 @@
 	struct archive_entry *archive_entry;
 	Boolean found_match = FALSE;
 
-	size_t buf_size = 0;
-	size_t r;
+	ssize_t buf_size = -1;
+	ssize_t r;
 
 	const char *entry_pathname = NULL;
 	const char *error = NULL;
@@ -397,15 +398,13 @@
 
 				buf_size = archive_entry_size(archive_entry);
 
-				if (buf_size == 0)
-					errno = EINVAL;
-				else {
+				if (buf_size != 0) {
 
 					*buf = malloc(buf_size+1);
 
 					if (*buf == NULL) {
 						error = strerror(errno);
-						buf_size = 0;
+						buf_size = -1;
 					} else {
 
 						r = archive_read_data(archive,
@@ -415,7 +414,8 @@
 
 						if (r != buf_size) {
 							error = archive_error_string(archive);
-							buf_size = 0;
+							buf_size = -1;
+							free(*buf);
 						}
 
 					}

==== //depot/projects/soc2010/pkg_complete/lib/libpkg/pkg.h#6 (text+ko) ====

@@ -178,7 +178,7 @@
 ssize_t		write_file(const char *, const char *);
 int		move_file(const char *, const char *, const char *);
 int		delete_hierarchy(const char *, Boolean, Boolean);
-size_t		unpack_to_buffer(const char *, const char *, char **);
+ssize_t		unpack_to_buffer(const char *, const char *, char **);
 int		unpack_to_disk(const char *, const char *);
 int		unpack_to_fd(const char *, const char *);
 void		format_cmd(char *, int, const char *, const char *,
@@ -199,7 +199,7 @@
 		    const char *name);
 int		write_plist(Package *, FILE *);
 int		read_plist(Package *, int);
-int		read_plist_from_buffer(Package *, char *, off_t);
+int		read_plist_from_buffer(Package *, char *, size_t);
 int		plist_cmd(const char *, char **);
 int		delete_package(Boolean, Boolean, Package *);
 Boolean 	make_preserve_name(char *, int, const char *, const char *);

==== //depot/projects/soc2010/pkg_complete/lib/libpkg/plist.c#5 (text+ko) ====

@@ -321,7 +321,7 @@
  * The buffer is not modified nor is free'ed
  */
 int
-read_plist_from_buffer(Package *pkg, char *plist_buf, off_t plist_size)
+read_plist_from_buffer(Package *pkg, char *plist_buf, size_t plist_size)
 {
 	char *cmd_buf = NULL;
 	char *cp;

==== //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/complete/perform.c#3 (text+ko) ====

@@ -89,7 +89,7 @@
 	Package pkg;
 	PackingList p;
 
-	size_t plist_size;
+	ssize_t plist_size;
 	size_t i;
 	char *plist_buf;
 	char fname[PATH_MAX];
@@ -97,7 +97,7 @@
 	short found = 0;
 
 	if ((plist_size = unpack_to_buffer(pkgname, CONTENTS_FNAME, &plist_buf))
-	    == 0) {
+	    == -1) {
 		warn("unpack_to_buffer()");
 		err = 1;
 	} else {


More information about the p4-projects mailing list