197680be4Sbostic /*
297680be4Sbostic * Copyright (c) 1989 The Regents of the University of California.
397680be4Sbostic * All rights reserved.
497680be4Sbostic *
597680be4Sbostic * Redistribution and use in source and binary forms are permitted
697680be4Sbostic * provided that the above copyright notice and this paragraph are
797680be4Sbostic * duplicated in all such forms and that any documentation,
897680be4Sbostic * advertising materials, and other materials related to such
997680be4Sbostic * distribution and use acknowledge that the software was developed
1097680be4Sbostic * by the University of California, Berkeley. The name of the
1197680be4Sbostic * University may not be used to endorse or promote products derived
1297680be4Sbostic * from this software without specific prior written permission.
1397680be4Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1497680be4Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1597680be4Sbostic * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1697680be4Sbostic */
1797680be4Sbostic
1897680be4Sbostic #ifndef lint
19*37bad718Sbostic static char sccsid[] = "@(#)util.c 5.3 (Berkeley) 05/22/90";
2097680be4Sbostic #endif /* not lint */
2197680be4Sbostic
2297680be4Sbostic #include <sys/param.h>
23*37bad718Sbostic #include <errno.h>
2497680be4Sbostic #include <stdio.h>
25af7d7743Sbostic #include <string.h>
26*37bad718Sbostic #include <stdlib.h>
2797680be4Sbostic
2897680be4Sbostic char *
rlink(name)2997680be4Sbostic rlink(name)
3097680be4Sbostic char *name;
3197680be4Sbostic {
3297680be4Sbostic extern char path[];
3397680be4Sbostic int len;
3497680be4Sbostic static char lbuf[MAXPATHLEN];
3597680be4Sbostic
3697680be4Sbostic len = readlink(name, lbuf, sizeof(lbuf));
3797680be4Sbostic if (len == -1) {
3897680be4Sbostic (void)fprintf(stderr, "mtree: %s: %s.\n",
3997680be4Sbostic path + 2, strerror(errno));
4097680be4Sbostic exit(1);
4197680be4Sbostic }
4297680be4Sbostic lbuf[len] = '\0';
4397680be4Sbostic return(lbuf);
4497680be4Sbostic }
4597680be4Sbostic
4697680be4Sbostic char *
emalloc(size)4797680be4Sbostic emalloc(size)
4897680be4Sbostic int size;
4997680be4Sbostic {
50*37bad718Sbostic char *p;
5197680be4Sbostic
5297680be4Sbostic /* NOSTRICT */
5397680be4Sbostic if (!(p = malloc((u_int)size)))
5497680be4Sbostic nomem();
5597680be4Sbostic bzero(p, size);
5697680be4Sbostic return(p);
5797680be4Sbostic }
5897680be4Sbostic
nomem()5997680be4Sbostic nomem()
6097680be4Sbostic {
61*37bad718Sbostic (void)fprintf(stderr, "mtree: %s.\n", strerror(ENOMEM));
6297680be4Sbostic exit(1);
6397680be4Sbostic }
64