This commit is contained in:
Your Name 2023-11-14 14:35:25 +03:00
parent 688fdd9285
commit 7c4e4402f9
6 changed files with 59 additions and 28 deletions

11
TODO
View File

@ -1,13 +1,8 @@
PlainOs
With "micro-" prefix
*Todo:
**ls
**chmod
**chgrp
**chown
**ls (mc print)
**dmesg (portable)
tee
tail
expr
uniq
@ -32,7 +27,6 @@ tar
Other:
kill
top
ps
mount
umount
@ -74,6 +68,3 @@ Shell:
Init:
sinit - Simple init
Libs:
readline

View File

@ -4,16 +4,12 @@
const char *objects[] = {
"console-tools",
"coreutils",
"sysutils",
"networking",
"procps",
"shell"
};
const char *libs[] = {
"readline"
/* "sysutils" */
};
#define CFLAGS "-Wall", "-Werror", "-Wextra", "-pedantic", "-flto", "-Os", "-s", "-I", "../libmu"
#define CC "tcc"
#define CC "cc"
#endif

View File

@ -135,11 +135,11 @@ int cptree(const char *src, const char *dst) {
if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, "..") || !strcmp(dst, ep->d_name))
continue;
char *src_path = mu_make_path("cp", src, ep->d_name);
char *src_path = mu_make_path((s_flag) ? NULL : "cp", src, ep->d_name);
if (src_path == NULL)
continue;
char *dst_path = mu_make_path("cp", dst, ep->d_name);
char *dst_path = mu_make_path((s_flag) ? NULL : "cp", dst, ep->d_name);
if (dst_path == NULL) {
free(src_path);
continue;
@ -188,7 +188,7 @@ int main(int argc, char **argv) {
else {
for (int i = 1; i < argc - 1; i++) {
char *new_path = mu_make_path("cp", argv[argc - 1], basename(argv[i]));
char *new_path = mu_make_path((s_flag) ? NULL : "cp", argv[argc - 1], basename(argv[i]));
if (new_path == NULL)
return 1;

View File

@ -20,7 +20,7 @@ unsigned int F_flag;
unsigned int p_flag;
struct d_node {
/* basename() */
/* basename */
char *name;
/* For free */
@ -155,7 +155,6 @@ void print(const struct d_node *node) {
}
int ls(const char *dir_name, int label, struct winsize w) {
(void)w;
size_t files = 0;
struct d_node **dir = list(dir_name, &files);
@ -173,12 +172,7 @@ int ls(const char *dir_name, int label, struct winsize w) {
}
/* Todo: sort and print */
else {
for (size_t i = 0; i < files; i++)
print(dir[i]);
putchar('\n');
}
else {}
dfree(dir);
return 0;

50
coreutils/tee.c Normal file
View File

@ -0,0 +1,50 @@
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int flag = O_TRUNC;
int opt;
while ((opt = getopt(argc, argv, "ai")) != -1) {
switch (opt) {
case 'a':
flag = O_APPEND;
break;
case 'i':
signal(SIGINT, SIG_IGN);
break;
default:
printf("tee [file]\n\t[-a Append]\n\t[-i Ignore interrupt signals]\n");
return 0;
}
}
argv += optind;
argc -= optind;
if (argc == 0) {
fprintf(stderr, "tee: missing operand\n");
return 1;
}
int fd = open(argv[0], O_WRONLY | flag | O_CREAT, 0666);
if (fd < 0) {
fprintf(stderr, "tee: %s\n", strerror(errno));
return 1;
}
char in[4096];
off_t bytes = 0;
while ((bytes = read(STDIN_FILENO, in, sizeof(in)))) {
write(STDOUT_FILENO, in, bytes);
write(fd, in, bytes);
}
close(fd);
return 0;
}

View File

@ -21,7 +21,7 @@ unsigned int tlines;
void count(const int fd) {
char buf[4096];
ssize_t n = 0;
off_t n = 0;
int in_word = 1;
while ((n = read(fd, buf, sizeof(buf))) > 0) {