ubase

suckless linux base utils
git clone git://git.2f30.org/ubase.git
Log | Files | Refs | README | LICENSE

commit 64744bd6f19add425da46eeb880e6b7048e5972d
parent 83390f489347788a9494f770f70788c6fc2399d7
Author: sin <sin@2f30.org>
Date:   Sun Sep 29 16:35:32 +0100

Remove stat(1) - this now lives in sbase

Diffstat:
Makefile | 1-
stat.c | 73-------------------------------------------------------------------------
2 files changed, 0 insertions(+), 74 deletions(-)
diff --git a/Makefile b/Makefile @@ -36,7 +36,6 @@ SRC = \ pivot_root.c \ ps.c \ rmmod.c \ - stat.c \ swapoff.c \ swapon.c \ truncate.c \ diff --git a/stat.c b/stat.c @@ -1,73 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include <sys/stat.h> -#include <sys/types.h> -#include <unistd.h> -#include <errno.h> -#include <inttypes.h> -#include <stdio.h> -#include <time.h> -#include "util.h" - -static void show_stat(const char *file, struct stat *st); - -static void -usage(void) -{ - eprintf("usage: %s [-L] file...\n", argv0); -} - -int -main(int argc, char *argv[]) -{ - struct stat st; - int i, ret = 0; - int Lflag = 0; - int (*fn)(const char *, struct stat *); - - ARGBEGIN { - case 'L': - Lflag = 1; - break; - default: - usage(); - } ARGEND; - - if (argc == 0) { - if (fstat(STDIN_FILENO, &st) < 0) - eprintf("stat <stdin>:"); - show_stat("<stdin>", &st); - } - - for (i = 0; i < argc; i++) { - fn = Lflag ? stat : lstat; - if (fn(argv[i], &st) == -1) { - fprintf(stderr, "%s %s: ", Lflag ? "stat" : "lstat", - argv[i]); - perror(NULL); - ret = 1; - continue; - } - show_stat(argv[i], &st); - } - - return ret; -} - -static void -show_stat(const char *file, struct stat *st) -{ - char buf[100]; - - printf(" File: ā€˜%sā€™\n", file); - printf(" Size: %ju\tBlocks: %ju\tIO Block: %ju\n", (uintmax_t)st->st_size, - (uintmax_t)st->st_blocks, (uintmax_t)st->st_blksize); - printf("Device: %xh/%ud\tInode: %ju\tLinks %ju\n", major(st->st_dev), - minor(st->st_dev), (uintmax_t)st->st_ino, (uintmax_t)st->st_nlink); - printf("Access: %04o\tUid: %u\tGid: %u\n", st->st_mode & 0777, st->st_uid, st->st_gid); - strftime(buf, sizeof(buf), "%F %T %z", localtime(&st->st_atime)); - printf("Access: %s\n", buf); - strftime(buf, sizeof(buf), "%F %T %z", localtime(&st->st_mtime)); - printf("Modify: %s\n", buf); - strftime(buf, sizeof(buf), "%F %T %z", localtime(&st->st_ctime)); - printf("Change: %s\n", buf); -}