xref: /csrg-svn/libexec/lfs_cleanerd/misc.c (revision 55858)
155495Sbostic /*-
255495Sbostic  * Copyright (c) 1991 The Regents of the University of California.
355495Sbostic  * All rights reserved.
455495Sbostic  *
555495Sbostic  * Redistribution and use in source and binary forms, with or without
655495Sbostic  * modification, are permitted provided that the following conditions
755495Sbostic  * are met:
855495Sbostic  * 1. Redistributions of source code must retain the above copyright
955495Sbostic  *    notice, this list of conditions and the following disclaimer.
1055495Sbostic  * 2. Redistributions in binary form must reproduce the above copyright
1155495Sbostic  *    notice, this list of conditions and the following disclaimer in the
1255495Sbostic  *    documentation and/or other materials provided with the distribution.
1355495Sbostic  * 3. All advertising materials mentioning features or use of this software
1455495Sbostic  *    must display the following acknowledgement:
1555495Sbostic  *	This product includes software developed by the University of
1655495Sbostic  *	California, Berkeley and its contributors.
1755495Sbostic  * 4. Neither the name of the University nor the names of its contributors
1855495Sbostic  *    may be used to endorse or promote products derived from this software
1955495Sbostic  *    without specific prior written permission.
2055495Sbostic  *
2155495Sbostic  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2255495Sbostic  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2355495Sbostic  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2455495Sbostic  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2555495Sbostic  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2655495Sbostic  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2755495Sbostic  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2855495Sbostic  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2955495Sbostic  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3055495Sbostic  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3155495Sbostic  * SUCH DAMAGE.
3255495Sbostic  */
3355495Sbostic 
3455495Sbostic #ifndef lint
3555495Sbostic static char sccsid[] = "@(#)misc.c	5.1 (Berkeley) 9/19/91";
3655495Sbostic #endif /* not lint */
3755495Sbostic 
3855495Sbostic #include <sys/types.h>
3955495Sbostic #include <unistd.h>
4055495Sbostic #include <errno.h>
4155495Sbostic #include <stdlib.h>
4255495Sbostic #include <stdio.h>
4355495Sbostic #include <string.h>
44*55858Sbostic extern char *special;
4555495Sbostic #if __STDC__
4655495Sbostic #include <stdarg.h>
4755495Sbostic #else
4855495Sbostic #include <varargs.h>
4955495Sbostic #endif
5055495Sbostic 
5155495Sbostic void
5255495Sbostic #if __STDC__
53*55858Sbostic err(const int fatal, const char *fmt, ...)
5455495Sbostic #else
5555495Sbostic err(fmt, va_alist)
5655495Sbostic 	char *fmt;
5755495Sbostic 	va_dcl
5855495Sbostic #endif
5955495Sbostic {
6055495Sbostic 	va_list ap;
6155495Sbostic #if __STDC__
6255495Sbostic 	va_start(ap, fmt);
6355495Sbostic #else
6455495Sbostic 	va_start(ap);
6555495Sbostic #endif
66*55858Sbostic 	(void)fprintf(stderr, "%s: ", special);
6755495Sbostic 	(void)vfprintf(stderr, fmt, ap);
6855495Sbostic 	va_end(ap);
69*55858Sbostic 	(void)fprintf(stderr, " %s\n", strerror(errno));
70*55858Sbostic 	if (fatal)
71*55858Sbostic 		exit(1);
7255495Sbostic }
73*55858Sbostic 
74*55858Sbostic void
75*55858Sbostic get(fd, off, p, len)
76*55858Sbostic 	int fd;
77*55858Sbostic 	off_t off;
78*55858Sbostic 	void *p;
79*55858Sbostic 	size_t len;
80*55858Sbostic {
81*55858Sbostic 	int rbytes;
82*55858Sbostic 
83*55858Sbostic 	if (lseek(fd, off, SEEK_SET) < 0)
84*55858Sbostic 		err(1, "%s: %s", special, strerror(errno));
85*55858Sbostic 	if ((rbytes = read(fd, p, len)) < 0)
86*55858Sbostic 		err(1, "%s: %s", special, strerror(errno));
87*55858Sbostic 	if (rbytes != len)
88*55858Sbostic 		err(1, "%s: short read (%d, not %d)", special, rbytes, len);
89*55858Sbostic }
90*55858Sbostic 
91