pkgtools

morpheus pkg tools
git clone git://git.2f30.org/pkgtools
Log | Files | Refs | README | LICENSE

commit 62efb81a806f242bf399455c105d65817e4b95a3
parent 8f296972da876716e26c18ce26d4052ba0237070
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Tue, 17 Jun 2014 17:15:19 +0200

use length of getline to determine newline

and group some variables together etc.

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
Mdb.c | 16+++++++---------
Minfopkg.c | 2+-
2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/db.c b/db.c @@ -107,8 +107,7 @@ dbfscollide(struct db *db, const char *file) struct archive *ar; struct archive_entry *entry; struct stat sb; - int ok = 0; - int r; + int ok = 0, r; realpath(file, pkgpath); @@ -300,8 +299,9 @@ dbpkgload(struct db *db, struct pkg *pkg) struct pkgentry *pe; FILE *fp; char path[PATH_MAX]; - char *buf = NULL, *p; + char *buf = NULL; size_t sz = 0; + ssize_t len; if (pkg->head) return 0; @@ -315,10 +315,9 @@ dbpkgload(struct db *db, struct pkg *pkg) return -1; } - while (getline(&buf, &sz, fp) != -1) { - p = strrchr(buf, '\n'); - if (p) - *p = '\0'; + while ((len = getline(&buf, &sz, fp)) != -1) { + if (len > 0 && buf[len - 1] == '\n') + buf[len - 1] = '\0'; if (buf[0] == '\0') { weprintf("%s: malformed pkg file\n", path); @@ -352,8 +351,7 @@ dbpkginstall(struct db *db, const char *file) char pkgpath[PATH_MAX]; struct archive *ar; struct archive_entry *entry; - int flags; - int r; + int flags, r; realpath(file, pkgpath); diff --git a/infopkg.c b/infopkg.c @@ -19,7 +19,7 @@ usage(void) fprintf(stderr, "usage: %s [-p prefix] [-o filename...]\n", argv0); fprintf(stderr, " -p Set the installation prefix\n"); fprintf(stderr, " -o Look for the packages that own the given filename(s)\n"); - exit(1); + exit(EXIT_FAILURE); } int