From: David Cantrell Date: Wed, 22 Aug 2012 01:51:56 +0000 (-0400) Subject: Use mkstemp() and handle /usr/lib64 in imake.c X-Git-Tag: 2.2.0b~64 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=16c57ad6690097ec6ed8b8995114bee1deb2fa7d;p=oweals%2Fcde.git Use mkstemp() and handle /usr/lib64 in imake.c tmpnam() usage replaced with mkstemp(). Find a suitable tmp directory checking the TMPDIR environment variable first, then the P_tmpdir macro and finally /tmp directly. On 64-bit Linux platforms, check to see if libc.so exists in /usr/lib64. If found, use it over /usr/lib/libc.so. --- diff --git a/cde/config/imake/imake.c b/cde/config/imake/imake.c index 5e26133a..cf0063f3 100644 --- a/cde/config/imake/imake.c +++ b/cde/config/imake/imake.c @@ -950,6 +950,9 @@ static const char libc_c[]= "}\n" ; +#define libc32path "/usr/lib/libc.so" +#define libc64path "/usr/lib64/libc.so" + static void get_libc_version(FILE *inFile) { @@ -973,13 +976,13 @@ get_libc_version(FILE *inFile) if (!strcmp(u.sysname, "Linux") && (!strcmp(u.machine, "x86_64"))) { - if (!lstat ("/usr/lib64/libc.so", &sb) && S_ISREG(sb.st_mode)) { - libcso = strdup("/usr/lib64/libc.so"); + if (!lstat (libc64path, &sb) && S_ISREG(sb.st_mode)) { + libcso = libc64path; } } if (libcso == NULL) { - libcso = strdup("/usr/lib/libc.so"); + libcso = libc32path; } if (lstat (libcso, &sb) == 0) { @@ -1000,13 +1003,35 @@ get_libc_version(FILE *inFile) * /usr/lib/libc.so is NOT a symlink -- this is libc 6.x / glibc 2.x * now we have to figure this out the hard way. */ - char *aout = tmpnam (NULL); + char aout[PATH_MAX]; + int fd = -1; FILE *fp; const char *format = "%s -o %s -x c -"; char *cc; int len; char *command; + memset(&aout, '\0', PATH_MAX); + + if (!lstat(getenv("TMPDIR"), &sb) && S_ISDIR(sb.st_mode)) + strcpy(aout, getenv("TMPDIR")); +#ifdef P_tmpdir /* defined by XPG and XOPEN, but don't assume we have it */ + else if (!lstat(P_tmpdir, &sb) && S_ISDIR(sb.st_mode)) + strcpy(aout, P_tmpdir); +#endif + else if (!lstat("/tmp", &sb) && S_ISDIR(sb.st_mode)) + strcpy(aout, "/tmp"); + else + abort(); + + strcpy(aout+strlen(aout), "/imaketmp.XXXXXX"); + + if ((fd = mkstemp(aout)) == -1) + abort (); + + if (close(fd) == -1) + abort (); + cc = getenv ("CC"); if (cc == NULL) cc = "gcc"; @@ -1034,8 +1059,6 @@ get_libc_version(FILE *inFile) abort (); } } - - free(libcso); } static void