155495Sbostic /*- 2*55860Sbostic * Copyright (c) 1992 The Regents of the University of California. 355495Sbostic * All rights reserved. 455495Sbostic * 5*55860Sbostic * %sccs.include.redist.c% 655495Sbostic */ 755495Sbostic 855495Sbostic #ifndef lint 9*55860Sbostic static char sccsid[] = "@(#)misc.c 5.1 (Berkeley) 08/06/92"; 1055495Sbostic #endif /* not lint */ 1155495Sbostic 1255495Sbostic #include <sys/types.h> 13*55860Sbostic 1455495Sbostic #include <unistd.h> 1555495Sbostic #include <errno.h> 1655495Sbostic #include <stdlib.h> 1755495Sbostic #include <stdio.h> 1855495Sbostic #include <string.h> 19*55860Sbostic 2055858Sbostic extern char *special; 21*55860Sbostic 2255495Sbostic #if __STDC__ 2355495Sbostic #include <stdarg.h> 2455495Sbostic #else 2555495Sbostic #include <varargs.h> 2655495Sbostic #endif 2755495Sbostic 2855495Sbostic void 2955495Sbostic #if __STDC__ 3055858Sbostic err(const int fatal, const char *fmt, ...) 3155495Sbostic #else 3255495Sbostic err(fmt, va_alist) 3355495Sbostic char *fmt; 3455495Sbostic va_dcl 3555495Sbostic #endif 3655495Sbostic { 3755495Sbostic va_list ap; 3855495Sbostic #if __STDC__ 3955495Sbostic va_start(ap, fmt); 4055495Sbostic #else 4155495Sbostic va_start(ap); 4255495Sbostic #endif 4355858Sbostic (void)fprintf(stderr, "%s: ", special); 4455495Sbostic (void)vfprintf(stderr, fmt, ap); 4555495Sbostic va_end(ap); 4655858Sbostic (void)fprintf(stderr, " %s\n", strerror(errno)); 4755858Sbostic if (fatal) 4855858Sbostic exit(1); 4955495Sbostic } 5055858Sbostic 5155858Sbostic void 5255858Sbostic get(fd, off, p, len) 5355858Sbostic int fd; 5455858Sbostic off_t off; 5555858Sbostic void *p; 5655858Sbostic size_t len; 5755858Sbostic { 5855858Sbostic int rbytes; 5955858Sbostic 6055858Sbostic if (lseek(fd, off, SEEK_SET) < 0) 6155858Sbostic err(1, "%s: %s", special, strerror(errno)); 6255858Sbostic if ((rbytes = read(fd, p, len)) < 0) 6355858Sbostic err(1, "%s: %s", special, strerror(errno)); 6455858Sbostic if (rbytes != len) 6555858Sbostic err(1, "%s: short read (%d, not %d)", special, rbytes, len); 6655858Sbostic } 67