Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Jun 2009 03:34:51 GMT
From:      David Forsythe <dforsyth@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 163332 for review
Message-ID:  <200906020334.n523Yp3x020838@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=163332

Change 163332 by dforsyth@squirrel on 2009/06/02 03:33:52

	Finished read_file_to_text up.  Need to move it.

Affected files ...

.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_info.c#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.c#4 edit

Differences ...

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#4 (text+ko) ====

@@ -43,6 +43,6 @@
 
 struct pkg_info;
 
-struct pkg_info *pkg_info_digest_info_from_text(const char *text);
+struct pkg_info *pkg_info_parse_info_from_text(const char *text);
 
 #endif

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_info.c#4 (text+ko) ====

@@ -29,7 +29,7 @@
 };
 
 struct pkg_info *
-pkg_info_digest_info_from_text(const char *text)
+pkg_info_parse_info_from_text(const char *text)
 {
 	struct pkg_info *pi;
 

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.c#4 (text+ko) ====

@@ -7,6 +7,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <dirent.h>
+#include <fcntl.h>
 
 #include "pkg_util.h"
 #include "pkg_info.h"
@@ -128,7 +129,7 @@
 		return (NULL);
 	}
 
-	text = pkgdb_read_read_pkg_file_to_text(db, p, COMMENT_FILE);
+	text = pkgdb_read_file_to_text(db, p, COMMENT_FILE);
 	pkg_set_comment(p, text);
 	
 	free(text);
@@ -212,23 +213,30 @@
 	if (path == NULL)
 		return (NULL);
 	strcpy(path, dir);
-	strcat(path, '/');
+	strcat(path, "/");
 	strcat(path, filename);
 
 	s = stat(path, &sb);
-	if (s < 0 || !S_ISREG(st.st_mode)) {
+	if (s < 0 || !S_ISREG(sb.st_mode)) {
 		free(path);
 		return (NULL);
 	}
 
-	fd = open(path, O_READONLY);
-	if (fd < 0) {
-		free(path);
+	fd = open(path, O_RDONLY);
+	free(path);
+	text = malloc(sb.st_size + 1);
+	if (fd < 0 || text == NULL) {
+		free(text);
+		return (NULL);
+	}
+	/* reuse s */
+	s = read(fd, text, sb.st_size);
+	if (s < 0) {
+		free(text);
 		return (NULL);
 	}
-
+	text[sb.st_size] = '\0';
 	
-
 	return (text);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906020334.n523Yp3x020838>