xref: /csrg-svn/lib/libc/gen/genbuildname.c (revision 40489)
1*40489Smckusick /*
2*40489Smckusick  * Copyright (c) 1990 The Regents of the University of California.
3*40489Smckusick  * All rights reserved.
4*40489Smckusick  *
5*40489Smckusick  * Redistribution and use in source and binary forms are permitted
6*40489Smckusick  * provided that the above copyright notice and this paragraph are
7*40489Smckusick  * duplicated in all such forms and that any documentation,
8*40489Smckusick  * advertising materials, and other materials related to such
9*40489Smckusick  * distribution and use acknowledge that the software was developed
10*40489Smckusick  * by the University of California, Berkeley.  The name of the
11*40489Smckusick  * University may not be used to endorse or promote products derived
12*40489Smckusick  * from this software without specific prior written permission.
13*40489Smckusick  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*40489Smckusick  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*40489Smckusick  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16*40489Smckusick  */
17*40489Smckusick 
18*40489Smckusick #if defined(LIBC_SCCS) && !defined(lint)
19*40489Smckusick static char sccsid[] = "@(#)genbuildname.c	5.1 (Berkeley) 03/13/90";
20*40489Smckusick #endif LIBC_SCCS and not lint
21*40489Smckusick 
22*40489Smckusick #include <strings.h>
23*40489Smckusick #include <sys/types.h>
24*40489Smckusick #include <sys/stat.h>
25*40489Smckusick 
26*40489Smckusick char *objdir = "obj";
27*40489Smckusick 
28*40489Smckusick #define	UNKNOWN	0
29*40489Smckusick #define	NODIR	1
30*40489Smckusick #define	USEDIR	2
31*40489Smckusick 
32*40489Smckusick char *
33*40489Smckusick genbuildname(name)
34*40489Smckusick 	char *name;
35*40489Smckusick {
36*40489Smckusick 	static int dirlen, chkobjdir = UNKNOWN;
37*40489Smckusick 	struct stat stbuf;
38*40489Smckusick 	char *newname;
39*40489Smckusick 
40*40489Smckusick 	if (chkobjdir == NODIR || index(name, '/') != (char *)0)
41*40489Smckusick 		return (name);
42*40489Smckusick 	if (chkobjdir == UNKNOWN &&
43*40489Smckusick 	    (stat(objdir, &stbuf) < 0 ||
44*40489Smckusick 	    (stbuf.st_mode & S_IFMT) != S_IFDIR)) {
45*40489Smckusick 		chkobjdir = NODIR;
46*40489Smckusick 		return (name);
47*40489Smckusick 	} else {
48*40489Smckusick 		chkobjdir = USEDIR;
49*40489Smckusick 		dirlen = strlen(objdir) + 2;
50*40489Smckusick 	}
51*40489Smckusick 	newname = (char *)malloc(dirlen + strlen(name));
52*40489Smckusick 	if (newname == (char *)0)
53*40489Smckusick 		return (name);
54*40489Smckusick 	strcpy(newname, objdir);
55*40489Smckusick 	strcat(newname, "/");
56*40489Smckusick 	strcat(newname, name);
57*40489Smckusick 	return (newname);
58*40489Smckusick }
59