pm

barely a pack manager
git clone git://z3bra.org/pm
Log | Files | Refs | README | LICENSE

commit b701a8feda3f99c087b21d82c87429919b056e67
parent cdc4dc147c7d6aece720af47f6fd85e34619635d
Author: z3bra <willyatmailoodotorg>
Date:   Thu Jun 16 11:58:21 +0200

Remove ability to read from stdin

<stdin> should be used to read date, not metadata like filenames. The same
behavior can be reproduced with tools like xargs(1), so it's better to rely on
it than reinventing the wheel badly.

Diffstat:
pm.c | 48+++++-------------------------------------------
1 file changed, 5 insertions(+), 43 deletions(-)
diff --git a/pm.c b/pm.c @@ -14,14 +14,6 @@ #include "arg.h" -/* - * Macro to return the next argument from argv if argc is higher than 0. - * In case argv is 0, it will read and return the next line from stdin. - */ -#define ARGV_OR_STDIN(argc, argv) ((argc>0) ? \ - *argv ? strdup(*(argv++)) : NULL : \ - slurp(0)) - #define PACK_ROOT (getenv("ROOT")?getenv("ROOT"):"") #define PACK_DATA "var/pm" #define PACK_BUFF_SIZE 8192 @@ -58,7 +50,6 @@ void usage(char *name); int is_empty(char *dir); int mkdir_parents(char *dir, mode_t mode); char *base_name(char *path); -char *slurp(int fd); struct pack *pack_load(char *path); void pack_free(struct pack *p); @@ -153,34 +144,6 @@ base_name(char *path) /* - * Fills the array passed as argument with lines read from the file descriptor. - * Returns the number of lines read - */ -char * -slurp(int fd) -{ - size_t len = 0; - off_t i = 0; - char *path = NULL; - - path = malloc(PATH_MAX); - while ((len = read(fd, &path[i], 1)) > 0) { - if (i >= PATH_MAX || path[i] == '\n') { - path[i] = '\0'; - break; - } - i++; - } - - if (i == 0) { - free(path); - path = NULL; - } - return path; -} - - -/* * Check for collisions between the filesystem and the tarball */ int @@ -771,15 +734,14 @@ main (int argc, char **argv) case ACTION_INSTALL: case ACTION_UPDATE: case ACTION_DELETE: - while ((n = ARGV_OR_STDIN(argc, argv)) != NULL) { + while(*argv) { if (action == ACTION_INSTALL) - r += install(rootfs, datadir, n); + r += install(rootfs, datadir, *argv); if (action == ACTION_UPDATE) - r += update(rootfs, datadir, n); + r += update(rootfs, datadir, *argv); if (action == ACTION_DELETE) - r += delete(rootfs, datadir, n); - - free(n); + r += delete(rootfs, datadir, *argv); + argv++; } break; case ACTION_INSPECT: