Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
a28542e5e5 |
5
Makefile
5
Makefile
@ -171,3 +171,8 @@ build/bin/swab: src/swab.rs build rustlibs
|
||||
true: build/bin/true
|
||||
build/bin/true: src/true.c build
|
||||
$(CC) $(CFLAGS) -o $@ src/true.c
|
||||
|
||||
.PHONY: zn
|
||||
zn: build/bin/zn
|
||||
build/bin/zn: src/zn.c build
|
||||
$(CC) $(CFLAGS) -o $@ src/zn.c
|
||||
|
61
src/zn.c
Normal file
61
src/zn.c
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include <limits.h> /* _POSIX_MAX_CANON */
|
||||
#include <stdio.h> /* fgets(3) */
|
||||
#include <string.h> /* strtok(3) */
|
||||
#include <sysexits.h> /* EX_OSERR */
|
||||
#include <unistd.h> /* fork(2) */
|
||||
#include <sys/wait.h> /* wait(2), WIFEXITED, WEXITSTATUS */
|
||||
|
||||
static char *sep = " \t\v\n";
|
||||
|
||||
static char **
|
||||
get_args(char *s) {
|
||||
size_t c = 0;
|
||||
static char *v[10];
|
||||
|
||||
if ((v[c] = strtok(s, sep)) == NULL) { return NULL; }
|
||||
|
||||
while (++c < sizeof v / sizeof *v) {
|
||||
if ((v[c] = strtok(NULL, sep)) == NULL) { return v; }
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_line(FILE *stream) {
|
||||
static char buffer[_POSIX_MAX_CANON];
|
||||
|
||||
return fgets(buffer, sizeof *buffer * MAX_CANON, stream);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char **a;
|
||||
char *s;
|
||||
|
||||
while ((s = get_line(stdin)) != NULL) {
|
||||
a = get_args(s);
|
||||
switch (fork()) {
|
||||
case -1: perror(argv[0]); return EX_OSERR;
|
||||
case 0: execvp(a[0], a);
|
||||
default: (void)wait(NULL);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user