xref: /original-bsd/libexec/lfs_cleanerd/misc.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1992, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)misc.c	8.1 (Berkeley) 06/04/93";
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 	if (errno)
47 		(void)fprintf(stderr, " %s", strerror(errno));
48 	(void)fprintf(stderr, "\n");
49 	if (fatal)
50 		exit(1);
51 }
52 
53 void
54 get(fd, off, p, len)
55 	int fd;
56 	off_t off;
57 	void *p;
58 	size_t len;
59 {
60 	int rbytes;
61 
62 	if (lseek(fd, off, SEEK_SET) < 0)
63 		err(1, "%s: %s", special, strerror(errno));
64 	if ((rbytes = read(fd, p, len)) < 0)
65 		err(1, "%s: %s", special, strerror(errno));
66 	if (rbytes != len)
67 		err(1, "%s: short read (%d, not %d)", special, rbytes, len);
68 }
69