Date: Sat, 5 Jun 2010 06:17:10 GMT From: Julien Laffaye <jlaffaye@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 179200 for review Message-ID: <201006050617.o556HA8L019323@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@179200?ac=10 Change 179200 by jlaffaye@jlaffaye-chulak on 2010/06/05 06:16:29 Changed the prototype of unpack_to_buffer() It is more useful now as we know the size of the buffer. Affected files ... .. //depot/projects/soc2010/pkg_complete/lib/libpkg/file.c#4 edit .. //depot/projects/soc2010/pkg_complete/lib/libpkg/pkg.h#5 edit Differences ... ==== //depot/projects/soc2010/pkg_complete/lib/libpkg/file.c#4 (text+ko) ==== @@ -335,20 +335,18 @@ * 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 an address to a buffer with the contents of *file if successful, or - * returns NULL on failure. + * Returns the size of the buffer if successful, or returns 0 on failure. */ -char* -unpack_to_buffer(const char *pkg, const char *file) +size_t +unpack_to_buffer(const char *pkg, const char *file, char **buf) { struct archive *archive; struct archive_entry *archive_entry; Boolean found_match = FALSE; - int64_t buf_size; + size_t buf_size = 0; - char *buf = NULL; const char *entry_pathname = NULL; const char *error = NULL; int archive_fd = -1; @@ -403,17 +401,20 @@ errno = EINVAL; else { - buf = malloc(sizeof(char)*buf_size); + *buf = malloc(sizeof(char)*buf_size); - if (buf == NULL) + if (*buf == NULL) { error = strerror(errno); - else { + buf_size = 0; + } else { r = archive_read_data(archive, - buf, buf_size); + *buf, buf_size); - if (r != ARCHIVE_OK) + if (r != ARCHIVE_OK) { error = archive_error_string(archive); + buf_size = 0; + } } @@ -435,7 +436,7 @@ if (archive != NULL) archive_read_finish(archive); - return (buf); + return (buf_size); } ==== //depot/projects/soc2010/pkg_complete/lib/libpkg/pkg.h#5 (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); -char* unpack_to_buffer(const char *, const char *); +size_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 *,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006050617.o556HA8L019323>