1
0
Fork 0

more cleanup

This commit is contained in:
dtb 2024-01-19 21:15:47 -07:00
parent 0398d9ca94
commit 2501cd52d8
1 changed files with 10 additions and 18 deletions

28
mm/mm.c
View File

@ -20,7 +20,7 @@
#include <signal.h> /* signal(2), SIG_ERR, SIG_IGN, SIGINT */
#include <stdio.h> /* fclose(3), fopen(3), fprintf(3), getc(3), putc(3),
* setvbuf(3), size_t, _IONBF, NULL */
#include <stdlib.h> /* free(3), malloc(3), realloc(3) */
#include <stdlib.h> /* free(3), realloc(3) */
#include <string.h> /* strerror(3) */
#include <unistd.h> /* getopt(3) */
#if !defined EX_OSERR || !defined EX_USAGE
@ -55,11 +55,6 @@ static char *stderr_name = "<stderr>";
static char *(fmode[]) = { (char []){"rb"}, (char []){"rb+"} };
static char *wharsh = "wb";
/* Opens the file at the path p and puts it in the files struct, returning NULL
* if either the opening or the placement of the open FILE pointer fail. */
#define Files_open(files, p) \
Files_append((files), fopen((p), (files)->mode), (p))
/* Adds the open FILE pointer for the file at the path s to the files struct,
* returning the FILE if successful and NULL if not, allocating more memory in
* the files buffers as needed. */
@ -84,6 +79,11 @@ Files_append(struct Files *files, FILE *file, char *name){
return files->files[files->s++] = file;
}
/* Opens the file at the path p and puts it in the files struct, returning NULL
* if either the opening or the placement of the open FILE pointer fail. */
#define Files_open(files, p) \
Files_append((files), fopen((p), (files)->mode), (p))
/* Prints a diagnostic message based on errno and returns an exit status
* appropriate for an OS error. */
static int
@ -114,17 +114,6 @@ terminate(struct Files *files){
return files;
}
/* Prints a diagnostic message synopsizing usage and returns an exit status
* appropriate for a usage error. */
static int
usage(char *s){
fprintf(stderr, "Usage: %s (-aehnu)"
" (-i [input])... (-o [output])...\n", s);
return EX_USAGE;
}
int main(int argc, char *argv[]){
int c;
size_t i;
@ -215,8 +204,11 @@ int main(int argc, char *argv[]){
s = 1;
break;
default:
fprintf(stderr, "Usage: %s (-aehnu)"
" (-i [input])... (-o [output])...\n",
argv[0]);
terminate(files);
return usage(argv[0]);
return EX_USAGE;
}
/* Unbuffer files. */