140489Smckusick /* 240489Smckusick * Copyright (c) 1990 The Regents of the University of California. 340489Smckusick * All rights reserved. 440489Smckusick * 540489Smckusick * Redistribution and use in source and binary forms are permitted 640489Smckusick * provided that the above copyright notice and this paragraph are 740489Smckusick * duplicated in all such forms and that any documentation, 840489Smckusick * advertising materials, and other materials related to such 940489Smckusick * distribution and use acknowledge that the software was developed 1040489Smckusick * by the University of California, Berkeley. The name of the 1140489Smckusick * University may not be used to endorse or promote products derived 1240489Smckusick * from this software without specific prior written permission. 1340489Smckusick * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1440489Smckusick * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1540489Smckusick * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1640489Smckusick */ 1740489Smckusick 1840489Smckusick #if defined(LIBC_SCCS) && !defined(lint) 19*42023Sbostic static char sccsid[] = "@(#)genbuildname.c 5.2 (Berkeley) 05/15/90"; 2040489Smckusick #endif LIBC_SCCS and not lint 2140489Smckusick 2240489Smckusick #include <sys/types.h> 2340489Smckusick #include <sys/stat.h> 24*42023Sbostic #include <string.h> 2540489Smckusick 2640489Smckusick char *objdir = "obj"; 2740489Smckusick 2840489Smckusick #define UNKNOWN 0 2940489Smckusick #define NODIR 1 3040489Smckusick #define USEDIR 2 3140489Smckusick 3240489Smckusick char * 3340489Smckusick genbuildname(name) 3440489Smckusick char *name; 3540489Smckusick { 3640489Smckusick static int dirlen, chkobjdir = UNKNOWN; 3740489Smckusick struct stat stbuf; 3840489Smckusick char *newname; 3940489Smckusick 4040489Smckusick if (chkobjdir == NODIR || index(name, '/') != (char *)0) 4140489Smckusick return (name); 4240489Smckusick if (chkobjdir == UNKNOWN && 4340489Smckusick (stat(objdir, &stbuf) < 0 || 4440489Smckusick (stbuf.st_mode & S_IFMT) != S_IFDIR)) { 4540489Smckusick chkobjdir = NODIR; 4640489Smckusick return (name); 4740489Smckusick } else { 4840489Smckusick chkobjdir = USEDIR; 4940489Smckusick dirlen = strlen(objdir) + 2; 5040489Smckusick } 5140489Smckusick newname = (char *)malloc(dirlen + strlen(name)); 5240489Smckusick if (newname == (char *)0) 5340489Smckusick return (name); 5440489Smckusick strcpy(newname, objdir); 5540489Smckusick strcat(newname, "/"); 5640489Smckusick strcat(newname, name); 5740489Smckusick return (newname); 5840489Smckusick } 59