From c63f340d90800895f007de64b7d2d14624263331 Mon Sep 17 00:00:00 2001 From: nthnluu Date: Sun, 28 Jan 2024 21:20:27 -0500 Subject: Created student weenix repository --- user/usr/bin/args.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 user/usr/bin/args.c (limited to 'user/usr/bin/args.c') 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 +#include +#include +#include + +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; +} -- cgit v1.2.3-70-g09d2