Commit | Line | Data |
---|---|---|
eeec77e9 KM |
1 | /* |
2 | * Copyright (c) 1990 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
269a7923 | 5 | * %sccs.include.redist.c% |
eeec77e9 KM |
6 | */ |
7 | ||
8 | #if defined(LIBC_SCCS) && !defined(lint) | |
269a7923 | 9 | static char sccsid[] = "@(#)genbuildname.c 5.3 (Berkeley) %G%"; |
eeec77e9 KM |
10 | #endif LIBC_SCCS and not lint |
11 | ||
eeec77e9 KM |
12 | #include <sys/types.h> |
13 | #include <sys/stat.h> | |
6ebcb998 | 14 | #include <string.h> |
eeec77e9 KM |
15 | |
16 | char *objdir = "obj"; | |
17 | ||
18 | #define UNKNOWN 0 | |
19 | #define NODIR 1 | |
20 | #define USEDIR 2 | |
21 | ||
22 | char * | |
23 | genbuildname(name) | |
24 | char *name; | |
25 | { | |
26 | static int dirlen, chkobjdir = UNKNOWN; | |
27 | struct stat stbuf; | |
28 | char *newname; | |
29 | ||
30 | if (chkobjdir == NODIR || index(name, '/') != (char *)0) | |
31 | return (name); | |
32 | if (chkobjdir == UNKNOWN && | |
33 | (stat(objdir, &stbuf) < 0 || | |
34 | (stbuf.st_mode & S_IFMT) != S_IFDIR)) { | |
35 | chkobjdir = NODIR; | |
36 | return (name); | |
37 | } else { | |
38 | chkobjdir = USEDIR; | |
39 | dirlen = strlen(objdir) + 2; | |
40 | } | |
41 | newname = (char *)malloc(dirlen + strlen(name)); | |
42 | if (newname == (char *)0) | |
43 | return (name); | |
44 | strcpy(newname, objdir); | |
45 | strcat(newname, "/"); | |
46 | strcat(newname, name); | |
47 | return (newname); | |
48 | } |