aboutsummaryrefslogtreecommitdiff
path: root/1/test/main.c
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-05-12 15:21:19 +0200
committerlonkaars <loek@pipeframe.xyz>2024-05-12 15:21:19 +0200
commit891595b9307eb2695411d8e32e4addd9cd927ec8 (patch)
treeb24c323ad3e09f05ca75386ac8fef38a6fff3e74 /1/test/main.c
parent6926a88695ce2e9fca51e01a1bf6fded3e4cbcca (diff)
rename folders
Diffstat (limited to '1/test/main.c')
-rw-r--r--1/test/main.c56
1 files changed, 0 insertions, 56 deletions
diff --git a/1/test/main.c b/1/test/main.c
deleted file mode 100644
index b87e56c..0000000
--- a/1/test/main.c
+++ /dev/null
@@ -1,56 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-
-int main(int argc, char** argv) {
- if (geteuid() != 0) {
- fprintf(stderr, "run me as root!\n");
- return 1;
- }
-
- argc--; // argv[0] is the program name
- if (argc == 0) {
- fprintf(stderr, "usage: %s /dev/lork\n", argv[0]);
- return 1;
- }
-
- char* dev = argv[1];
- const char* input = "test";
- int fd;
- ssize_t bytes;
-
- fd = open(dev, O_RDWR);
- if (-1 == fd) {
- fprintf(stderr, "open() failed with code %d\n", errno);
- return 1;
- }
-
- bytes = write(fd, input, strlen(input));
- if (-1 == bytes) {
- fprintf(stderr, "write() failed with code %d\n", errno);
- return 1;
- }
- fprintf(stderr, "input \"%s\" to %s (%ld bytes succesful)\n", input, dev, bytes);
-
- char buf[80];
- bytes = read(fd, buf, 80);
- if (-1 == bytes) {
- fprintf(stderr, "read() failed with code %d\n", errno);
- return 1;
- }
- fprintf(stderr, "output from %s: (%ld bytes)\n", dev, bytes);
- if (bytes > 0) {
- if (bytes < 80) buf[bytes] = '\0'; // null terminate string for printf
- printf("%s\n", buf);
- }
-
- if (-1 == close(fd)) {
- fprintf(stderr, "close() failed with code %d\n", errno);
- return 1;
- }
-
- return 0;
-}
-