Compare commits
9 Commits
Author | SHA1 | Date |
---|---|---|
Emma Tebibyte | 9093b06166 | |
dtb | 6132c9bf47 | |
dtb | 919b171400 | |
dtb | 8e38db92c7 | |
dtb | adc9dbded5 | |
Emma Tebibyte | 488351da39 | |
Emma Tebibyte | d8b54fdbf5 | |
Emma Tebibyte | f6aac60aee | |
dtb | 61382c34d9 |
5
Makefile
5
Makefile
|
@ -17,6 +17,8 @@
|
|||
DESTDIR ?= dist
|
||||
PREFIX ?= /usr/local
|
||||
|
||||
MANDIR != [ $(PREFIX) = / ] && printf '/usr/share/man\n' \
|
||||
|| printf '/share/man\n'
|
||||
SYSEXITS != printf '\043include <sysexits.h>\n' | cpp -M - | sed 's/ /\n/g' \
|
||||
| sed -n 's/sysexits\.h//p' || printf 'include\n'
|
||||
|
||||
|
@ -42,7 +44,7 @@ clean:
|
|||
dist: all
|
||||
mkdir -p $(DESTDIR)/$(PREFIX)/bin $(DESTDIR)/$(PREFIX)/share/man/man1
|
||||
cp build/bin/* $(DESTDIR)/$(PREFIX)/bin
|
||||
cp docs/*.1 $(DESTDIR)/$(PREFIX)/share/man/man1
|
||||
cp docs/*.1 $(DESTDIR)/$(PREFIX)/$(MANDIR)/man1
|
||||
|
||||
.PHONY: install
|
||||
install: dist
|
||||
|
@ -102,7 +104,6 @@ mm: build/bin/mm
|
|||
build/bin/mm: src/mm.c build
|
||||
$(CC) $(CFLAGS) -o $@ src/mm.c
|
||||
|
||||
|
||||
.PHONY: npc
|
||||
npc: build/bin/npc
|
||||
build/bin/npc: src/npc.c build
|
||||
|
|
18
src/mm.c
18
src/mm.c
|
@ -106,6 +106,15 @@ oserr(char *s, char *r){
|
|||
} \
|
||||
return retval
|
||||
|
||||
/* Prints a usage text, in which s is the program being run (i.e. argv[0]), and
|
||||
* returns an exit status appropriate for a usage error. */
|
||||
int usage(char *s){
|
||||
|
||||
fprintf(stderr, "Usage: %s (-aenu) (-i [input])... (-o [output])...\n", s);
|
||||
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int c;
|
||||
struct Files files[2]; /* {read, write} */
|
||||
|
@ -178,12 +187,15 @@ int main(int argc, char *argv[]){
|
|||
k = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Usage: %s (-aenu) (-i [input])..."
|
||||
" (-o [output])...\n", argv[0]);
|
||||
retval = EX_USAGE;
|
||||
retval = usage(argv[0]);
|
||||
terminate;
|
||||
}
|
||||
|
||||
if(optind != argc){
|
||||
retval = usage(argv[0]);
|
||||
terminate;
|
||||
}
|
||||
|
||||
files[0].s += files[0].s == 0;
|
||||
files[1].s += files[1].s == 0;
|
||||
|
||||
|
|
15
src/scrut.c
15
src/scrut.c
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2023 DTB <trinity@trinity.moe>
|
||||
* Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
||||
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
|
@ -17,13 +18,15 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h> /* fprintf(3), stderr, NULL */
|
||||
#include <stdlib.h> /* EXIT_FAILURE */
|
||||
#include <stdlib.h> /* EXIT_FAILURE, EXIT_SUCCESS */
|
||||
#include <string.h> /* memset(3), strchr(3) */
|
||||
#ifndef EX_USAGE
|
||||
# include <sysexits.h>
|
||||
#endif
|
||||
#include <unistd.h> /* access(3), getopt(3), F_OK, R_OK, W_OK, X_OK */
|
||||
#include <sys/stat.h> /* lstat(3), stat struct, S_ISBLK, S_ISCHR, S_ISDIR,
|
||||
* S_ISFIFO, S_ISGID, S_ISREG, S_ISLNK, S_ISSOCK,
|
||||
* S_ISUID, S_ISVTX */
|
||||
#include <sysexits.h>
|
||||
|
||||
static char args[] = "bcdefghkprsuwxLS";
|
||||
static char ops[(sizeof args) / (sizeof *args)];
|
||||
|
@ -57,7 +60,7 @@ int main(int argc, char *argv[]){
|
|||
|
||||
argv += optind;
|
||||
do{ if(access(*argv, F_OK) != 0 || lstat(*argv, &buf) == -1)
|
||||
return 1; /* doesn't exist or isn't stattable */
|
||||
return EXIT_FAILURE; /* doesn't exist or isn't stattable */
|
||||
|
||||
for(i = 0; ops[i] != '\0'; ++i)
|
||||
if(ops[i] == 'e')
|
||||
|
@ -97,8 +100,8 @@ usage: fprintf(stderr, "Usage: %s (-%s) [file...]\n",
|
|||
&& !S_ISLNK(buf.st_mode))
|
||||
|| (ops[i] == 'S'
|
||||
&& !S_ISSOCK(buf.st_mode)))
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}while(*++argv != NULL);
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue