Date: Mon, 31 May 2010 05:36:59 GMT From: Garrett Cooper <gcooper@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 179001 for review Message-ID: <201005310536.o4V5axj6016172@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@179001?ac=10 Change 179001 by gcooper@gcooper-bayonetta on 2010/05/31 05:36:19 size_t is unsigned; off_t isn't. Switch to off_t in write_file. Drop the buffered I/O through stdio. Affected files ... .. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/file.c#20 edit .. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/pkg.h#13 edit Differences ... ==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/file.c#20 (text+ko) ==== @@ -269,32 +269,29 @@ * Return the number of bytes successfully written out to str or -1 on * failure. */ -size_t +off_t write_file(const char *name, const char *str) { - FILE *fp = NULL; + int fd = -1; + int serrno; off_t written_len = -1; size_t len; - int serrno; errno = 0; - fp = fopen(name, "w"); - if (fp != NULL) { + len = strlen(str); - len = strlen(str); - written_len = fwrite(str, 1, len, fp); + if ((fd = open(name, O_WRONLY | O_CREAT)) != -1) { - if (fp != NULL) { - serrno = errno; - (void) fclose(fp); - if (serrno != 0) - errno = serrno; - } + written_len = write(fd, str, len); + serrno = errno; + (void) close(fd); + if (serrno != 0) + errno = serrno; } - return (size_t) (errno == 0 && written_len > 0 ? written_len : -1); + return (off_t) (errno == 0 && written_len > 0 ? written_len : -1); } ==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/pkg.h#13 (text+ko) ==== @@ -175,7 +175,7 @@ const char *fileGetURL(const char *, const char *, int); char *fileFindByPath(const char *, const char *); char *fileGetContents(const char *); -size_t write_file(const char *, const char *); +off_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 *);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201005310536.o4V5axj6016172>