fixed ls, added files count column in long format. New macro OS_NAME in config.h that using in uname -o

This commit is contained in:
Your Name 2024-02-16 17:20:01 +03:00
parent e067b7c784
commit 3af9145796
5 changed files with 17 additions and 12 deletions

View File

@ -45,6 +45,9 @@ char *INIT_START[] = {"/etc/rc.init", NULL};
/* Default cmd (xargs) */
#define ECHO_CMD "echo"
/* Os name for uname */
/* #define OS_NAME "unknow" */
/* Options: To disable, comment line */
/* Add escape-char support in echo */
#define ECHO_FANCY

View File

@ -1,5 +1,6 @@
#include <fcntl.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
@ -84,6 +85,8 @@ int copy(int fd, void *buf, off_t len, off_t max) {
}
int main(int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
char *ifp = "-";
char *ofp = "-";

View File

@ -155,7 +155,7 @@ void dfree(struct d_node **dir, size_t files) {
free(dir);
}
char *GetDate(time_t mtime) {
char *get_date(time_t mtime) {
static char time[100];
strftime(time, sizeof(time), "%b %d %H:%M", localtime(&mtime));
return time;
@ -204,11 +204,12 @@ int print(const struct d_node *node) {
ret += printf("%7ju ", (uintmax_t)node->stats.st_ino);
if (s_flag) {
off_t size = (512 * node->stats.st_blocks + BLK_SIZE - 1) / BLK_SIZE;
if (h_flag)
ret += printf("%7s ", mu_humansize(node->stats.st_size));
ret += printf("%7s ", mu_humansize(size * BLK_SIZE));
else
ret += printf("%7ju ", (uintmax_t)node->stats.st_size);
ret += printf("%7ju ", (uintmax_t)size);
}
if (l_flag) {
@ -223,19 +224,20 @@ int print(const struct d_node *node) {
char *gr_name = (gr != 0) ? gr->gr_name : "nobody";
char *pw_name = (pw != 0) ? pw->pw_name : "nobody";
if (h_flag)
ret += printf(" %s %s %6s %s ", pw_name, gr_name, mu_humansize(node->stats.st_size), GetDate(node->stats.st_mtime));
ret += printf(" %4ju %2s %2s %6s %s ", (uintmax_t)node->stats.st_nlink, pw_name, gr_name, mu_humansize(node->stats.st_size), get_date(node->stats.st_mtime));
else
ret += printf(" %s %s %10jd %s ", pw_name, gr_name, (uintmax_t)node->stats.st_size, GetDate(node->stats.st_mtime));
ret += printf(" %4ju %2s %2s %10jd %s ", (uintmax_t)node->stats.st_nlink, pw_name, gr_name, (uintmax_t)node->stats.st_size, get_date(node->stats.st_mtime));
}
if (c_flag && p_flag)
printf("%s", color);
ret += printf("%s%c ", node->name, (F_flag) ? suf : 0);
ret += printf("%s", node->name);
if (c_flag && p_flag)
printf("\033[0m");
printf("%c", (F_flag) ? suf : 0);
return ret;
}
@ -300,10 +302,7 @@ int sorts(const void *p1, const void *p2) {
}
int sortd(const void *p1, const void *p2) {
struct d_node *l1 = *(struct d_node **)p1;
struct d_node *l2 = *(struct d_node **)p2;
return l2->name[1] - l1->name[0];
return (*(struct d_node **)p1)->stats.st_nlink - (*(struct d_node **)p2)->stats.st_nlink;
}
int ls(const char *dir_name, int label, struct winsize w) {

View File

@ -11,7 +11,7 @@
unsigned int f_flag;
unsigned int u_flag;
unsigned int z_flag;
unsigned int n_loops;
unsigned int n_loops = 3;
int shred(int rand_fd, int fd) {
/* Get size */
@ -44,7 +44,6 @@ int shred(int rand_fd, int fd) {
}
int main(int argc, char **argv) {
n_loops = 3;
int opt;
while ((opt = getopt(argc, argv, "fuzn:")) != -1) {

View File

@ -3,6 +3,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/utsname.h>
#include "config.h"
#if defined(OS_NAME)
#elif defined(__ANDROID__)