diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | package/deps.mak | 3 | ||||
-rw-r--r-- | package/modes | 3 | ||||
-rw-r--r-- | package/targets.mak | 1 | ||||
-rw-r--r-- | src/shh-portable-utils/deps-exe/dirname | 1 | ||||
-rw-r--r-- | src/shh-portable-utils/dirname.c | 40 |
6 files changed, 48 insertions, 1 deletions
@@ -11,6 +11,7 @@ src/include/shh-portable-utils/config.h /chmod /chown /cut +/dirname /false /true /uniq diff --git a/package/deps.mak b/package/deps.mak index 1850169..9e88c08 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -9,6 +9,7 @@ src/shh-portable-utils/chgrp.o src/shh-portable-utils/chgrp.lo: src/shh-portable src/shh-portable-utils/chmod.o src/shh-portable-utils/chmod.lo: src/shh-portable-utils/chmod.c src/shh-portable-utils/chown.o src/shh-portable-utils/chown.lo: src/shh-portable-utils/chown.c src/shh-portable-utils/cut.o src/shh-portable-utils/cut.lo: src/shh-portable-utils/cut.c src/shh-portable-utils/shhfuncs.h +src/shh-portable-utils/dirname.o src/shh-portable-utils/dirname.lo: src/shh-portable-utils/dirname.c src/shh-portable-utils/false.o src/shh-portable-utils/false.lo: src/shh-portable-utils/false.c src/shh-portable-utils/shhgetln.o src/shh-portable-utils/shhgetln.lo: src/shh-portable-utils/shhgetln.c src/shh-portable-utils/shhfuncs.h src/shh-portable-utils/true.o src/shh-portable-utils/true.lo: src/shh-portable-utils/true.c @@ -26,6 +27,8 @@ chown: EXTRA_LIBS := ${SOCKET_LIB} -lskarnet chown: src/shh-portable-utils/chown.o ${LIBNSSS} cut: EXTRA_LIBS := -lskarnet cut: src/shh-portable-utils/cut.o src/shh-portable-utils/shhgetln.o +dirname: EXTRA_LIBS := -lskarnet +dirname: src/shh-portable-utils/dirname.o false: EXTRA_LIBS := false: src/shh-portable-utils/false.o true: EXTRA_LIBS := diff --git a/package/modes b/package/modes index f915ed4..2a2e5fe 100644 --- a/package/modes +++ b/package/modes @@ -1,9 +1,10 @@ -basename 0755 +basename 0755 cat 0755 chgrp 0755 chmod 0755 chown 0755 cut 0755 +dirname 0755 false 0755 true 0755 uniq 0755 diff --git a/package/targets.mak b/package/targets.mak index e01a01a..cff022d 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -5,6 +5,7 @@ chgrp \ chmod \ chown \ cut \ +dirname \ false \ true \ uniq diff --git a/src/shh-portable-utils/deps-exe/dirname b/src/shh-portable-utils/deps-exe/dirname new file mode 100644 index 0000000..e7187fe --- /dev/null +++ b/src/shh-portable-utils/deps-exe/dirname @@ -0,0 +1 @@ +-lskarnet diff --git a/src/shh-portable-utils/dirname.c b/src/shh-portable-utils/dirname.c new file mode 100644 index 0000000..688d9c1 --- /dev/null +++ b/src/shh-portable-utils/dirname.c @@ -0,0 +1,40 @@ +#include <string.h> + +#include <skalibs/strerr2.h> +#include <skalibs/allreadwrite.h> + +#define USAGE "dirname string" + +int main(int argc, char **argv) +{ + size_t len; + char *dirname_end; + PROG = "dirname"; + if (argc < 2) + strerr_dieusage(100, USAGE); + + len = strlen(argv[1]); + if (!len) { + allwrite(1, ".\n", 2); + return 0; + } + + while (len && argv[1][len - 1] == '/') + len--; + if (len == 0) { + allwrite(1, "/\n", 2); + return 0; + } + + argv[1][len] = '\0'; + + dirname_end = strrchr(argv[1], '/'); + if (!dirname_end) + allwrite(1, ".\n", 2); + else { + allwrite(1, argv[1], dirname_end - argv[1]); + fd_write(1, "\n", 1); + } + + return 0; +} |