Upload files to "/"

This commit is contained in:
8nl 2024-01-08 09:28:03 +00:00
parent 9f1e254d0e
commit b617b4cc5e
2 changed files with 92 additions and 0 deletions

5
Makefile Normal file
View File

@ -0,0 +1,5 @@
CC?=cc
CFLAGS?=-Os -s
all:
$(CC) $(CFLAGS) cutecat.c -o cutecat

87
cutecat.c Normal file
View File

@ -0,0 +1,87 @@
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
unsigned int d_flag;
char eyes[] = {'U', 'O'};
void OwO(char *buf, off_t len) {
if (d_flag)
return;
for (int i = 0; i < len / 10; i++) {
size_t i = rand() % len;
if (i + 3 < len && !isspace(buf[i]) && !isspace(buf[i + 2])) {
char eye = eyes[rand() % sizeof(eyes)];
buf[i] = eye;
buf[i + 1] = 'w';
buf[i + 2] = eye;
}
}
}
int cat(const char *path) {
int fd = STDIN_FILENO;
if (strcmp(path, "-"))
fd = open(path, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "cat: %s: %s\n", path, strerror(errno));
return 1;
}
char buf[513];
off_t len = 0;
while ((len = read(fd, buf, sizeof(buf))) > 0) {
OwO(buf, len);
if (write(STDOUT_FILENO, buf, len) != len) {
fprintf(stderr, "cat: %s\n", strerror(errno));
return 1;
}
}
if (strcmp(path, "-"))
close(fd);
return 0;
}
int main(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "d")) != -1) {
switch (opt) {
case 'd':
d_flag = 1;
break;
default:
printf("cutecat [file1 file2...]\n\t[-d Default mode]\n");
return 0;
}
}
argv += optind;
argc -= optind;
if (!d_flag)
srand(getpid());
if (argc == 0)
return cat("-");
else {
int ret = 0;
for (int i = 0; i < argc; i++)
if (cat(argv[i]))
ret = 1;
return ret;
}
}