=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/file/file.c,v retrieving revision 1.30 retrieving revision 1.31 diff -c -r1.30 -r1.31 *** src/usr.bin/file/file.c 2015/04/24 16:47:32 1.30 --- src/usr.bin/file/file.c 2015/04/24 17:10:50 1.31 *************** *** 1,4 **** ! /* $OpenBSD: file.c,v 1.30 2015/04/24 16:47:32 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: file.c,v 1.31 2015/04/24 17:10:50 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott *************** *** 57,63 **** __dead void usage(void); ! static void open_file(struct input_file *, const char *, int *); static void read_link(struct input_file *); static void test_file(struct magic *, struct input_file *, int); --- 57,64 ---- __dead void usage(void); ! static void prepare_file(struct input_file *, const char *, int *); ! static void open_file(struct input_file *); static void read_link(struct input_file *); static void test_file(struct magic *, struct input_file *, int); *************** *** 91,97 **** int main(int argc, char **argv) { ! struct input_file inf; int opt, i, width = 0; FILE *f; struct magic *m; --- 92,98 ---- int main(int argc, char **argv) { ! struct input_file *files = NULL; int opt, i, width = 0; FILE *f; struct magic *m; *************** *** 166,184 **** exit(0); } for (i = 0; i < argc; i++) { ! memset(&inf, 0, sizeof inf); ! open_file(&inf, argv[i], &width); ! test_file(m, &inf, width); } exit(0); } static void ! open_file(struct input_file *inf, const char *path, int *width) { char *label; ! int n, retval; inf->path = xstrdup(path); --- 167,187 ---- exit(0); } + files = xcalloc(argc, sizeof *files); + for (i = 0; i < argc; i++) + prepare_file(&files[i], argv[i], &width); for (i = 0; i < argc; i++) { ! open_file(&files[i]); ! test_file(m, &files[i], width); } exit(0); } static void ! prepare_file(struct input_file *inf, const char *path, int *width) { char *label; ! int n; inf->path = xstrdup(path); *************** *** 186,191 **** --- 189,200 ---- if (n > *width) *width = n; inf->label = label; + } + + static void + open_file(struct input_file *inf) + { + int retval; retval = lstat(inf->path, &inf->sb); if (retval == -1) {