From 545c5f85c38de8ddb8c026bf3b76658c8d8f3d6b Mon Sep 17 00:00:00 2001 From: WlodekM Date: Sat, 15 Feb 2025 10:51:57 +0200 Subject: fix some stuff; add some coreutils --- progs/hello/hello.c | 8 ++++++++ progs/mkdir/mkdir.c | 17 +++++++++++++++++ progs/mount/mount.c | 25 +++++++++++++++++++++++++ progs/tty/tty.c | 10 ++++++++++ 4 files changed, 60 insertions(+) create mode 100644 progs/hello/hello.c create mode 100644 progs/mkdir/mkdir.c create mode 100644 progs/mount/mount.c create mode 100644 progs/tty/tty.c (limited to 'progs') diff --git a/progs/hello/hello.c b/progs/hello/hello.c new file mode 100644 index 0000000..e11e06e --- /dev/null +++ b/progs/hello/hello.c @@ -0,0 +1,8 @@ +#include +#include + +__attribute__((force_align_arg_pointer)) +int main() { + write(1, ":3\n", 3); + exit(0); +} \ No newline at end of file diff --git a/progs/mkdir/mkdir.c b/progs/mkdir/mkdir.c new file mode 100644 index 0000000..cbf5cdf --- /dev/null +++ b/progs/mkdir/mkdir.c @@ -0,0 +1,17 @@ +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + if (!argv[1]) { + write(1, "you IDIOT, you forgot to include the file name, MORON\n", 55); + exit(1); + } + struct stat st = {0}; + + if (stat(argv[1], &st) == -1) { + mkdir(argv[1], 0700); + } + exit(0); +} \ No newline at end of file diff --git a/progs/mount/mount.c b/progs/mount/mount.c new file mode 100644 index 0000000..296dd42 --- /dev/null +++ b/progs/mount/mount.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + if (argc != 4) { + fprintf(stderr, "usag: %s \n", argv[0]); + return EXIT_FAILURE; + } + + const char *source = argv[1]; + const char *target = argv[2]; + const char *fstype = argv[3]; + + if (mount(source, target, fstype, 0, NULL) == -1) { + fprintf(stderr, "mount failed: %s\n", strerror(errno)); + return EXIT_FAILURE; + } + + printf("Mounted %s on %s with type %s\n", source, target, fstype); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/progs/tty/tty.c b/progs/tty/tty.c new file mode 100644 index 0000000..d906121 --- /dev/null +++ b/progs/tty/tty.c @@ -0,0 +1,10 @@ +#include +#include + +__attribute__((force_align_arg_pointer)) +int main() { + char *tty = ttyname(1); + write(1, tty, sizeof(tty)); + write(1, "\n", 1); + exit(0); +} \ No newline at end of file -- cgit 1.4.1-2-gfad0