xref: /original-bsd/usr.sbin/mtree/util.c (revision 84bbc80e)
1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 static char sccsid[] = "@(#)util.c	5.3 (Berkeley) 05/22/90";
20 #endif /* not lint */
21 
22 #include <sys/param.h>
23 #include <errno.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 
28 char *
29 rlink(name)
30 	char *name;
31 {
32 	extern char path[];
33 	int len;
34 	static char lbuf[MAXPATHLEN];
35 
36 	len = readlink(name, lbuf, sizeof(lbuf));
37 	if (len == -1) {
38 		(void)fprintf(stderr, "mtree: %s: %s.\n",
39 		    path + 2, strerror(errno));
40 		exit(1);
41 	}
42 	lbuf[len] = '\0';
43 	return(lbuf);
44 }
45 
46 char *
47 emalloc(size)
48 	int size;
49 {
50 	char *p;
51 
52 	/* NOSTRICT */
53 	if (!(p = malloc((u_int)size)))
54 		nomem();
55 	bzero(p, size);
56 	return(p);
57 }
58 
59 nomem()
60 {
61 	(void)fprintf(stderr, "mtree: %s.\n", strerror(ENOMEM));
62 	exit(1);
63 }
64