package

simple and robust package manager
Log | Files | Refs | README

commit a5a090fb79c24a52f783094032fc1807fab3a86b
parent ec04b033d02f3ee762415ad1114bffc6f694c6ce
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sat, 19 Jan 2019 12:48:21 +0100

cleanup and debug the source

Diffstat:
M.gitignore | 1+
MMakefile | 11+++++++----
Mbuffer.c | 7+++----
Mbuffer.h | 4++--
Mforkexec.c | 5++---
Mforkexec.h | 2+-
Mhier.c | 1-
Mlock.h | 1+
Mlog.c | 6+++---
Mlog.h | 150++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mmake-mk | 2+-
Mmake-o | 2+-
Mpackage-add.c | 40+++++++++++++---------------------------
Mpackage-build.c | 116++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mpackage-dep.c | 10+++++-----
Mpackage-get.c | 87++++++++++++++++++++++++++++++++-----------------------------------------------
Mpackage-install.c | 50++++++++++++++++++++++++++++++++++++++++++--------
Mpackage-tree.c | 9+++++----
Mpackage.c | 28+---------------------------
Mpackage.h | 1-
Mstr.c | 4++--
21 files changed, 259 insertions(+), 278 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -5,3 +5,4 @@ package-add package-dep package-get package-tree +package-install diff --git a/Makefile b/Makefile @@ -1,4 +1,4 @@ -bin = package-build package-dep package-get package-tree package-add +bin = package-build package-dep package-get package-tree package-add package-install obj = package.o buffer.o fmt.o stat.o hier.o log.o mem.o str.o stralloc.o forkexec.o tai.o tain.o .PHONY: all @@ -10,8 +10,8 @@ clean: .PHONY: install install: all - mkdir -p ${PREFIX} - cp -r bin ${PREFIX} + mkdir -p ${PREFIX}/bin + cp bin/* ${PREFIX}/bin cp ${bin} ${PREFIX}/bin package-build: package-build.o ${obj} @@ -29,6 +29,9 @@ package-get: package-get.o ${obj} package-tree: package-tree.o ${obj} ./make-bin $@ package-tree.o ${obj} +package-install: package-install.o ${obj} + ./make-bin $@ package-install.o ${obj} + .c.o: ./make-o $< @@ -42,7 +45,7 @@ package-add.o: package-add.c buffer.h fmt.h genalloc.h log.h package.h stat package-build.o: package-build.c buffer.h env.h fmt.h forkexec.h hier.h hier.h log.h open.h package.h stat.h str.h stralloc.h tain.h package-dep.o: package-dep.c buffer.h env.h stat.h genalloc.h log.h package.h str.h package-get.o: package-get.c buffer.h env.h forkexec.h hier.h lock.h log.h open.h package.h stat.h stralloc.h -package-install.o: package-install.c package.h +package-install.o: package-install.c package.h log.h stat.h hier.h package-tree.o: package-tree.c buffer.h env.h log.h open.h package.h stat.h stralloc.h package.o: package.c buffer.h env.h fmt.h forkexec.h genalloc.h mem.h open.h package.h stralloc.h lock.h tai.h stat.o: stat.c stat.h diff --git a/buffer.c b/buffer.c @@ -154,11 +154,11 @@ buffer_readall(ssize_t (*op)(), int fd, char *buf, size_t len) return n; } -size_t +ssize_t buffer_gettoken(buffer *b, stralloc *sa, char x) { ssize_t r; - size_t n = 0; + ssize_t n = 0; char c; while ((r = buffer_getc(b, &c)) > 0) { @@ -169,9 +169,8 @@ buffer_gettoken(buffer *b, stralloc *sa, char x) return (r == 0) ? n : r; } -size_t +ssize_t buffer_putc(buffer *b, char c) { return buffer_put(b, &c, 1); } - diff --git a/buffer.h b/buffer.h @@ -26,11 +26,11 @@ extern buffer *buffer_2; #define buffer_getline(b, sa) buffer_gettoken(b, sa, '\n') int buffer_put(buffer *, const char *, size_t); -size_t buffer_gettoken(buffer *, stralloc *, char); -size_t buffer_putc(buffer *, char); ssize_t buffer_fill(buffer *); ssize_t buffer_flush(buffer *); ssize_t buffer_get(buffer *, char *, size_t); +ssize_t buffer_gettoken(buffer *, stralloc *, char); +ssize_t buffer_putc(buffer *, char); ssize_t buffer_read(ssize_t (*op)(), int, char *, size_t); ssize_t buffer_readall(ssize_t (*op)(), int, char *, size_t); ssize_t buffer_write(ssize_t (*op)(), int, char const *, size_t); diff --git a/forkexec.c b/forkexec.c @@ -24,7 +24,7 @@ forkexec_wait(char const *argv[]) } int -forkexec_wait_redir(char const *argv[], int fd) +forkexec_redir(char const *argv[], int from, int to) { pid_t pid = 0; int st; @@ -33,8 +33,7 @@ forkexec_wait_redir(char const *argv[], int fd) case -1: return -1; case 0: - close(1); if (dup(fd) == -1) exit(126); - close(2); if (dup(fd) == -1) exit(126); + close(from); if (dup(to) == -1) exit(126); execvp(*argv, (char *const *) argv); exit(127); } diff --git a/forkexec.h b/forkexec.h @@ -1,7 +1,7 @@ #ifndef FORKEXEC_H #define FORKEXEC_H +int forkexec_redir(char const *argv[], int, int); int forkexec_wait(char const *argv[]); -int forkexec_wait_redir(char const *argv[], int); #endif diff --git a/hier.c b/hier.c @@ -129,7 +129,6 @@ hier_copy_recurse(stralloc *from, stralloc *to, int action) if (!stralloc_cat0(from)) break; if (lstat(from->x, &st) == -1) break; - if (S_ISDIR(st.st_mode)) { if (mkdir(to->x, st.st_mode) == -1 && errno != EEXIST) break; if (!hier_copy_recurse(from, to, action)) break; diff --git a/lock.h b/lock.h @@ -1,6 +1,7 @@ #ifndef LOCK_H #define LOCK_H +#include <sys/file.h> #include <fcntl.h> #define lock_shared(fd) (!flock((fd), LOCK_SH)) diff --git a/log.c b/log.c @@ -35,7 +35,7 @@ log_put(int level, char const *type, int argc, ...) } void -log_putsys(int level, char const *type, int argc, ...) +log_put_sys(int level, char const *type, int argc, ...) { va_list a; @@ -56,7 +56,7 @@ log_putsys(int level, char const *type, int argc, ...) } void -log_die(int e, char const *type, int argc, ...) +log_fatal(int e, char const *type, int argc, ...) { va_list a; @@ -76,7 +76,7 @@ log_die(int e, char const *type, int argc, ...) } void -log_diesys(int e, char const *type, int argc, ...) +log_fatal_sys(int e, char const *type, int argc, ...) { va_list a; diff --git a/log.h b/log.h @@ -1,90 +1,90 @@ #ifndef STRERR_H #define STRERR_H -#define log_die1(x, a) log_die(x, "fatal", 1, a) -#define log_die2(x, a,b) log_die(x, "fatal", 2, a,b) -#define log_die3(x, a,b,c) log_die(x, "fatal", 3, a,b,c) -#define log_die4(x, a,b,c,d) log_die(x, "fatal", 4, a,b,c,d) -#define log_die5(x, a,b,c,d,e) log_die(x, "fatal", 5, a,b,c,d,e) -#define log_die6(x, a,b,c,d,e,f) log_die(x, "fatal", 6, a,b,c,d,e,f) -#define log_die7(x, a,b,c,d,e,f,g) log_die(x, "fatal", 7, a,b,c,d,e,f,g) -#define log_die8(x, a,b,c,d,e,f,g,h) log_die(x, "fatal", 8, a,b,c,d,e,f,g,h) -#define log_die9(x, a,b,c,d,e,f,g,h,i) log_die(x, "fatal", 9, a,b,c,d,e,f,g,h,i) -#define log_diesys1(x, a) log_diesys(x, "fatal", 1, a) -#define log_diesys2(x, a,b) log_diesys(x, "fatal", 2, a,b) -#define log_diesys3(x, a,b,c) log_diesys(x, "fatal", 3, a,b,c) -#define log_diesys4(x, a,b,c,d) log_diesys(x, "fatal", 4, a,b,c,d) -#define log_diesys5(x, a,b,c,d,e) log_diesys(x, "fatal", 5, a,b,c,d,e) -#define log_diesys6(x, a,b,c,d,e,f) log_diesys(x, "fatal", 6, a,b,c,d,e,f) -#define log_diesys7(x, a,b,c,d,e,f,g) log_diesys(x, "fatal", 7, a,b,c,d,e,f,g) -#define log_diesys8(x, a,b,c,d,e,f,g,h) log_diesys(x, "fatal", 8, a,b,c,d,e,f,g,h) -#define log_diesys9(x, a,b,c,d,e,f,g,h,i) log_diesys(x, "fatal", 9, a,b,c,d,e,f,g,h,i) +#define log_fatal_1(x, a) log_fatal(x, "fatal", 1, a) +#define log_fatal_2(x, a,b) log_fatal(x, "fatal", 2, a,b) +#define log_fatal_3(x, a,b,c) log_fatal(x, "fatal", 3, a,b,c) +#define log_fatal_4(x, a,b,c,d) log_fatal(x, "fatal", 4, a,b,c,d) +#define log_fatal_5(x, a,b,c,d,e) log_fatal(x, "fatal", 5, a,b,c,d,e) +#define log_fatal_6(x, a,b,c,d,e,f) log_fatal(x, "fatal", 6, a,b,c,d,e,f) +#define log_fatal_7(x, a,b,c,d,e,f,g) log_fatal(x, "fatal", 7, a,b,c,d,e,f,g) +#define log_fatal_8(x, a,b,c,d,e,f,g,h) log_fatal(x, "fatal", 8, a,b,c,d,e,f,g,h) +#define log_fatal_9(x, a,b,c,d,e,f,g,h,i) log_fatal(x, "fatal", 9, a,b,c,d,e,f,g,h,i) +#define log_fatal_sys_1(x, a) log_fatal_sys(x, "fatal", 1, a) +#define log_fatal_sys_2(x, a,b) log_fatal_sys(x, "fatal", 2, a,b) +#define log_fatal_sys_3(x, a,b,c) log_fatal_sys(x, "fatal", 3, a,b,c) +#define log_fatal_sys_4(x, a,b,c,d) log_fatal_sys(x, "fatal", 4, a,b,c,d) +#define log_fatal_sys_5(x, a,b,c,d,e) log_fatal_sys(x, "fatal", 5, a,b,c,d,e) +#define log_fatal_sys_6(x, a,b,c,d,e,f) log_fatal_sys(x, "fatal", 6, a,b,c,d,e,f) +#define log_fatal_sys_7(x, a,b,c,d,e,f,g) log_fatal_sys(x, "fatal", 7, a,b,c,d,e,f,g) +#define log_fatal_sys_8(x, a,b,c,d,e,f,g,h) log_fatal_sys(x, "fatal", 8, a,b,c,d,e,f,g,h) +#define log_fatal_sys_9(x, a,b,c,d,e,f,g,h,i) log_fatal_sys(x, "fatal", 9, a,b,c,d,e,f,g,h,i) -#define log_err1(a) log_put(2, "error", 1, a) -#define log_err2(a,b) log_put(2, "error", 2, a,b) -#define log_err3(a,b,c) log_put(2, "error", 3, a,b,c) -#define log_err4(a,b,c,d) log_put(2, "error", 4, a,b,c,d) -#define log_err5(a,b,c,d,e) log_put(2, "error", 5, a,b,c,d,e) -#define log_err6(a,b,c,d,e,f) log_put(2, "error", 6, a,b,c,d,e,f) -#define log_err7(a,b,c,d,e,f,g) log_put(2, "error", 7, a,b,c,d,e,f,g) -#define log_err8(a,b,c,d,e,f,g,h) log_put(2, "error", 8, a,b,c,d,e,f,g,h) -#define log_err9(a,b,c,d,e,f,g,h,i) log_put(2, "error", 9, a,b,c,d,e,f,g,h,i) -#define log_errsys1(a) log_putsys(2, "error", 1, a) -#define log_errsys2(a,b) log_putsys(2, "error", 2, a,b) -#define log_errsys3(a,b,c) log_putsys(2, "error", 3, a,b,c) -#define log_errsys4(a,b,c,d) log_putsys(2, "error", 4, a,b,c,d) -#define log_errsys5(a,b,c,d,e) log_putsys(2, "error", 5, a,b,c,d,e) -#define log_errsys6(a,b,c,d,e,f) log_putsys(2, "error", 6, a,b,c,d,e,f) -#define log_errsys7(a,b,c,d,e,f,g) log_putsys(2, "error", 7, a,b,c,d,e,f,g) -#define log_errsys8(a,b,c,d,e,f,g,h) log_putsys(2, "error", 8, a,b,c,d,e,f,g,h) -#define log_errsys9(a,b,c,d,e,f,g,h,i) log_putsys(2, "error", 9, a,b,c,d,e,f,g,h,i) +#define log_error_1(a) log_put(2, "error", 1, a) +#define log_error_2(a,b) log_put(2, "error", 2, a,b) +#define log_error_3(a,b,c) log_put(2, "error", 3, a,b,c) +#define log_error_4(a,b,c,d) log_put(2, "error", 4, a,b,c,d) +#define log_error_5(a,b,c,d,e) log_put(2, "error", 5, a,b,c,d,e) +#define log_error_6(a,b,c,d,e,f) log_put(2, "error", 6, a,b,c,d,e,f) +#define log_error_7(a,b,c,d,e,f,g) log_put(2, "error", 7, a,b,c,d,e,f,g) +#define log_error_8(a,b,c,d,e,f,g,h) log_put(2, "error", 8, a,b,c,d,e,f,g,h) +#define log_error_9(a,b,c,d,e,f,g,h,i) log_put(2, "error", 9, a,b,c,d,e,f,g,h,i) +#define log_error_sys_1(a) log_put_sys(2, "error", 1, a) +#define log_error_sys_2(a,b) log_put_sys(2, "error", 2, a,b) +#define log_error_sys_3(a,b,c) log_put_sys(2, "error", 3, a,b,c) +#define log_error_sys_4(a,b,c,d) log_put_sys(2, "error", 4, a,b,c,d) +#define log_error_sys_5(a,b,c,d,e) log_put_sys(2, "error", 5, a,b,c,d,e) +#define log_error_sys_6(a,b,c,d,e,f) log_put_sys(2, "error", 6, a,b,c,d,e,f) +#define log_error_sys_7(a,b,c,d,e,f,g) log_put_sys(2, "error", 7, a,b,c,d,e,f,g) +#define log_error_sys_8(a,b,c,d,e,f,g,h) log_put_sys(2, "error", 8, a,b,c,d,e,f,g,h) +#define log_error_sys_9(a,b,c,d,e,f,g,h,i) log_put_sys(2, "error", 9, a,b,c,d,e,f,g,h,i) -#define log_warn1(a) log_put(3, "warning", 1, a) -#define log_warn2(a,b) log_put(3, "warning", 2, a,b) -#define log_warn3(a,b,c) log_put(3, "warning", 3, a,b,c) -#define log_warn4(a,b,c,d) log_put(3, "warning", 4, a,b,c,d) -#define log_warn5(a,b,c,d,e) log_put(3, "warning", 5, a,b,c,d,e) -#define log_warn6(a,b,c,d,e,f) log_put(3, "warning", 6, a,b,c,d,e,f) -#define log_warn7(a,b,c,d,e,f,g) log_put(3, "warning", 7, a,b,c,d,e,f,g) -#define log_warn8(a,b,c,d,e,f,g,h) log_put(3, "warning", 8, a,b,c,d,e,f,g,h) -#define log_warn9(a,b,c,d,e,f,g,h,i) log_put(3, "warning", 9, a,b,c,d,e,f,g,h,i) -#define log_warnsys1(a) log_putsys(3, "warning", 1, a) -#define log_warnsys2(a,b) log_putsys(3, "warning", 2, a,b) -#define log_warnsys3(a,b,c) log_putsys(3, "warning", 3, a,b,c) -#define log_warnsys4(a,b,c,d) log_putsys(3, "warning", 4, a,b,c,d) -#define log_warnsys5(a,b,c,d,e) log_putsys(3, "warning", 5, a,b,c,d,e) -#define log_warnsys6(a,b,c,d,e,f) log_putsys(3, "warning", 6, a,b,c,d,e,f) -#define log_warnsys7(a,b,c,d,e,f,g) log_putsys(3, "warning", 7, a,b,c,d,e,f,g) -#define log_warnsys8(a,b,c,d,e,f,g,h) log_putsys(3, "warning", 8, a,b,c,d,e,f,g,h) -#define log_warnsys9(a,b,c,d,e,f,g,h,i) log_putsys(3, "warning", 9, a,b,c,d,e,f,g,h,i) +#define log_warn_1(a) log_put(3, "warning", 1, a) +#define log_warn_2(a,b) log_put(3, "warning", 2, a,b) +#define log_warn_3(a,b,c) log_put(3, "warning", 3, a,b,c) +#define log_warn_4(a,b,c,d) log_put(3, "warning", 4, a,b,c,d) +#define log_warn_5(a,b,c,d,e) log_put(3, "warning", 5, a,b,c,d,e) +#define log_warn_6(a,b,c,d,e,f) log_put(3, "warning", 6, a,b,c,d,e,f) +#define log_warn_7(a,b,c,d,e,f,g) log_put(3, "warning", 7, a,b,c,d,e,f,g) +#define log_warn_8(a,b,c,d,e,f,g,h) log_put(3, "warning", 8, a,b,c,d,e,f,g,h) +#define log_warn_9(a,b,c,d,e,f,g,h,i) log_put(3, "warning", 9, a,b,c,d,e,f,g,h,i) +#define log_warn_sys_1(a) log_put_sys(3, "warning", 1, a) +#define log_warn_sys_2(a,b) log_put_sys(3, "warning", 2, a,b) +#define log_warn_sys_3(a,b,c) log_put_sys(3, "warning", 3, a,b,c) +#define log_warn_sys_4(a,b,c,d) log_put_sys(3, "warning", 4, a,b,c,d) +#define log_warn_sys_5(a,b,c,d,e) log_put_sys(3, "warning", 5, a,b,c,d,e) +#define log_warn_sys_6(a,b,c,d,e,f) log_put_sys(3, "warning", 6, a,b,c,d,e,f) +#define log_warn_sys_7(a,b,c,d,e,f,g) log_put_sys(3, "warning", 7, a,b,c,d,e,f,g) +#define log_warn_sys_8(a,b,c,d,e,f,g,h) log_put_sys(3, "warning", 8, a,b,c,d,e,f,g,h) +#define log_warn_sys_9(a,b,c,d,e,f,g,h,i) log_put_sys(3, "warning", 9, a,b,c,d,e,f,g,h,i) -#define log_info1(a) log_put(4, "info", 1, a) -#define log_info2(a,b) log_put(4, "info", 2, a,b) -#define log_info3(a,b,c) log_put(4, "info", 3, a,b,c) -#define log_info4(a,b,c,d) log_put(4, "info", 4, a,b,c,d) -#define log_info5(a,b,c,d,e) log_put(4, "info", 5, a,b,c,d,e) -#define log_info6(a,b,c,d,e,f) log_put(4, "info", 6, a,b,c,d,e,f) -#define log_info7(a,b,c,d,e,f,g) log_put(4, "info", 7, a,b,c,d,e,f,g) -#define log_info8(a,b,c,d,e,f,g,h) log_put(4, "info", 8, a,b,c,d,e,f,g,h) -#define log_info9(a,b,c,d,e,f,g,h,i) log_put(4, "info", 9, a,b,c,d,e,f,g,h,i) +#define log_info_1(a) log_put(4, "info", 1, a) +#define log_info_2(a,b) log_put(4, "info", 2, a,b) +#define log_info_3(a,b,c) log_put(4, "info", 3, a,b,c) +#define log_info_4(a,b,c,d) log_put(4, "info", 4, a,b,c,d) +#define log_info_5(a,b,c,d,e) log_put(4, "info", 5, a,b,c,d,e) +#define log_info_6(a,b,c,d,e,f) log_put(4, "info", 6, a,b,c,d,e,f) +#define log_info_7(a,b,c,d,e,f,g) log_put(4, "info", 7, a,b,c,d,e,f,g) +#define log_info_8(a,b,c,d,e,f,g,h) log_put(4, "info", 8, a,b,c,d,e,f,g,h) +#define log_info_9(a,b,c,d,e,f,g,h,i) log_put(4, "info", 9, a,b,c,d,e,f,g,h,i) -#define log_debug1(a) log_put(5, "debug", 1, a) -#define log_debug2(a,b) log_put(5, "debug", 2, a,b) -#define log_debug3(a,b,c) log_put(5, "debug", 3, a,b,c) -#define log_debug4(a,b,c,d) log_put(5, "debug", 4, a,b,c,d) -#define log_debug5(a,b,c,d,e) log_put(5, "debug", 5, a,b,c,d,e) -#define log_debug6(a,b,c,d,e,f) log_put(5, "debug", 6, a,b,c,d,e,f) -#define log_debug7(a,b,c,d,e,f,g) log_put(5, "debug", 7, a,b,c,d,e,f,g) -#define log_debug8(a,b,c,d,e,f,g,h) log_put(5, "debug", 8, a,b,c,d,e,f,g,h) -#define log_debug9(a,b,c,d,e,f,g,h,i) log_put(5, "debug", 9, a,b,c,d,e,f,g,h,i) +#define log_debug_1(a) log_put(5, "debug", 1, a) +#define log_debug_2(a,b) log_put(5, "debug", 2, a,b) +#define log_debug_3(a,b,c) log_put(5, "debug", 3, a,b,c) +#define log_debug_4(a,b,c,d) log_put(5, "debug", 4, a,b,c,d) +#define log_debug_5(a,b,c,d,e) log_put(5, "debug", 5, a,b,c,d,e) +#define log_debug_6(a,b,c,d,e,f) log_put(5, "debug", 6, a,b,c,d,e,f) +#define log_debug_7(a,b,c,d,e,f,g) log_put(5, "debug", 7, a,b,c,d,e,f,g) +#define log_debug_8(a,b,c,d,e,f,g,h) log_put(5, "debug", 8, a,b,c,d,e,f,g,h) +#define log_debug_9(a,b,c,d,e,f,g,h,i) log_put(5, "debug", 9, a,b,c,d,e,f,g,h,i) extern int log_level; -void log_die(int, char const *, int, ...); -void log_diesys(int, char const *, int, ...); +void log_fatal(int, char const *, int, ...); +void log_fatal_sys(int, char const *, int, ...); void log_init(int); void log_put(int, char const *, int, ...); -void log_putsys(int, char const *, int, ...); +void log_put_sys(int, char const *, int, ...); void log_usage(char const *, char const *); #endif diff --git a/make-mk b/make-mk @@ -3,6 +3,6 @@ for file in "$@" do - printf '%-16s %-16s ' "${file%.c}.o:" "$file" | tr -d '\n' + printf '%-17s %-17s ' "${file%.c}.o:" "$file" | tr -d '\n' sed -rn 's/^#include "([^"]+.h)".*$/\1/p' "$file" | xargs done diff --git a/make-o b/make-o @@ -1,2 +1,2 @@ #!/bin/sh -exec cc -Wno-unknown-warning-option -Wall -Wextra -Wno-misleading-indentation -std=c99 -pedantic -c "$@" +exec cc -D_POSIX_SOURCE -Wall -Wextra -Wno-misleading-indentation -std=c99 -pedantic -c "$@" diff --git a/package-add.c b/package-add.c @@ -14,13 +14,13 @@ void usage(char *argv0) { - log_usage(argv0, "-p pkgdir -d defdir packageage[/version]"); + log_usage(argv0, "-p pkgdir -d defdir package[/version]"); } void die_nomem(void) { - log_diesys1(100, "malloc"); + log_fatal_sys_1(100, "malloc"); } int @@ -43,19 +43,19 @@ main(int argc, char **argv) if (!*av) usage(*argv); - if (!stat_isdir(def)) log_diesys1(101, def); - if (!stat_isdir(pkg)) log_diesys1(101, pkg); + if (!stat_isdir(def)) log_fatal_sys_1(101, def); + if (!stat_isdir(pkg)) log_fatal_sys_1(101, pkg); n = package_scan(&p, *av); if (n == 0 || (*av)[n] != '\0') - log_die2(1, "invalid packageage name: ", *av); + log_fatal_2(1, "invalid packageage name: ", *av); if (!package_version(&p, def)) - log_diesys3(101, "could not get ", *av," version"); + log_fatal_sys_3(101, "could not read ", *av,"'s version"); genalloc_init(&ga); if (!package_dep(&p, &ga, def)) - log_diesys1(103, "could not resolve packageage dependencies"); + log_fatal_sys_1(103, "could not resolve packageage dependencies"); if (!genalloc_append(&ga, p)) die_nomem(); for (size_t i = 0; i < genalloc_len(&ga, package); ++i) @@ -66,12 +66,7 @@ main(int argc, char **argv) char const *argv[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; int x; - buffer_puts(buffer_2, " "); - buffer_puts(buffer_2, p->name); - buffer_puts(buffer_2, " "); - buffer_puts(buffer_2, p->ver); - buffer_puts(buffer_2, "\n"); - buffer_flush(buffer_2); + log_info_5("[ ", p->name, "/", p->ver, " ]"); fmt[package_fmt(p, fmt)] = '\0'; @@ -101,31 +96,22 @@ main(int argc, char **argv) if (!stralloc_cat0(&sa)) die_nomem(); if (stat_isfile(sa.x)) goto build; - buffer_puts(buffer_2, " package-get ....... "); - buffer_flush(buffer_2); + log_info_1("package-get"); argv[0] = "package-get"; if ((x = forkexec_wait(argv)) != 0) goto error; - buffer_puts(buffer_2, "ok\n"); - buffer_flush(buffer_2); build: - buffer_puts(buffer_2, " package-build ..... "); - buffer_flush(buffer_2); + log_info_1("package-build"); argv[0] = "package-build"; if ((x = forkexec_wait(argv)) != 0) goto error; - buffer_puts(buffer_2, "ok\n"); - buffer_flush(buffer_2); install: - buffer_puts(buffer_2, " package-install ... "); - buffer_flush(buffer_2); + log_info_1("package-install"); argv[0] = "package-install"; if ((x = forkexec_wait(argv)) != 0) goto error; - buffer_puts(buffer_2, "ok\n"); - buffer_flush(buffer_2); continue; error: - buffer_puts(buffer_2, "error\n"); - buffer_flush(buffer_2); + fmt[fmt_long(fmt, x)] = '\0'; + log_error_2("exited with status ", fmt); return x; } genalloc_free(&ga); diff --git a/package-build.c b/package-build.c @@ -1,5 +1,4 @@ #include <sys/types.h> -#include <sys/dirent.h> #include <sys/stat.h> #include <ctype.h> #include <dirent.h> @@ -12,6 +11,7 @@ #include "forkexec.h" #include "hier.h" #include "hier.h" +#include "lock.h" #include "log.h" #include "open.h" #include "package.h" @@ -24,13 +24,8 @@ static int untar(void) { char const *argv[] = { "tar", "-x", "-f", "../../source.tar", NULL }; - int fd; - int x; - if ((fd = open_trunc("../log/1-untar")) == -1) return 0; - x = forkexec_wait_redir(argv, fd); - close(fd); - return x; + return forkexec_redir(argv, 2, 1); } static int @@ -54,8 +49,6 @@ patch(package const *p, char *def) if (!stralloc_cats(&sa, "/")) goto err; n = sa.n; - close(2); - if ((fd = open_trunc("../log/2-patch")) == -1) goto err; d[0] = "default"; d[1] = p->ver; for (i = 0; i < 2; ++i) { @@ -76,26 +69,24 @@ patch(package const *p, char *def) sa.n = m; if (!stralloc_cats(&sa, de->d_name)) goto err; if (!stralloc_cat0(&sa)) goto err; - close(0); - if (open_read(sa.x) == -1) goto err; - if (write(fd, "=== patch ===\n", 14) == -1) goto err; - if (forkexec_wait_redir(argv, fd) != 0) goto err; - if (write(fd, "\n", 1) == -1) goto err; + if ((fd = open_read(sa.x)) == -1) goto err; + if (forkexec_redir(argv, 0, fd) != 0) goto err; + if (write(1, "\n", 1) == -1) goto err; + close(fd); } closedir(dp); } ret = 1; err: - close(0); + if (fd >= 0) close(fd); stralloc_free(&sa); - if (fd >= 0) { write(fd, "=== end ===\n", 12); close(fd); } if (ret == 0) closedir(dp); return ret; } static int -data(package const *p, char const *def) +copy(package const *p, char const *def) { stralloc sa = STRALLOC_ZERO; size_t n; @@ -107,8 +98,6 @@ data(package const *p, char const *def) if (!stralloc_cats(&sa, p->name)) goto err; if (!stralloc_cats(&sa, "/")) goto err; - if (close(open_trunc("../log/3-data")) == -1) goto err; - n = sa.n; if (!stralloc_cats(&sa, "default/data")) goto err; if (!stralloc_cat0(&sa)) goto err; @@ -132,7 +121,6 @@ build(package const *p, char const *def) stralloc sa; char const *argv[] = { NULL, NULL }; size_t n; - int fd = - 1; int ret = -1; stralloc_init(&sa); @@ -141,29 +129,26 @@ build(package const *p, char const *def) if (!stralloc_cats(&sa, p->name)) goto err; if (!stralloc_cats(&sa, "/")) goto err; - if ((fd = open_trunc("../log/4-build")) == -1) goto err; - n = sa.n; if (!stralloc_cats(&sa, p->ver)) goto err; if (!stralloc_cats(&sa, "/build")) goto err; if (!stralloc_cat0(&sa)) goto err; argv[0] = sa.x; - if (stat_isfile(sa.x)) { ret = forkexec_wait_redir(argv, fd); goto err; } + if (stat_isfile(sa.x)) { ret = forkexec_redir(argv, 2, 1); goto err; } sa.n = n; if (!stralloc_cats(&sa, "default/build")) goto err; if (!stralloc_cat0(&sa)) goto err; argv[0] = sa.x; - if (stat_isfile(sa.x)) { ret = forkexec_wait_redir(argv, fd); goto err; } + if (stat_isfile(sa.x)) { ret = forkexec_redir(argv, 2, 1); goto err; } err: stralloc_free(&sa); - if (fd >= 0) close(fd); return ret; } static int -package_env_set(char const *name, char const *path) +env_sane_name(char const *name, char const *path) { char buf[NAME_MAX]; int len; @@ -196,7 +181,7 @@ env(package *p, char const *def, char const *pkg, char const *id) if (!stralloc_cats(&sa, id)) goto err; if (!stralloc_cats(&sa, "/build")) goto err; if (!stralloc_cat0(&sa)) goto err; - if (!package_env_set("PREFIX", sa.x)) goto err; + if (!env_sane_name("PREFIX", sa.x)) goto err; errno = 0; fd = package_opendepfile(p, def); @@ -214,14 +199,14 @@ env(package *p, char const *def, char const *pkg, char const *id) if (!package_version(&new, def)) goto err; stralloc_zero(&sa); - if (!stralloc_cats(&sa, pkg)) + if (!stralloc_cats(&sa, pkg)) goto err; if (!stralloc_cats(&sa, "/")) goto err; if (!stralloc_cats(&sa, new.name)) goto err; if (!stralloc_cats(&sa, "/")) goto err; if (!stralloc_cats(&sa, new.ver)) goto err; if (!stralloc_cats(&sa, "/current/build")) goto err; if (!stralloc_cat0(&sa)) goto err; - if (!package_env_set(new.name, sa.x)) goto err; + if (!env_sane_name(new.name, sa.x)) goto err; } ret = (r == 0); err: @@ -234,7 +219,7 @@ err: void usage(char const *argv0, char const *param) { - log_err2("missing parameter: ", param); + log_error_2("missing parameter: ", param); log_usage(argv0, "-p pkgdir -d defdir packageage[/version]"); } @@ -259,62 +244,79 @@ main(int argc, char **argv) if (!*av) usage(*argv, "packageage[/version]"); - if (!stat_isdir(def)) log_diesys1(101, def); - if (!stat_isdir(pkg)) log_diesys1(101, pkg); - tain_now(&tn); id[tain_fmt(&tn, id)] = '\0'; if (chdir(pkg) == -1) - log_diesys2(101, "chdir ", pkg); + log_fatal_sys_2(101, "chdir ", pkg); if ((*av)[package_scan(&p, *av)] != '\0') - log_diesys2(1, "invalid packageage format: ", *av); + log_fatal_sys_2(1, "invalid packageage format: ", *av); if (mkdir(p.name, 075) == -1 && errno != EEXIST) - log_diesys4(101, "mkdir ", pkg, "/", p.name); + log_fatal_sys_4(101, "mkdir ", pkg, "/", p.name); if (chdir(p.name) == -1) - log_diesys4(101, "chdir ", pkg, "/", p.name); + log_fatal_sys_4(101, "chdir ", pkg, "/", p.name); if (!package_version(&p, def)) - log_diesys4(101, "version ", def, "/", p.name); + log_fatal_sys_4(101, "version ", def, "/", p.name); if (mkdir(p.ver, 075) == -1 && errno != EEXIST) - log_diesys6(101, "mkdir ", pkg, "/", p.name, "/", p.ver); + log_fatal_sys_6(101, "mkdir ", pkg, "/", p.name, "/", p.ver); + if (!lock_exclusive(open_read("source.tar")) == -1) + log_fatal_7(101, "flock ", pkg, "/", p.name, "/", p.ver, "/source.tar"); if (chdir(p.ver) == -1) - log_diesys6(101, "chdir ", pkg, "/", p.name, "/", p.ver); + log_fatal_sys_6(101, "chdir ", pkg, "/", p.name, "/", p.ver); if (mkdir(id, 075) == -1 && errno != EEXIST) - log_diesys8(101, "mkdir ", pkg, "/", p.name, "/", p.ver, "/", id); + log_fatal_sys_8(101, "mkdir ", pkg, "/", p.name, "/", p.ver, "/", id); if (chdir(id) == -1) - log_diesys8(101, "chdir ", pkg, "/", p.name, "/", p.ver, "/", id); + log_fatal_sys_8(101, "chdir ", pkg, "/", p.name, "/", p.ver, "/", id); + if (close(1) == -1 || open_trunc("log") == -1) + log_fatal_sys_9(101, "open ", pkg, "/", p.name, "/", p.ver, "/", id, "/log"); if (mkdir("build", 075) == -1 && errno != EEXIST) - log_diesys9(101, "mkdir ", pkg, "/", p.name, "/", p.ver, "/", id, "/build"); - if (mkdir("log", 075) == -1 && errno != EEXIST) - log_diesys9(101, "mkdir ", pkg, "/", p.name, "/", p.ver, "/", id, "/log"); + log_fatal_sys_9(101, "mkdir ", pkg, "/", p.name, "/", p.ver, "/", id, "/build"); if (mkdir("source", 075) == -1 && errno != EEXIST) - log_diesys9(101, "mkdir ", pkg, "/", p.name, "/", p.ver, "/", id, "/source"); + log_fatal_sys_9(101, "mkdir ", pkg, "/", p.name, "/", p.ver, "/", id, "/source"); if (symlink(id, "latest") == -1 && errno != EEXIST) - log_diesys9(101, "symlink ", pkg, "/", p.name, "/", p.ver, "/", id, "/latest"); + log_fatal_sys_9(101, "symlink ", pkg, "/", p.name, "/", p.ver, "/", id, "/latest"); if (rename("latest", "../latest") == -1 && errno != EEXIST) - log_diesys7(101, "rename ", pkg, "/", p.name, "/", p.ver, "/latest"); + log_fatal_sys_7(101, "rename ", pkg, "/", p.name, "/", p.ver, "/latest"); if (chdir("source") == -1) - log_diesys4(101, "could not change directory to ", pkg, "/", p.name); + log_fatal_sys_4(101, "could not change directory to ", pkg, "/", p.name); + + write(1, "=== untar ===\n", 14); if ((x = untar()) != 0) { char fmt[50]; fmt_long(fmt, x); - log_die4(100, "tar of ", p.name, " exited ", fmt); + log_fatal_8(100, "tar -x -f ", pkg, "/", p.name, "/", p.ver, "/source.tar -> exit ", fmt); } + write(1, "=== end ===\n", 12); + + write(1, "\n=== patch ===\n", 15); if (!patch(&p, def)) - log_diesys3(100, "patching ", p.name, "'s source"); - if (!data(&p, def)) - log_diesys6(100, "copying ", p.name, "'s data from ", def, " to ", pkg); + log_fatal_sys_3(100, "patching ", p.name, "'s source"); + write(1, "=== end ===\n", 12); + + write(1, "\n=== copy ===\n", 14); + if (!copy(&p, def)) + log_fatal_sys_9(100, "copy ", def, "/", p.name, "/", p.ver, "/", id, "/source"); + write(1, "=== end ===\n", 12); + + write(1, "\n=== setenv ===\n", 16); if (!env(&p, def, pkg, id)) - log_diesys2(100, "could not set environment variables for ", *argv); + log_fatal_sys_2(100, "could not set environment variables for ", *argv); + write(1, "=== end ===\n", 12); + + write(1, "\n=== build ===\n", 15); if ((x = build(&p, def)) != 0) { char fmt[50]; fmt_long(fmt, x); - log_die4(100, "build script of ", p.name, " exited ", fmt); + log_fatal_7(100, def, "/", p.name, "/", p.ver, "/build -> exit ", fmt); } + write(1, "=== end ===\n", 12); + + write(1, "\n=== release ==\n", 17); if (symlink(id, "../current") == -1 && errno != EEXIST) - log_diesys9(101, "symlink ", pkg, "/", p.name, "/", p.ver, "/", id, "/current"); + log_fatal_sys_9(101, "symlink ", pkg, "/", p.name, "/", p.ver, "/", id, "/current"); if (rename("../current", "../../current") == -1 && errno != EEXIST) - log_diesys7(101, "rename ", pkg, "/", p.name, "/", p.ver, "/current"); + log_fatal_sys_7(101, "rename ", pkg, "/", p.name, "/", p.ver, "/current"); + write(1, "=== end ===\n", 12); return 0; } diff --git a/package-dep.c b/package-dep.c @@ -26,19 +26,19 @@ main(int argc, char **argv) def = "/etc/pack"; - if (!stat_isdir(def)) log_diesys1(101, def); + if (!stat_isdir(def)) log_fatal_sys_1(101, def); n = package_scan(&p, *argv); if (n == 0 || (*argv)[n] != '\0') - log_die2(1, "invalid packageage name: ", *argv); + log_fatal_2(1, "invalid packageage name: ", *argv); if (!package_version(&p, def)) - log_diesys3(103, "could not get ", *argv," version"); + log_fatal_sys_3(103, "could not get ", *argv," version"); genalloc_init(&ga); if (!package_dep(&p, &ga, def)) - log_diesys1(103, "could not resolve packageage dependencies"); - if (!genalloc_append(&ga, p)) log_diesys1(103, "malloc"); + log_fatal_sys_1(103, "could not resolve packageage dependencies"); + if (!genalloc_append(&ga, p)) log_fatal_sys_1(103, "malloc"); for (i = 0; i < genalloc_len(&ga, package); ++i) { char fmt[PACKAGE_FMT]; diff --git a/package-get.c b/package-get.c @@ -12,42 +12,17 @@ #include "stat.h" #include "stralloc.h" -int -get(package const *p, char const *cmd, char const *url) -{ - char const *argv[] = { NULL, NULL, NULL, NULL }; - char fmt[PACKAGE_FMT]; - stralloc sa; - - stralloc_init(&sa); - - log_info2("trying mirror ", url); - - package_fmt(p, fmt); - argv[0] = cmd; - argv[1] = fmt; - argv[2] = url; - argv[3] = NULL; - if ((forkexec_wait(argv)) != 0) - { - log_err4("downloading packageage ", p->name, "/", p->ver); - return 0; - } - - return 1; -} - void die_nomem(void) { - log_diesys1(100, "malloc"); + log_fatal_sys_1(100, "malloc"); } void -usage(char const *argv0, char const *param) +usage(char const *argv_0, char const *param) { - log_err2("missing parameter: ", param); - log_usage(argv0, "-p pkgdir -d defdir packageage[/version]"); + log_error_2("missing parameter: ", param); + log_usage(argv_0, "-p pkgdir -d defdir packageage[/version]"); } int @@ -63,7 +38,7 @@ main(int argc, char **argv) char **av = argv; int fd = -1; size_t n; - size_t r; + ssize_t r; (void)argc; @@ -77,13 +52,13 @@ main(int argc, char **argv) if (!pkg) usage(*argv, "-p"); if (!*av) usage(*argv, "packageage[/version]"); - if (!stat_isdir(def)) log_diesys1(101, def); + if (!stat_isdir(def)) log_fatal_sys_1(101, def); n = package_scan(&p, *av); if ((*av)[n] != '\0') - log_die2(1, "invalid packageage format: ", *argv); + log_fatal_2(1, "invalid packageage format: ", *argv); if (!package_version(&p, def)) - log_diesys2(101, "package_version ", p.name); + log_fatal_sys_2(101, "package_version ", p.name); stralloc_init(&sa); if (!stralloc_cats(&sa, def)) die_nomem(); @@ -103,21 +78,21 @@ main(int argc, char **argv) if (!stralloc_cats(&sa, p.ver)) die_nomem(); if (!stralloc_cat0(&sa)) die_nomem(); if (!hier_mkdir(sa.x, 0750)) - log_diesys2(101, "mkdir ", sa.x); + log_fatal_sys_2(101, "mkdir ", sa.x); if (chdir(sa.x) == -1) - log_diesys2(101, "chdir ", sa.x); + log_fatal_sys_2(101, "chdir ", sa.x); sa.n--; - if (close(1) == -1 || dup(open_trunc("source.tmp")) == -1) - log_diesys3(100, "redirect tar output to ", sa.x, "/source.tmp"); + if (close(1) == -1 || (open_trunc("source.tmp")) == -1) + log_fatal_sys_3(100, "open ", sa.x, "/source.tmp"); if (!lock_exclusive(1)) - log_diesys3(100, "flock ", sa.x, "/source.tmp"); - if (close(2) == -1 || dup(open_trunc("source.log")) == -1) - log_diesys3(100, "redirect err output to ", sa.x, "/source.log"); + log_fatal_sys_3(100, "flock ", sa.x, "/source.tmp"); buffer_init(&b, &read, fd, buf, sizeof buf); - while (stralloc_zero(&sa), (r = buffer_getline(&b, &sa)) > 0) - { + while (stralloc_zero(&sa), (r = buffer_getline(&b, &sa)) > 0) { + char const *argv[] = { NULL, NULL, NULL, NULL }; + char fmt[PACKAGE_FMT]; + cmd = NULL; if (sa.x[sa.n - 1] == '\n') --sa.n; @@ -128,16 +103,24 @@ main(int argc, char **argv) if (str_start(sa.x, "ftps://")) cmd = "package-ftps"; if (str_start(sa.x, "git://")) cmd = "package-git"; if (str_start(sa.x, "cvs://")) cmd = "package-cvs"; - if (!cmd) log_warn2("no handler found for downloading ", sa.x); - else if (get(&p, cmd, sa.x)) break; + if (!cmd) log_warn_2("no handler found for downloading ", sa.x); + + log_info_2("trying mirror ", sa.x); + + package_fmt(&p, fmt); + argv[0] = cmd; + argv[1] = fmt; + argv[2] = sa.x; + argv[3] = NULL; + if ((forkexec_redir(argv, 2, open_trunc("source.log"))) != 0) + log_error_4("downloading packageage ", p.name, "/", p.ver); + else if (rename("source.tmp", "source.tar") == -1) + log_fatal_sys_1(100, "rename source.tmp source.tar"); + else + return 0; } - if (r < 0) log_errsys1("buffering"); - if (!cmd) log_errsys4("no mirror found for ", p.name, "/", p.ver); - - if (rename("source.tmp", "source.tar") == -1) - log_diesys1(100, "rename source.tmp source.tar"); + if (r < 0) log_error_sys_1("buffering"); + log_fatal_4(1, "could not download ", p.name, "/", p.ver); - stralloc_free(&sa); - close(fd); - return 0; + return 2; } diff --git a/package-install.c b/package-install.c @@ -1,9 +1,25 @@ #include "package.h" +#include "log.h" +#include "stat.h" +#include "hier.h" void die_nomem(void) { - log_diesys1(100, "malloc"); + log_fatal_sys_1(100, "malloc"); +} + +void +die_usage(char const *argv0) +{ + log_usage(argv0, "-r rootdir package[/version]"); +} + +void +die_param(char const *argv0, char const *param) +{ + log_error_2("missing parameter ", param); + die_usage(argv0); } int @@ -14,23 +30,41 @@ main(int argc, char **argv) char *def = PACKAGE_DEF; char *pkg = PACKAGE_DIR; char *root = PACKAGE_ROOT; + char **av = argv; (void)argc; - while (*++av) { + while (*++av) + { if (str_equal(*av, "-p")) { if (!(pkg = *++av)) break; continue; } if (str_equal(*av, "-d")) { if (!(def = *++av)) break; continue; } if (str_equal(*av, "-r")) { if (!(root = *++av)) break; continue; } break; } - if (!def) usage(*argv, "-d"); - if (!pkg) usage(*argv, "-p"); - if (!*av) usage(*argv, "packageage[/version]"); + if (!def) die_param(*argv, "-d"); + if (!pkg) die_param(*argv, "-p"); + if (!*av) die_usage(*argv); + + if (!stat_isdir(def)) log_fatal_sys_1(101, def); + if (!stat_isdir(root)) log_fatal_sys_1(101, root); - if (!stat_isdir(def)) log_diesys1(101, def); - if (!stat_isdir(root)) log_diesys1(101, root); + if (*av[0] == '\0' || (*av)[package_scan(&p, *av)] != '\0') + log_fatal_sys_2(1, "invalid package format: ", *av); + + if (!package_version(&p, def)) log_fatal_sys_2(101, "version ", p.name); stralloc_init(&sa); - if (!stralloc_init(&sa)) die_nomem(); + if (!stralloc_cats(&sa, pkg)) die_nomem(); + if (!stralloc_cats(&sa, "/")) die_nomem(); + if (!stralloc_cats(&sa, p.name)) die_nomem(); + if (!stralloc_cats(&sa, "/")) die_nomem(); + if (!stralloc_cats(&sa, p.ver)) die_nomem(); + if (!stralloc_cats(&sa, "/current")) die_nomem(); + if (!stralloc_cat0(&sa)) die_nomem(); + + if (hier_symlink(sa.x, root) == -1) + log_fatal_sys_4(102, "symlink ", sa.x, " ", root); + + return 0; } diff --git a/package-tree.c b/package-tree.c @@ -36,7 +36,8 @@ tree(package *p, stralloc *prefix, char const *def) if (!stralloc_cats(&sa, p->name)) goto err; if (!stralloc_cats(&sa, "/")) goto err; n = sa.n; - ver[0] = p->ver; ver[1] = "default"; + ver[0] = p->ver; + ver[1] = "default"; errno = 0; for (size_t i = 0; i < 2 && fd == -1; ++i) { @@ -75,17 +76,17 @@ main(int argc, char **argv) stralloc sa; package p; - if (!stat_isdir(def)) log_diesys1(101, def); + if (!stat_isdir(def)) log_fatal_sys_1(101, def); if (argc != 2) log_usage(*argv, "packageage[/version]"); ++argv; if (!package_scan(&p, *argv)) - log_die2(1, "invalid packageage format: ", *argv); + log_fatal_2(1, "invalid packageage format: ", *argv); stralloc_init(&sa); if (!tree(&p, &sa, def)) - log_diesys4(100, "generating tree for ", p.name, "/", p.ver); + log_fatal_sys_4(100, "generating tree for ", p.name, "/", p.ver); stralloc_free(&sa); buffer_flush(buffer_1); diff --git a/package.c b/package.c @@ -12,7 +12,6 @@ #include "open.h" #include "package.h" #include "stralloc.h" -#include "lock.h" #include "tai.h" size_t @@ -130,7 +129,7 @@ err: return fd; } -int +static int package_hasdep(package const *p, genalloc *packages) { size_t i; @@ -147,31 +146,6 @@ package_hasdep(package const *p, genalloc *packages) } int -package_lock(package *p, char const *pkg) -{ - stralloc sa; - int fd = -1; - int ret = 0; - - stralloc_init(&sa); - if (!stralloc_cats(&sa, pkg)) goto err; - if (!stralloc_cats(&sa, "/")) goto err; - if (!stralloc_cats(&sa, p->name)) goto err; - if (!stralloc_cats(&sa, "/")) goto err; - if (!stralloc_cats(&sa, p->ver)) goto err; - if (!stralloc_cats(&sa, "/source.tar")) goto err; - if (!stralloc_cat0(&sa)) goto err; - - if ((fd = open_trunc(sa.x)) == -1) goto err; - if (!lock_exclusive(fd)) { ret = -1; goto err; } - - ret = fd; -err: - stralloc_free(&sa); - return ret; -} - -int package_dep(package const *p, genalloc *packages, char const *def) { stralloc sa = STRALLOC_ZERO; diff --git a/package.h b/package.h @@ -15,7 +15,6 @@ typedef struct { } package; int package_dep(package const *, genalloc *, char const *); -int package_hasdep(package const *, genalloc *); int package_lock(package *, char const *); int package_opendepfile(package const *, char const *); int package_version(package *, char const *); diff --git a/str.c b/str.c @@ -4,12 +4,12 @@ size_t str_chr(char const *buf, char c) { char *s = strchr(buf, c); - return s ? s - buf : strlen(buf); + return s ? (size_t)(s - buf) : strlen(buf); } size_t str_rchr(char const *buf, char c) { char *s = strrchr(buf, c); - return s ? s - buf : strlen(buf); + return s ? (size_t)(s - buf) : strlen(buf); }