commit: 125f26c7e95d8e3c2f1582058a4a6f0c3ba14776
parent: f65fd3799216d1d6753052bafc1af17f635ef8d8
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sun, 7 Oct 2018 22:02:24 +0200
src/pwd.c: New Program
Diffstat:
1 file changed, 32 insertions(+), 0 deletions(-)
diff --git a/src/pwd.c b/src/pwd.c
@@ -0,0 +1,32 @@
+// Copyright 2018 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
+// Distributed under the terms of the CC-BY-SA-4.0 license
+
+#include <errno.h> /* errno */
+#include <stdio.h> /* puts, perror, printf */
+#include <stdlib.h> /* exit */
+#include <string.h> /* strerror */
+#include <unistd.h> /* getcwd() */
+
+char buf[BUFSIZ];
+
+void usage(char *a0)
+{
+ (void)printf("usage: %s\n", a0);
+ exit(EXIT_SUCCESS);
+}
+
+int main(int argc, char *argv[])
+{
+ if(argc != 1) usage(argv[0]);
+
+ if(getcwd(buf, sizeof(buf)) == NULL)
+ {
+ perror(strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ else
+ {
+ const char *pwd = buf;
+ return puts(pwd);
+ }
+}