aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
Diffstat (limited to 'toys')
-rw-r--r--toys/Config.in8
-rw-r--r--toys/pwd.c16
-rw-r--r--toys/toylist.h62
3 files changed, 86 insertions, 0 deletions
diff --git a/toys/Config.in b/toys/Config.in
index 89481bde..2120636c 100644
--- a/toys/Config.in
+++ b/toys/Config.in
@@ -34,6 +34,14 @@ config HELLO
help
A hello world program. You don't need this.
+config PWD
+ bool "pwd"
+ default n
+ help
+ usage: pwd
+
+ The print working directory command prints the current directory.
+
config TOYSH
bool "sh (toysh)"
default n
diff --git a/toys/pwd.c b/toys/pwd.c
new file mode 100644
index 00000000..3ba7ae0d
--- /dev/null
+++ b/toys/pwd.c
@@ -0,0 +1,16 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * pwd.c - Print working directory.
+ */
+
+#include "toys.h"
+
+int pwd_main(void)
+{
+ char *pwd = xgetcwd();
+
+ puts(pwd);
+ if (CFG_TOYS_FREE) free(pwd);
+
+ return 0;
+}
diff --git a/toys/toylist.h b/toys/toylist.h
new file mode 100644
index 00000000..87716b0f
--- /dev/null
+++ b/toys/toylist.h
@@ -0,0 +1,62 @@
+/* vi: set ts=4 :*/
+/* Toybox infrastructure.
+ *
+ * Copyright 2006 Rob Landley <rob@landley.net>
+ */
+
+
+// When #included from main.c, provide the guts for toy_list[]
+
+#ifdef FROM_MAIN
+#undef NEWTOY
+#undef OLDTOY
+#define NEWTOY(name, flags) {#name, name##_main, flags},
+#define OLDTOY(name, oldname, flags) {#name, oldname##_main, flags},
+
+// When #included from toys.h, provide function declarations and structs.
+// The #else is because main.c #includes this file twice.
+
+#else
+#define NEWTOY(name, flags) int name##_main(void);
+#define OLDTOY(name, oldname, flags)
+
+struct df_data {
+ struct string_list *fstype;
+ long units;
+};
+
+union toy_union {
+ struct df_data df;
+} toy;
+
+#define TOYFLAG_USR (1<<0)
+#define TOYFLAG_BIN (1<<1)
+#define TOYFLAG_SBIN (1<<2)
+#define TOYMASK_LOCATION ((1<<4)-1)
+
+#define TOYFLAG_NOFORK (1<<4)
+
+extern struct toy_list {
+ char *name;
+ int (*toy_main)(void);
+ int flags;
+} toy_list[];
+
+#endif
+
+// List of all the applets toybox can provide.
+
+// This one is out of order on purpose.
+
+NEWTOY(toybox, 0)
+
+// The rest of these are alphabetical, for binary search.
+
+USE_TOYSH(NEWTOY(cd, TOYFLAG_NOFORK))
+USE_DF(NEWTOY(df, TOYFLAG_USR|TOYFLAG_SBIN))
+USE_TOYSH(NEWTOY(exit, TOYFLAG_NOFORK))
+USE_HELLO(NEWTOY(hello, TOYFLAG_NOFORK|TOYFLAG_USR))
+USE_PWD(NEWTOY(pwd, TOYFLAG_BIN))
+USE_TOYSH(OLDTOY(sh, toysh, TOYFLAG_BIN))
+USE_TOYSH(NEWTOY(toysh, TOYFLAG_BIN))
+USE_WHICH(NEWTOY(which, TOYFLAG_USR|TOYFLAG_BIN))