xref: /original-bsd/bin/ls/util.c (revision 9cc8b07d)
1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Michael Fischbein.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #ifndef lint
12 static char sccsid[] = "@(#)util.c	5.12 (Berkeley) 03/09/92";
13 #endif /* not lint */
14 
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <ctype.h>
20 #include <fts.h>
21 #include <errno.h>
22 #include <string.h>
23 #include "ls.h"
24 #include "extern.h"
25 
26 void
27 prcopy(src, dest, len)
28 	register char *src, *dest;
29 	register int len;
30 {
31 	register int ch;
32 
33 	while(len--) {
34 		ch = *src++;
35 		*dest++ = isprint(ch) ? ch : '?';
36 	}
37 }
38 
39 void
40 usage()
41 {
42 	(void)fprintf(stderr, "usage: ls [-1ACFLRTacdfiklqrstu] [file ...]\n");
43 	exit(1);
44 }
45 
46 #if __STDC__
47 #include <stdarg.h>
48 #else
49 #include <varargs.h>
50 #endif
51 
52 void
53 #if __STDC__
54 err(int fatal, const char *fmt, ...)
55 #else
56 err(fatal, fmt, va_alist)
57 	int fatal;
58 	char *fmt;
59 	va_dcl
60 #endif
61 {
62 	va_list ap;
63 #if __STDC__
64 	va_start(ap, fmt);
65 #else
66 	va_start(ap);
67 #endif
68 	(void)fprintf(stderr, "ls: ");
69 	(void)vfprintf(stderr, fmt, ap);
70 	va_end(ap);
71 	(void)fprintf(stderr, "\n");
72 	if (fatal)
73 		exit(1);
74 }
75