155495Sbostic /*-
2*61433Sbostic * Copyright (c) 1992, 1993
3*61433Sbostic * The Regents of the University of California. All rights reserved.
455495Sbostic *
555860Sbostic * %sccs.include.redist.c%
655495Sbostic */
755495Sbostic
855495Sbostic #ifndef lint
9*61433Sbostic static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 06/04/93";
1055495Sbostic #endif /* not lint */
1155495Sbostic
1255495Sbostic #include <sys/types.h>
1355860Sbostic
1455495Sbostic #include <unistd.h>
1555495Sbostic #include <errno.h>
1655495Sbostic #include <stdlib.h>
1755495Sbostic #include <stdio.h>
1855495Sbostic #include <string.h>
1955860Sbostic
2055858Sbostic extern char *special;
2155860Sbostic
2255495Sbostic #if __STDC__
2355495Sbostic #include <stdarg.h>
2455495Sbostic #else
2555495Sbostic #include <varargs.h>
2655495Sbostic #endif
2755495Sbostic
2855495Sbostic void
2955495Sbostic #if __STDC__
err(const int fatal,const char * fmt,...)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);
4661378Scgd if (errno)
4761378Scgd (void)fprintf(stderr, " %s", strerror(errno));
4861378Scgd (void)fprintf(stderr, "\n");
4955858Sbostic if (fatal)
5055858Sbostic exit(1);
5155495Sbostic }
5255858Sbostic
5355858Sbostic void
get(fd,off,p,len)5455858Sbostic get(fd, off, p, len)
5555858Sbostic int fd;
5655858Sbostic off_t off;
5755858Sbostic void *p;
5855858Sbostic size_t len;
5955858Sbostic {
6055858Sbostic int rbytes;
6155858Sbostic
6255858Sbostic if (lseek(fd, off, SEEK_SET) < 0)
6355858Sbostic err(1, "%s: %s", special, strerror(errno));
6455858Sbostic if ((rbytes = read(fd, p, len)) < 0)
6555858Sbostic err(1, "%s: %s", special, strerror(errno));
6655858Sbostic if (rbytes != len)
6755858Sbostic err(1, "%s: short read (%d, not %d)", special, rbytes, len);
6855858Sbostic }
69