This commit is contained in:
usr 2024-06-17 12:43:35 +03:00
parent 98cedee7a7
commit 5a84258647
8 changed files with 30 additions and 38 deletions

12
TODO
View File

@ -9,7 +9,6 @@ tr
cut
shuf
stty
stat
sort
test
tar
@ -34,12 +33,8 @@ Other:
hexdump
Loginutils:
su
adduser
addgroup
deluser
passwd
delgroup
userctl
groupctl
getty
Modutils (linux only):
@ -59,7 +54,4 @@ FIX:
head
echo (escape)
xargs (-I)
ls (unicode)
que (unicode)
nl
df

View File

@ -7,8 +7,8 @@
#define MU_HUMAN_BUF_SIZE 16
char *mu_humansize(off_t n, off_t block) {
static char buf[MU_HUMAN_BUF_SIZE + 1];
memset(buf, '\0', sizeof(buf));
static char mu_hs_buf[MU_HUMAN_BUF_SIZE + 1];
memset(mu_hs_buf, '\0', sizeof(mu_hs_buf));
char *postfixes = "BKMGTPE";
@ -19,12 +19,12 @@ char *mu_humansize(off_t n, off_t block) {
size /= block;
if (i)
snprintf(buf, sizeof(buf), "%.1f%c", size, postfixes[i]);
snprintf(mu_hs_buf, sizeof(mu_hs_buf), "%.1f%c", size, postfixes[i]);
else
snprintf(buf, sizeof(buf), "%ju", n);
snprintf(mu_hs_buf, sizeof(mu_hs_buf), "%ju", n);
return buf;
return mu_hs_buf;
}
#endif

View File

@ -43,7 +43,12 @@ int main(int argc, char **argv) {
return 1;
}
puts("Filesystem Size Used Available Use% Mounted on");
if (h_flag)
puts("Filesystem Size Used Available Use% Mounted on");
else
puts("Filesystem Size Used Available Use% Mounted on");
int ret = 0;
struct mntent *me;

View File

@ -24,7 +24,7 @@ int nl(const char *path) {
size_t size = 0;
while (getline(&buf, &size, fp) != EOF) {
if (strlen(buf) > 1)
fprintf(stdout, "%*d\t%s\n", w_flag, lines++, buf);
fprintf(stdout, "%*d\t%s", w_flag, lines++, buf);
else
fprintf(stdout, "%*s\t%s", w_flag, " ", buf);

View File

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,7 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "get_stat.h"
int main(int argc, char **argv) {
}

View File

@ -20,11 +20,14 @@ int addpattern(char *str) {
}
}
regexs = realloc(regexs, (r_size + 1) * sizeof(PATTERN));
if (regexs == NULL) {
fprintf(stderr, "grep: malloc failed\n");
PATTERN *regexs_tmp = realloc(regexs, (r_size + 1) * sizeof(PATTERN));
if (regexs_tmp == NULL) {
free(regexs);
fprintf(stderr, "grep: realloc failed\n");
return 1;
}
regexs = regexs_tmp;
regexs[r_size].pattern = str;
@ -44,7 +47,7 @@ int main(int argc, char **argv) {
break;
default:
printf("grep [e] [PATTERN | -e PATTERN] [FILE]\n");
printf("grep [e] [FILE]\n\t-e PTRN Pattern to match\n");
return 0;
}
}
@ -59,4 +62,3 @@ int main(int argc, char **argv) {
free(regexs);
return 0;
}

View File

@ -52,10 +52,11 @@ int add_arg(const char *str, int chars, int flag) {
else if (s_flag > 0 && chars > s_flag)
return ERROR;
if (!flag && I_flag) {
for (int i = 0; i < args; i++)
if (strstr(cmd[i], I_flag))
cmd[i] = strdup(str);
if (!flag && I_flag && strstr(str, I_flag) != NULL) {
size_t len = strlen(I_flag) + strlen(str);
cmd[args] = malloc(len + 1);
if (cmd[args] == NULL)
return ERROR;
return I_FLAG;
}
@ -139,8 +140,10 @@ PUSH:
continue;
}
arg = realloc(arg, (arg_size++) + 1);
if (arg == NULL) {
char *tmp = realloc(arg, (arg_size++) + 1);
if (tmp == NULL) {
free(arg);
fprintf(stderr, "xargs: realloc failed\n");
return ERROR;
}