This commit is contained in:
Your Name 2023-11-06 13:41:52 +03:00
parent 076ec8f540
commit f1bba77e6e
7 changed files with 61 additions and 22 deletions

13
TODO
View File

@ -10,7 +10,6 @@ nice
renice
nohup
split
truncate
date
tee
tr
@ -22,10 +21,9 @@ dd
stty
stat
sort
printf
test
install
dmesg
tar
chgrp
Other:
kill
@ -41,6 +39,7 @@ Other:
dhcp-client
getopt
fdisk
ntpd
Loginutils:
su
@ -62,3 +61,9 @@ Findutils:
Shell:
lsh - lavash
Init:
sinit - Simple init
Libs:
readline

View File

@ -16,25 +16,12 @@ long gid;
long uid;
int change(const char *file) {
struct stat old_file;
if (get_stat("chown", file, &old_file))
if (chown_func(file, uid, gid)) {
fprintf(stderr, "chown: unable to chown %s: %s\n", file, strerror(errno));
return 1;
if (chown_func(file, uid, gid) == 0) {
struct stat new_file;
if (get_stat("chown", file, &new_file))
return 1;
if (old_file.st_gid != new_file.st_gid || old_file.st_uid != new_file.st_uid)
return 0;
fprintf(stderr, "chown: %s unchanged\n", file);
}
else
fprintf(stderr, "chown: unable to chown %s: %s\n", file, strerror(errno));
return 1;
return 0;
}
int cntree(const char *dst) {

View File

@ -65,7 +65,7 @@ int main(const int argc, char **argv) {
f_flag = 1;
else if (!strcmp(argv[i], "--help")) {
printf("rm [-f force] [src1 src2...]\n");
printf("rm [-f force] file1 file2...\n");
return 0;
}
}

View File

@ -83,6 +83,7 @@ int main(const int argc, const char **argv) {
}
shred(rand_fd, fd);
fsync(fd);
close(fd);
if (u_flag)

View File

@ -1,7 +1,6 @@
#include <fcntl.h>
#include <unistd.h>
#include <utime.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>

47
coreutils/truncate.c Normal file
View File

@ -0,0 +1,47 @@
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
int main(const int argc, const char **argv) {
unsigned int c_flag = 0;
unsigned int s_size = 0;
int i;
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-')
break;
else if (!strncmp(argv[i], "-s=", 3))
s_size = atoi(argv[i] + 3);
else if (!strcmp(argv[i], "-c"))
c_flag = 1;
else if (!strcmp(argv[i], "--help")) {
printf("truncate [-c Do not create files] [-s=SIZE] file1 file2...\n");
return 0;
}
}
int flags = O_WRONLY | O_NONBLOCK;
if (!c_flag)
flags |= O_CREAT;
int fd = open(argv[i], flags, 0666);
if (fd < 0) {
fprintf(stderr, "truncate %s %s\n", argv[i], strerror(errno));
return 1;
}
if (ftruncate(fd, s_size) == -1) {
close(fd);
fprintf(stderr, "truncate %s %s\n", argv[i], strerror(errno));
return 1;
}
close(fd);
return 0;
}

0
obj/.gitignore vendored Normal file
View File