summaryrefslogtreecommitdiff
path: root/src/dirname.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dirname.c')
-rw-r--r--src/dirname.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/dirname.c b/src/dirname.c
new file mode 100644
index 0000000..982606a
--- /dev/null
+++ b/src/dirname.c
@@ -0,0 +1,28 @@
+#include <unistd.h>
+#include <string.h>
+#include <libgen.h>
+
+static int my_write(int fd, const char *s, size_t l)
+{
+ if (!l) l = strlen(s);
+ while (l) {
+ ssize_t n = write(fd, s, l);
+ if (n<0) return -1;
+ s += n; l -= n;
+ }
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ char *s;
+ if (argc != 2) {
+ my_write(2, argv[0], 0);
+ my_write(2, ": missing operand\n", 0);
+ return 1;
+ }
+ s = dirname(argv[1]);
+ if (my_write(1, s, 0)<0 || my_write(1, "\n", 1)<0)
+ return 1;
+ return 0;
+}