1 /*- 2 * Copyright (c) 1992 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)misc.c 5.1 (Berkeley) 08/06/92"; 10 #endif /* not lint */ 11 12 #include <sys/types.h> 13 14 #include <unistd.h> 15 #include <errno.h> 16 #include <stdlib.h> 17 #include <stdio.h> 18 #include <string.h> 19 20 extern char *special; 21 22 #if __STDC__ 23 #include <stdarg.h> 24 #else 25 #include <varargs.h> 26 #endif 27 28 void 29 #if __STDC__ 30 err(const int fatal, const char *fmt, ...) 31 #else 32 err(fmt, va_alist) 33 char *fmt; 34 va_dcl 35 #endif 36 { 37 va_list ap; 38 #if __STDC__ 39 va_start(ap, fmt); 40 #else 41 va_start(ap); 42 #endif 43 (void)fprintf(stderr, "%s: ", special); 44 (void)vfprintf(stderr, fmt, ap); 45 va_end(ap); 46 (void)fprintf(stderr, " %s\n", strerror(errno)); 47 if (fatal) 48 exit(1); 49 } 50 51 void 52 get(fd, off, p, len) 53 int fd; 54 off_t off; 55 void *p; 56 size_t len; 57 { 58 int rbytes; 59 60 if (lseek(fd, off, SEEK_SET) < 0) 61 err(1, "%s: %s", special, strerror(errno)); 62 if ((rbytes = read(fd, p, len)) < 0) 63 err(1, "%s: %s", special, strerror(errno)); 64 if (rbytes != len) 65 err(1, "%s: short read (%d, not %d)", special, rbytes, len); 66 } 67