aboutsummaryrefslogtreecommitdiff
path: root/user/usr/bin/args.c
diff options
context:
space:
mode:
authornthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
committernthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
commitc63f340d90800895f007de64b7d2d14624263331 (patch)
tree2c0849fa597dd6da831c8707b6f2603403778d7b /user/usr/bin/args.c
Created student weenix repository
Diffstat (limited to 'user/usr/bin/args.c')
-rw-r--r--user/usr/bin/args.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/user/usr/bin/args.c b/user/usr/bin/args.c
new file mode 100644
index 0000000..e10e821
--- /dev/null
+++ b/user/usr/bin/args.c
@@ -0,0 +1,36 @@
+/*
+ * Does some basic checks to make sure arguments are
+ * being passed to userland programs correctly.
+ */
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char **argv, char **envp)
+{
+ int i;
+ char buf[100];
+
+ open("/dev/tty0", O_RDONLY, 0);
+ open("/dev/tty0", O_WRONLY, 0);
+
+ snprintf(buf, sizeof(buf), "Arguments: (argc = %d, argv = %p)\n", argc,
+ argv);
+ write(1, buf, strlen(buf));
+ for (i = 0; argv[i]; i++)
+ {
+ snprintf(buf, sizeof(buf), " %d \"%s\"\n", i, argv[i]);
+ write(1, buf, strlen(buf));
+ }
+ snprintf(buf, sizeof(buf), "Environment: (envp = %p)\n", envp);
+ write(1, buf, strlen(buf));
+ for (i = 0; envp[i]; i++)
+ {
+ snprintf(buf, sizeof(buf), " %d \"%s\"\n", i, envp[i]);
+ write(1, buf, strlen(buf));
+ }
+
+ return 0;
+}