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.9 (Berkeley) 10/28/91"; 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 "ls.h" 21 #include "extern.h" 22 23 void 24 prcopy(src, dest, len) 25 register char *src, *dest; 26 register int len; 27 { 28 register int ch; 29 30 while(len--) { 31 ch = *src++; 32 *dest++ = isprint(ch) ? ch : '?'; 33 } 34 } 35 36 void * 37 emalloc(size) 38 u_int size; 39 { 40 void *retval; 41 42 if ((retval = malloc(size)) == NULL) 43 err("%s", strerror(errno)); 44 return (retval); 45 } 46 47 void 48 usage() 49 { 50 (void)fprintf(stderr, "usage: ls [-1ACFLRTacdfgiklqrstu] [file ...]\n"); 51 exit(1); 52 } 53 54 #if __STDC__ 55 #include <stdarg.h> 56 #else 57 #include <varargs.h> 58 #endif 59 60 void 61 #if __STDC__ 62 err(const char *fmt, ...) 63 #else 64 err(fmt, va_alist) 65 char *fmt; 66 va_dcl 67 #endif 68 { 69 va_list ap; 70 #if __STDC__ 71 va_start(ap, fmt); 72 #else 73 va_start(ap); 74 #endif 75 (void)fprintf(stderr, "ls: "); 76 (void)vfprintf(stderr, fmt, ap); 77 va_end(ap); 78 (void)fprintf(stderr, "\n"); 79 exit(1); 80 /* NOTREACHED */ 81 } 82 83 void 84 #if __STDC__ 85 warn(const char *fmt, ...) 86 #else 87 warn(fmt, va_alist) 88 char *fmt; 89 va_dcl 90 #endif 91 { 92 va_list ap; 93 #if __STDC__ 94 va_start(ap, fmt); 95 #else 96 va_start(ap); 97 #endif 98 (void)fprintf(stderr, "ls: "); 99 (void)vfprintf(stderr, fmt, ap); 100 va_end(ap); 101 (void)fprintf(stderr, "\n"); 102 } 103