PERFORCE change 163332 for review
David Forsythe
dforsyth at FreeBSD.org
Tue Jun 2 03:34:53 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=163332
Change 163332 by dforsyth at 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);
}
More information about the p4-projects
mailing list