nl, du, nologin fix

This commit is contained in:
Your Name 2023-12-02 15:48:28 +03:00
parent f4a5c3d62b
commit a000660955
4 changed files with 22 additions and 9 deletions

View File

@ -1,7 +1,7 @@
#ifndef _CONFIG_H
#define _CONFIG_H
/* (cat tee wc xargs) */
/* (cat tee wc xargs rev) */
#define BUF_SIZE 4096
/* Random source (shred) */
@ -16,6 +16,9 @@
/* mount config */
#define MOUNT_CFG "/etc/fstab"
/* nologin sleep */
#define NOLOGIN_SLEEP 60
/* colors for ls */
#define LS_DIR_COLOR "\033[1;34m"
#define LS_LINK_COLOR "\033[1;35m"

View File

@ -14,15 +14,18 @@ unsigned int h_flag;
unsigned int s_flag;
unsigned int c_flag;
unsigned int b_flag;
unsigned int n_flag;
char n_flag = '\n';
off_t total;
void print(off_t size, const char *filename) {
if (h_flag)
printf("%s\t%s%c", mu_humansize(size * BLK_SIZE), filename, (n_flag) ? '\0' : '\n');
printf("%s\t%s%c", mu_humansize(size * BLK_SIZE), filename, n_flag);
else if (b_flag)
printf("%ju\t%s%c", (intmax_t)size, filename, n_flag);
else
printf("%jd\t%s%c", (intmax_t)size, filename, (n_flag) ? '\0' : '\n');
printf("%ju\t%s%c", ((intmax_t)size * BLK_SIZE) / 1024, filename, n_flag);
}
off_t du(const char *path, int recurs_flag) {
@ -71,7 +74,7 @@ off_t du(const char *path, int recurs_flag) {
sum = sb.st_size;
else
sum = (500 * sb.st_blocks + BLK_SIZE - 1) / BLK_SIZE;
sum = (512 * sb.st_blocks + BLK_SIZE - 1) / BLK_SIZE;
if (c_flag)
total += sum;
@ -106,7 +109,7 @@ int main(int argc, char **argv) {
break;
case '0':
n_flag = 1;
n_flag = '\0';
break;
default:

View File

@ -1,11 +1,12 @@
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "config.h"
unsigned int w_flag = 2;
unsigned int w_flag = 4;
unsigned int lines = 1;
int nl(const char *path) {
@ -20,11 +21,14 @@ int nl(const char *path) {
}
char buf[BUF_SIZE + 1];
while (fgets(buf, sizeof(buf), fp))
while (fgets(buf, sizeof(buf), fp)) {
if (strlen(buf) > 1)
fprintf(stdout, "%*u\t%s", w_flag, lines++, buf);
putchar('\n');
else
fprintf(stdout, "%*s\t%s", w_flag, " ", buf);
}
if (strcmp(path, "-"))
fclose(fp);

View File

@ -1,6 +1,9 @@
#include <stdio.h>
#include <unistd.h>
#include "config.h"
int main(void) {
printf("nologin: shell disabled\n");
sleep(NOLOGIN_SLEEP);
return 0;
}