summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-09-21 10:49:07 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-09-21 10:49:07 +0000
commita08f7a62968c167e84bf012cb24dd8a187ae639f (patch)
treeabb362430ea28ac08310cb02e8d6c27a6da21814 /src
parentd0996a25bd4030875fbc98cabea815dd6741dd0d (diff)
downloadexecline-a08f7a62968c167e84bf012cb24dd8a187ae639f.tar.xz
Add the getcwd program
Diffstat (limited to 'src')
-rw-r--r--src/execline/deps-exe/getcwd1
-rw-r--r--src/execline/getcwd.c24
2 files changed, 25 insertions, 0 deletions
diff --git a/src/execline/deps-exe/getcwd b/src/execline/deps-exe/getcwd
new file mode 100644
index 0000000..e7187fe
--- /dev/null
+++ b/src/execline/deps-exe/getcwd
@@ -0,0 +1 @@
+-lskarnet
diff --git a/src/execline/getcwd.c b/src/execline/getcwd.c
new file mode 100644
index 0000000..116acab
--- /dev/null
+++ b/src/execline/getcwd.c
@@ -0,0 +1,24 @@
+/* ISC license. */
+
+#include <skalibs/bytestr.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/env.h>
+#include <skalibs/stralloc.h>
+#include <skalibs/djbunix.h>
+
+#define USAGE "getcwd variable prog..."
+
+int main (int argc, char const *const *argv, char const *const *envp)
+{
+ stralloc sa = STRALLOC_ZERO ;
+ PROG = "getcwd" ;
+ if (argc < 3) strerr_dieusage(100, USAGE) ;
+ if (argv[1][str_chr(argv[1], '=')])
+ strerr_dief2x(100, "invalid variable name: ", argv[1]) ;
+ if (!stralloc_cats(&sa, argv[1]) || !stralloc_catb(&sa, "=", 1))
+ strerr_diefu1sys(111, "stralloc_catb") ;
+ if (sagetcwd(&sa) < 0) strerr_diefu1sys(111, "getcwd") ;
+ if (!stralloc_0(&sa)) strerr_diefu1sys(111, "stralloc_catb") ;
+ pathexec_r(argv + 2, envp, env_len(envp), sa.s, sa.len) ;
+ strerr_dieexec(111, argv[2]) ;
+}