Commit 95dbaa61 authored by Orion Poplawski's avatar Orion Poplawski Committed by Mike Gabriel

Fix FTBFS when compiled with -Werror=format-security…

Fix FTBFS when compiled with -Werror=format-security (055_nx-X11_imake-Werror-format-security.full.patch).
parent 0b711de4
Description: Fix FTBFS when compiled with -Werror=format-security
Author: Orion Poplawski <orion@cora.nwra.com>
diff -up a/nx-X11/config/imake/imake.c b/nx-X11/config/imake/imake.c
--- a/nx-X11/config/imake/imake.c 2014-01-04 13:39:35.000000000 -0700
+++ b/nx-X11/config/imake/imake.c 2014-01-24 13:55:53.940697330 -0700
@@ -7,8 +7,6 @@
* be passed to the template file. *
* *
***************************************************************************/
-/* $XFree86: xc/config/imake/imake.c,v 3.63tsi Exp $ */
-
/*
*
Copyright (c) 1985, 1986, 1987, 1998 The Open Group
@@ -153,23 +151,14 @@ in this Software without prior written a
#endif
#include <stdlib.h>
#include <stdio.h>
-#ifdef MONOLITH
-# include "Xosdefs.h"
-#else
-# include <X11/Xosdefs.h>
-#endif
+#include <stdarg.h>
+#include <X11/Xfuncproto.h>
+#include <X11/Xosdefs.h>
#include <string.h>
#include <ctype.h>
#ifdef WIN32
# include "Xw32defs.h"
#endif
-#if 0
-#ifndef X_NOT_POSIX
-# ifndef _POSIX_SOURCE
-# define _POSIX_SOURCE
-# endif
-#endif
-#endif
#include <sys/types.h>
#include <fcntl.h>
#ifdef X_NOT_POSIX
@@ -231,22 +220,16 @@ typedef union wait waitType;
# define WIFEXITED(w) waitCode(w)
# endif
#endif /* X_NOT_POSIX */
-# include <stdlib.h>
-#if defined(macII) && !defined(__STDC__) /* stdlib.h fails to define these */
-char *malloc(), *realloc();
-#endif /* macII */
+#include <stdlib.h>
#include <errno.h>
#ifdef __minix_vmd
-#define USE_FREOPEN 1
+# define USE_FREOPEN 1
#endif
-#if !((defined(sun) && !defined(SVR4)) || defined(macII))
-#define USE_STRERROR 1
-#endif
#ifndef WIN32
-#include <sys/utsname.h>
+# include <sys/utsname.h>
#else
-#include <windows.h>
+# include <windows.h>
#endif
#ifndef SYS_NMLN
# ifdef _SYS_NMLN
@@ -256,39 +239,22 @@ char *malloc(), *realloc();
# endif
#endif
#if defined(linux) || defined(__GNU__) || defined(__GLIBC__)
-#include <limits.h>
-#include <stdio.h>
+# include <limits.h>
+# include <stdio.h>
#endif
#ifdef __QNX__
-#include <unix.h>
-#endif
-
-/*
- * This define of strerror is copied from (and should be identical to)
- * Xos.h, which we don't want to include here for bootstrapping reasons.
- */
-#ifndef USE_STRERROR
-# ifndef strerror
-extern char *sys_errlist[];
-extern int sys_nerr;
-# define strerror(n) \
- (((n) >= 0 && (n) < sys_nerr) ? sys_errlist[n] : "unknown error")
-# endif
+# include <unix.h>
#endif
#if defined(__NetBSD__) /* see code clock in init() below */
-#include <sys/utsname.h>
-#endif
-
-#if !(defined(Lynx) || defined(__Lynx__) || (defined(SVR4) && !defined(sun))) && !defined (__CYGWIN__)
-#define HAS_MKSTEMP
+# include <sys/utsname.h>
#endif
typedef unsigned char boolean;
#define TRUE 1
#define FALSE 0
-# include "imakemdep.h"
+#include "imakemdep.h"
#ifdef CROSSCOMPILE
# include "imakemdep_cpp.h"
#endif
@@ -305,7 +271,7 @@ int xvariables[10];
#endif
#ifndef PATH_MAX
-#define PATH_MAX 1024
+# define PATH_MAX 1024
#endif
/*
@@ -331,11 +297,13 @@ void KludgeOutputLine(char **), KludgeRe
# endif
#endif
-char *cpp = NULL;
+const char *cpp = NULL;
-char *tmpMakefile = "/tmp/Imf.XXXXXX";
-char *tmpImakefile = "/tmp/IIf.XXXXXX";
-char *make_argv[ ARGUMENTS ] = {
+const char *tmpMakefile;
+const char *tmpMakefileTemplate = "/tmp/Imf.XXXXXX";
+const char *tmpImakefile;
+const char *tmpImakefileTemplate = "/tmp/IIf.XXXXXX";
+const char *make_argv[ ARGUMENTS ] = {
#ifdef WIN32
"nmake"
#else
@@ -345,53 +313,53 @@ char *make_argv[ ARGUMENTS ] = {
int make_argindex;
int cpp_argindex;
-char *Imakefile = NULL;
-char *Makefile = "Makefile";
-char *Template = "Imake.tmpl";
-char *ImakefileC = "Imakefile.c";
+const char *Imakefile = NULL;
+const char *Makefile = "Makefile";
+const char *Template = "Imake.tmpl";
+const char *ImakefileC = "Imakefile.c";
boolean haveImakefileC = FALSE;
-char *cleanedImakefile = NULL;
-char *program;
-char *FindImakefile(char *Imakefile);
-char *ReadLine(FILE *tmpfd, char *tmpfname);
-char *CleanCppInput(char *imakefile);
-char *Strdup(char *cp);
+const char *cleanedImakefile = NULL;
+const char *program;
+const char *FindImakefile(const char *Imakefile);
+char *ReadLine(FILE *tmpfd, const char *tmpfname);
+const char *CleanCppInput(const char *imakefile);
+char *Strdup(const char *cp);
char *Emalloc(int size);
-void LogFatalI(char *s, int i), LogFatal(char *x0, char *x1),
- LogMsg(char *x0, char *x1);
+void LogFatal(const char *x0, ...) _X_ATTRIBUTE_PRINTF(1, 2);
+void LogMsg(const char *x0, ...) _X_ATTRIBUTE_PRINTF(1, 2);
void showit(FILE *fd);
void wrapup(void);
void init(void);
-void AddMakeArg(char *arg);
-void AddCppArg(char *arg);
+void AddMakeArg(const char *arg);
+void AddCppArg(const char *arg);
#ifdef CROSSCOMPILE
char *CrossCompileCPP(void);
#endif
void SetOpts(int argc, char **argv);
-void CheckImakefileC(char *masterc);
-void cppit(char *imakefile, char *template, char *masterc,
- FILE *outfd, char *outfname);
+void CheckImakefileC(const char *masterc);
+void cppit(const char *imakefile, const char *template, const char *masterc,
+ FILE *outfd, const char *outfname);
void makeit(void);
-void CleanCppOutput(FILE *tmpfd, char *tmpfname);
+void CleanCppOutput(FILE *tmpfd, const char *tmpfname);
boolean isempty(char *line);
-void writetmpfile(FILE *fd, char *buf, int cnt, char *fname);
+void writetmpfile(FILE *fd, const char *buf, int cnt, const char *fname);
#ifdef SIGNALRETURNSINT
int catch(int sig);
#else
void catch(int sig);
#endif
-void showargs(char **argv);
-boolean optional_include(FILE *inFile, char *defsym, char *fname);
-void doit(FILE *outfd, char *cmd, char **argv);
+void showargs(const char **argv);
+boolean optional_include(FILE *inFile, const char *defsym, const char *fname);
+void doit(FILE *outfd, const char *cmd, const char **argv);
boolean define_os_defaults(FILE *inFile);
#ifdef CROSSCOMPILE
static void get_cross_compile_dir(FILE *inFile);
#endif
#ifdef CROSSCOMPILEDIR
-char *CrossCompileDir = CROSSCOMPILEDIR;
+const char *CrossCompileDir = CROSSCOMPILEDIR;
#else
-char *CrossCompileDir = "";
+const char *CrossCompileDir = "";
#endif
boolean CrossCompiling = FALSE;
@@ -428,24 +396,25 @@ main(int argc, char *argv[])
if ((tmpfd = fopen(tmpMakefile, "w+")) == NULL)
LogFatal("Cannot create temporary file %s.", tmpMakefile);
} else {
-#ifdef HAS_MKSTEMP
+#ifdef HAVE_MKSTEMP
int fd;
#endif
- tmpMakefile = Strdup(tmpMakefile);
-#ifndef HAS_MKSTEMP
- if (mktemp(tmpMakefile) == NULL ||
- (tmpfd = fopen(tmpMakefile, "w+")) == NULL) {
- LogFatal("Cannot create temporary file %s.", tmpMakefile);
+ char *tmpMakefileName = Strdup(tmpMakefileTemplate);
+#ifndef HAVE_MKSTEMP
+ if (mktemp(tmpMakefileName) == NULL ||
+ (tmpfd = fopen(tmpMakefileName, "w+")) == NULL) {
+ LogFatal("Cannot create temporary file %s.", tmpMakefileName);
}
#else
- fd = mkstemp(tmpMakefile);
+ fd = mkstemp(tmpMakefileName);
if (fd == -1 || (tmpfd = fdopen(fd, "w+")) == NULL) {
if (fd != -1) {
- unlink(tmpMakefile); close(fd);
+ unlink(tmpMakefileName); close(fd);
}
- LogFatal("Cannot create temporary file %s.", tmpMakefile);
+ LogFatal("Cannot create temporary file %s.", tmpMakefileName);
}
#endif
+ tmpMakefile = tmpMakefileName;
}
AddMakeArg("-f");
AddMakeArg( tmpMakefile );
@@ -498,7 +467,7 @@ void
catch(int sig)
{
errno = 0;
- LogFatalI("Signal %d.", sig);
+ LogFatal("Signal %d.", sig);
}
/*
@@ -572,21 +541,21 @@ init(void)
}
void
-AddMakeArg(char *arg)
+AddMakeArg(const char *arg)
{
errno = 0;
if (make_argindex >= ARGUMENTS-1)
- LogFatal("Out of internal storage.", "");
+ LogFatal("Out of internal storage.");
make_argv[ make_argindex++ ] = arg;
make_argv[ make_argindex ] = NULL;
}
void
-AddCppArg(char *arg)
+AddCppArg(const char *arg)
{
errno = 0;
if (cpp_argindex >= ARGUMENTS-1)
- LogFatal("Out of internal storage.", "");
+ LogFatal("Out of internal storage.");
cpp_argv[ cpp_argindex++ ] = arg;
cpp_argv[ cpp_argindex ] = NULL;
}
@@ -618,7 +587,7 @@ SetOpts(int argc, char **argv)
else {
argc--, argv++;
if (! argc)
- LogFatal("No description arg after -f flag", "");
+ LogFatal("No description arg after -f flag");
Imakefile = argv[0];
}
} else if (argv[0][1] == 's') {
@@ -628,7 +597,7 @@ SetOpts(int argc, char **argv)
else {
argc--, argv++;
if (!argc)
- LogFatal("No description arg after -s flag", "");
+ LogFatal("No description arg after -s flag");
Makefile = ((argv[0][0] == '-') && !argv[0][1]) ?
NULL : argv[0];
}
@@ -642,7 +611,7 @@ SetOpts(int argc, char **argv)
else {
argc--, argv++;
if (! argc)
- LogFatal("No description arg after -T flag", "");
+ LogFatal("No description arg after -T flag");
Template = argv[0];
}
} else if (argv[0][1] == 'C') {
@@ -651,7 +620,7 @@ SetOpts(int argc, char **argv)
else {
argc--, argv++;
if (! argc)
- LogFatal("No imakeCfile arg after -C flag", "");
+ LogFatal("No imakeCfile arg after -C flag");
ImakefileC = argv[0];
}
} else if (argv[0][1] == 'v') {
@@ -667,10 +636,10 @@ SetOpts(int argc, char **argv)
if (!cpp)
{
AddCppArg("-E");
-#ifdef __GNUC__
+# ifdef __GNUC__
if (verbose)
AddCppArg("-v");
-#endif
+# endif
cpp = DEFAULT_CC;
}
# else
@@ -686,8 +655,8 @@ SetOpts(int argc, char **argv)
AddCppArg(ImakefileC);
}
-char *
-FindImakefile(char *Imakefile)
+const char *
+FindImakefile(const char *Imakefile)
{
if (Imakefile) {
if (access(Imakefile, R_OK) < 0)
@@ -695,7 +664,7 @@ FindImakefile(char *Imakefile)
} else {
if (access("Imakefile", R_OK) < 0) {
if (access("imakefile", R_OK) < 0)
- LogFatal("No description file.", "");
+ LogFatal("No description file.");
else
Imakefile = "imakefile";
} else
@@ -704,44 +673,50 @@ FindImakefile(char *Imakefile)
return(Imakefile);
}
-void
-LogFatalI(char *s, int i)
+static void _X_ATTRIBUTE_PRINTF(1, 0)
+vLogMsg(const char *fmt, va_list args)
{
- /*NOSTRICT*/
- LogFatal(s, (char *)(long)i);
+ int error_number = errno;
+
+ if (error_number) {
+ fprintf(stderr, "%s: ", program);
+ fprintf(stderr, "%s\n", strerror(error_number));
+ }
+ fprintf(stderr, "%s: ", program);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
}
void
-LogFatal(char *x0, char *x1)
+LogFatal(const char *fmt, ...)
{
static boolean entered = FALSE;
+ va_list args;
if (entered)
return;
entered = TRUE;
- LogMsg(x0, x1);
+ va_start(args, fmt);
+ vLogMsg(fmt, args);
+ va_end(args);
fprintf(stderr, " Stop.\n");
wrapup();
exit(1);
}
void
-LogMsg(char *x0, char *x1)
+LogMsg(const char *fmt, ...)
{
- int error_number = errno;
+ va_list args;
- if (error_number) {
- fprintf(stderr, "%s: ", program);
- fprintf(stderr, "%s\n", strerror(error_number));
- }
- fprintf(stderr, "%s: ", program);
- fprintf(stderr, x0, x1);
- fprintf(stderr, "\n");
+ va_start(args, fmt);
+ vLogMsg(fmt, args);
+ va_end(args);
}
void
-showargs(char **argv)
+showargs(const char **argv)
{
for (; *argv; argv++)
fprintf(stderr, "%s ", *argv);
@@ -751,7 +726,7 @@ showargs(char **argv)
#define ImakefileCHeader "/* imake - temporary file */"
void
-CheckImakefileC(char *masterc)
+CheckImakefileC(const char *masterc)
{
char mkcbuf[1024];
FILE *inFile;
@@ -767,7 +742,8 @@ CheckImakefileC(char *masterc)
fclose(inFile);
LogFatal("Refuse to overwrite: %s", masterc);
}
- fclose(inFile);
+ else
+ fclose(inFile);
}
}
@@ -778,7 +754,7 @@ CheckImakefileC(char *masterc)
#define OverrideWarning "Warning: local file \"%s\" overrides global macros."
boolean
-optional_include(FILE *inFile, char *defsym, char *fname)
+optional_include(FILE *inFile, const char *defsym, const char *fname)
{
errno = 0;
if (access(fname, R_OK) == 0) {
@@ -790,7 +766,7 @@ optional_include(FILE *inFile, char *def
}
void
-doit(FILE *outfd, char *cmd, char **argv)
+doit(FILE *outfd, const char *cmd, const char **argv)
{
int pid;
waitType status;
@@ -805,18 +781,18 @@ doit(FILE *outfd, char *cmd, char **argv
if (status < 0)
LogFatal("Cannot spawn %s.", cmd);
if (status > 0)
- LogFatalI("Exit code %d.", status);
+ LogFatal("Exit code %d.", status);
#else
pid = fork();
if (pid < 0)
- LogFatal("Cannot fork.", "");
+ LogFatal("Cannot fork.");
if (pid) { /* parent... simply wait */
while (wait(&status) > 0) {
errno = 0;
if (WIFSIGNALED(status))
- LogFatalI("Signal %d.", waitSig(status));
+ LogFatal("Signal %d.", waitSig(status));
if (WIFEXITED(status) && waitCode(status))
- LogFatalI("Exit code %d.", waitCode(status));
+ LogFatal("Exit code %d.", waitCode(status));
}
}
else { /* child... dup and exec cmd */
@@ -832,7 +808,7 @@ doit(FILE *outfd, char *cmd, char **argv
#if !defined WIN32
static void
-parse_utsname(struct utsname *name, char *fmt, char *result, char *msg)
+parse_utsname(struct utsname *name, const char *fmt, char *result, const char *msg)
{
char buf[SYS_NMLN * 5 + 1];
char *ptr = buf;
@@ -892,7 +868,7 @@ parse_utsname(struct utsname *name, char
/* Just in case... */
if (strlen(buf) >= sizeof(buf))
- LogFatal("Buffer overflow parsing uname.", "");
+ LogFatal("Buffer overflow parsing uname.");
/* Parse the buffer. The sscanf() return value is rarely correct. */
*result = '\0';
@@ -978,13 +954,23 @@ const char *libc_c=
static void
get_libc_version(FILE *inFile)
{
- char aout[] = "/tmp/imakeXXXXXX";
+ char aout[4096], *tmpdir;
FILE *fp;
const char *format = "%s -o %s -x c -";
char *cc;
int len;
char *command;
+ /* If $TMPDIR is defined and has an acceptable length,
+ * use that as tmp dir, else use /tmp. That fixes
+ * problems with /tmp mounted "noexec".
+ */
+ if((tmpdir = getenv("TMPDIR")) != NULL && strlen(tmpdir) < (4096-13))
+ strcpy(aout, tmpdir);
+ else
+ strcpy(aout, "/tmp");
+ strcat(aout, "/imakeXXXXXX");
+
/* Pre-create temp file safely */
{
/* Linux + ELF has mkstemp() */
@@ -1000,7 +986,8 @@ get_libc_version(FILE *inFile)
cc = "gcc";
len = strlen (aout) + strlen (format) + strlen (cc);
if (len < 128) len = 128;
- command = alloca (len);
+ if((command = alloca (len)) == NULL)
+ abort();
if (snprintf (command , len, format, cc, aout) == len)
abort ();
@@ -1015,12 +1002,16 @@ get_libc_version(FILE *inFile)
abort ();
while (fgets (command, len, fp))
- fprintf (inFile, command);
+ fputs (command, inFile);
len = pclose (fp);
remove (aout);
- if (len)
- abort ();
+ if (len) {
+ /* handwave furiously */
+ printf("#define DefaultLinuxCLibMajorVersion 6\n");
+ printf("#define DefaultLinuxCLibMinorVersion 12\n");
+ printf("#define DefaultLinuxCLibTeenyVersion 0\n");
+ }
}
#endif
@@ -1031,14 +1022,14 @@ get_stackprotector(FILE *inFile)
FILE *fp;
char *cc;
char command[1024], buf[1024];
-
+
cc = getenv("CC");
if (cc == NULL) {
cc = "cc";
}
snprintf(command, sizeof(command), "%s -v 2>&1", cc);
fp = popen(command, "r");
- if (fp == NULL)
+ if (fp == NULL)
abort();
while (fgets(buf, sizeof(buf), fp)) {
if (strstr(buf, "propolice") != NULL) {
@@ -1046,11 +1037,10 @@ get_stackprotector(FILE *inFile)
break;
}
}
- if (pclose(fp))
- abort();
+ pclose(fp);
}
#endif
-
+
#if defined CROSSCOMPILE || defined linux || defined(__GLIBC__)
static void
@@ -1058,9 +1048,9 @@ get_distrib(FILE *inFile)
{
struct stat sb;
- static char* suse = "/etc/SuSE-release";
- static char* redhat = "/etc/redhat-release";
- static char* debian = "/etc/debian_version";
+ static const char* suse = "/etc/SuSE-release";
+ static const char* redhat = "/etc/redhat-release";
+ static const char* debian = "/etc/debian_version";
fprintf (inFile, "%s\n", "#define LinuxUnknown 0");
fprintf (inFile, "%s\n", "#define LinuxSuSE 1");
@@ -1076,14 +1066,14 @@ get_distrib(FILE *inFile)
fprintf (inFile, "%s\n", "#define LinuxWare 11");
fprintf (inFile, "%s\n", "#define LinuxYggdrasil 12");
-#ifdef CROSSCOMPILE
+# ifdef CROSSCOMPILE
if (CrossCompiling) {
fprintf (inFile, "%s\n",
"#define DefaultLinuxDistribution LinuxUnknown");
fprintf (inFile, "%s\n", "#define DefaultLinuxDistName Unknown");
return;
}
-#endif
+# endif
if (lstat (suse, &sb) == 0) {
fprintf (inFile, "%s\n", "#define DefaultLinuxDistribution LinuxSuSE");
fprintf (inFile, "%s\n", "#define DefaultLinuxDistName SuSE");
@@ -1116,7 +1106,7 @@ get_ld_version(FILE *inFile)
int ldmajor, ldminor;
const char *ld = "ld -v";
-#ifdef CROSSCOMPILE
+# ifdef CROSSCOMPILE
if (CrossCompiling) {
char cmd[PATH_MAX];
strcpy (cmd, CrossCompileDir);
@@ -1124,7 +1114,7 @@ get_ld_version(FILE *inFile)
strcat (cmd,ld);
ldprog = popen (cmd, "r");
} else
-#endif
+# endif
ldprog = popen (ld, "r");
if (ldprog) {
@@ -1192,7 +1182,7 @@ get_binary_format(FILE *inFile)
* Returns: 0 if successful, -1 if not.
*/
static int
-ask_sun_compiler_for_versions(const char *cmd, const char *path,
+ask_sun_compiler_for_versions(const char *cmd, const char *path,
int *cmajor, int *cminor)
{
char buf[BUFSIZ];
@@ -1201,7 +1191,7 @@ ask_sun_compiler_for_versions(const char
FILE* ccproc;
const char vflag[] = " -V 2>&1";
int retval = -1;
-
+
int len = strlen(cmd) + sizeof(vflag);
if (path != NULL) {
@@ -1229,7 +1219,7 @@ ask_sun_compiler_for_versions(const char
}
}
if (retval != 0) {
- fprintf(stderr,
+ fprintf(stderr,
"warning: could not parse version number in output of:\n"
" %s\n", cmdtorun);
}
@@ -1247,23 +1237,22 @@ get_sun_compiler_versions (FILE *inFile)
{
const char* sunpro_path = "/opt/SUNWspro/bin";
int cmajor, cminor, found = 0;
- struct stat sb;
/* If cross-compiling, only check CrossCompilerDir for compilers.
- * If not cross-compiling, first check cc in users $PATH,
+ * If not cross-compiling, first check cc in users $PATH,
* then try /opt/SUNWspro if not found in the users $PATH
*/
-#if defined CROSSCOMPILE
+# if defined CROSSCOMPILE
if (CrossCompiling) {
if (ask_sun_compiler_for_versions("cc", CrossCompileDir,
&cmajor, &cminor) == 0) {
found = 1;
}
- }
+ }
else
-#endif
- {
+# endif
+ {
if (ask_sun_compiler_for_versions("cc", NULL, &cmajor, &cminor) == 0) {
found = 1;
} else if (ask_sun_compiler_for_versions("cc", sunpro_path,
@@ -1282,22 +1271,22 @@ get_sun_compiler_versions (FILE *inFile)
/* Now do it again for C++ compiler (CC) */
found = 0;
-#if defined CROSSCOMPILE
+# if defined CROSSCOMPILE
if (CrossCompiling) {
if (ask_sun_compiler_for_versions("CC", CrossCompileDir,
&cmajor, &cminor) == 0) {
found = 1;
}
- }
+ }
else
-#endif
- {
+# endif
+ {
if (ask_sun_compiler_for_versions("CC", NULL, &cmajor, &cminor) == 0) {
found = 1;
} else if (ask_sun_compiler_for_versions("CC", sunpro_path,
&cmajor, &cminor) == 0) {
found = 1;
- fprintf(inFile,
+ fprintf(inFile,
"#define DefaultSunProCplusplusCompilerDir %s", sunpro_path);
}
}
@@ -1318,7 +1307,7 @@ static void
get_gcc_version(FILE *inFile, char *name)
{
fprintf (inFile, "#define HasGcc 1\n");
-#ifdef CROSSCOMPILE
+# ifdef CROSSCOMPILE
if (CrossCompiling)
{
if (gnu_c > 1) {
@@ -1329,20 +1318,20 @@ get_gcc_version(FILE *inFile, char *name
fprintf (inFile, "#define GccMajorVersion %d\n", gnu_c);
fprintf (inFile, "#define GccMinorVersion %d\n", gnu_c_minor);
} else
-#endif
+# endif
{
-#if __GNUC__ > 1
+# if __GNUC__ > 1
fprintf (inFile, "#define HasGcc2 1\n");
-# if __GNUC__ > 2
+# if __GNUC__ > 2
fprintf (inFile, "#define HasGcc3 1\n");
+# endif
# endif
-#endif
fprintf (inFile, "#define GccMajorVersion %d\n", __GNUC__);
fprintf (inFile, "#define GccMinorVersion %d\n", __GNUC_MINOR__);
}
-#if defined(HAS_MERGE_CONSTANTS)
+# if defined(HAS_MERGE_CONSTANTS)
fprintf (inFile, "#define HasGccMergeConstants %d\n", HAS_MERGE_CONSTANTS);
-#endif
+# endif
}
#endif
@@ -1350,8 +1339,8 @@ static boolean
get_gcc(char *cmd)
{
struct stat sb;
- static char* gcc_path[] = {
-# if defined(linux) || \
+ static const char* gcc_path[] = {
+#if defined(linux) || \
defined(__NetBSD__) || \
defined(__OpenBSD__) || \
defined(__FreeBSD__) || \
@@ -1362,14 +1351,14 @@ get_gcc(char *cmd)
defined(__GNU__) || \
defined(__GLIBC__)
"/usr/bin/cc", /* for Linux PostIncDir */
-# endif
+#endif
"/usr/local/bin/gcc",
"/opt/gnu/bin/gcc",
"/usr/pkg/bin/gcc"
};
#ifdef CROSSCOMPILE
- static char* cross_cc_name[] = {
+ static const char* cross_cc_name[] = {
"cc",
"gcc"
};
@@ -1399,7 +1388,7 @@ get_gcc(char *cmd)
return FALSE;
}
-#if defined CROSSCOMPILE || !defined __UNIXOS2__
+#ifdef CROSSCOMPILE
static void
get_gcc_incdir(FILE *inFile, char* name)
{
@@ -1428,14 +1417,14 @@ get_gcc_incdir(FILE *inFile, char* name)
boolean
define_os_defaults(FILE *inFile)
{
-#if defined CROSSCOMPILE || ( !defined(WIN32) && !defined(__UNIXOS2__) )
-#ifdef CROSSCOMPILE
-#ifdef __GNUC__
+#if defined CROSSCOMPILE || !defined(WIN32)
+# ifdef CROSSCOMPILE
+# ifdef __GNUC__
if (1)
-#else
+# else
if ((sys != win32) && (sys != emx))
-#endif
-#endif
+# endif
+# endif
{
# if (defined(DEFAULT_OS_NAME) || defined(DEFAULT_OS_MAJOR_REV) || \
defined(DEFAULT_OS_MINOR_REV) || defined(DEFAULT_OS_TEENY_REV))
@@ -1444,16 +1433,16 @@ define_os_defaults(FILE *inFile)
char buf[SYS_NMLN * 5 + 1];
/* Obtain the system information. */
-#ifdef CROSSCOMPILE
+# ifdef CROSSCOMPILE
if (!CrossCompiling)
-#endif
+# endif
{
if (uname(&uts_name) < 0)
- LogFatal("Cannot invoke uname", "");
+ LogFatal("Cannot invoke uname");
else
name = &uts_name;
}
-#if defined CROSSCOMPILE && (defined linux || defined(__GLIBC__))
+# if defined CROSSCOMPILE && (defined linux || defined(__GLIBC__))
else {
strncpy(uts_name.sysname,cross_uts_sysname,SYS_NMLN);
strncpy(uts_name.release,cross_uts_release,SYS_NMLN);
@@ -1461,14 +1450,14 @@ define_os_defaults(FILE *inFile)
strncpy(uts_name.machine,cross_uts_machine,SYS_NMLN);
name = &uts_name;
}
-#endif
-# ifdef __FreeBSD__
+# endif
+# ifdef __FreeBSD__
/* Override for compiling in chroot of other OS version, such as
* in the bento build cluster.
*/
{
char *e;
- if ((e = getenv("OSREL")) != NULL &&
+ if ((e = getenv("OSREL")) != NULL &&
strlen(name->sysname) + strlen(e) + 1 < SYS_NMLN) {
strcpy(name->release, e);
strcpy(name->version, name->sysname);
@@ -1476,7 +1465,7 @@ define_os_defaults(FILE *inFile)
strcat(name->version, e);
}
}
-# endif
+# endif
# if defined DEFAULT_OS_NAME
# if defined CROSSCOMPILE
@@ -1648,10 +1637,8 @@ define_os_defaults(FILE *inFile)
char name[PATH_MAX];
if (get_gcc(name)) {
get_gcc_version (inFile,name);
-# if defined CROSSCOMPILE || !defined __UNIXOS2__
-# if defined CROSSCOMPILE
+# if defined CROSSCOMPILE
if (sys != emx)
-# endif
get_gcc_incdir(inFile,name);
# endif
}
@@ -1664,7 +1651,7 @@ define_os_defaults(FILE *inFile)
get_binary_format(inFile);
# endif
}
-#endif /* !WIN32 && !__UNIXOS2__*/
+#endif /* !WIN32 */
#if defined WIN32
# ifdef CROSSCOMPILE
else if (sys == win32 && !CrossCompiling)
@@ -1688,8 +1675,6 @@ define_os_defaults(FILE *inFile)
#endif /* WIN32 */
#ifdef CROSSCOMPILE
else if (sys == emx)
-#endif
-#if defined CROSSCOMPILE || defined __UNIXOS2__
{
fprintf(inFile, "#define DefaultOSMajorVersion 4\n");
fprintf(inFile, "#define DefaultOSMinorVersion 0\n");
@@ -1703,8 +1688,8 @@ define_os_defaults(FILE *inFile)
}
void
-cppit(char *imakefile, char *template, char *masterc,
- FILE *outfd, char *outfname)
+cppit(const char *imakefile, const char *template, const char *masterc,
+ FILE *outfd, const char *outfname)
{
FILE *inFile;
@@ -1721,8 +1706,11 @@ cppit(char *imakefile, char *template, c
fprintf(inFile, IncludeFmt, ImakeTmplSym) < 0 ||
optional_include(inFile, "IMAKE_ADMIN_MACROS", "adminmacros") ||
optional_include(inFile, "IMAKE_LOCAL_MACROS", "localmacros") ||
- fflush(inFile) ||
- fclose(inFile))
+ fflush(inFile)) {
+ fclose(inFile);
+ LogFatal("Cannot write to %s.", masterc);
+ }
+ else if (fclose(inFile))
LogFatal("Cannot write to %s.", masterc);
/*
* Fork and exec cpp
@@ -1737,8 +1725,8 @@ makeit(void)
doit(NULL, make_argv[0], make_argv);
}
-char *
-CleanCppInput(char *imakefile)
+const char *
+CleanCppInput(const char *imakefile)
{
FILE *outFile = NULL;
FILE *inFile;
@@ -1792,28 +1780,29 @@ CleanCppInput(char *imakefile)
strcmp(ptoken, "pragma") &&
strcmp(ptoken, "undef")) {
if (outFile == NULL) {
-#ifdef HAS_MKSTEMP
+#ifdef HAVE_MKSTEMP
int fd;
#endif
- tmpImakefile = Strdup(tmpImakefile);
-#ifndef HAS_MKSTEMP
- if (mktemp(tmpImakefile) == NULL ||
- (outFile = fopen(tmpImakefile, "w+")) == NULL) {
+ char *tmpImakefileName = Strdup(tmpImakefileTemplate);
+#ifndef HAVE_MKSTEMP
+ if (mktemp(tmpImakefileName) == NULL ||
+ (outFile = fopen(tmpImakefileName, "w+")) == NULL) {
LogFatal("Cannot open %s for write.",
- tmpImakefile);
+ tmpImakefileName);
}
#else
- fd=mkstemp(tmpImakefile);
+ fd=mkstemp(tmpImakefileName);
if (fd != -1)
outFile = fdopen(fd, "w");
if (outFile == NULL) {
if (fd != -1) {
- unlink(tmpImakefile); close(fd);
+ unlink(tmpImakefileName); close(fd);
}
LogFatal("Cannot open %s for write.",
- tmpImakefile);
+ tmpImakefileName);
}
#endif
+ tmpImakefile = tmpImakefileName;
}
writetmpfile(outFile, punwritten, pbuf-punwritten,
tmpImakefile);
@@ -1838,7 +1827,7 @@ CleanCppInput(char *imakefile)
}
void
-CleanCppOutput(FILE *tmpfd, char *tmpfname)
+CleanCppOutput(FILE *tmpfd, const char *tmpfname)
{
char *input;
int blankline = 0;
@@ -1960,7 +1949,7 @@ isempty(char *line)
/*ARGSUSED*/
char *
-ReadLine(FILE *tmpfd, char *tmpfname)
+ReadLine(FILE *tmpfd, const char *tmpfname)
{
static boolean initialized = FALSE;
static char *buf, *pline, *end;
@@ -1988,10 +1977,10 @@ ReadLine(FILE *tmpfd, char *tmpfname)
fseek(tmpfd, 0, 0);
#if defined(SYSV) || defined(WIN32) || defined(USE_FREOPEN)
tmpfd = freopen(tmpfname, "w+", tmpfd);
-#ifdef WIN32
+# ifdef WIN32
if (! tmpfd) /* if failed try again */
tmpfd = freopen(tmpfname, "w+", fp);
-#endif
+# endif
if (! tmpfd)
LogFatal("cannot reopen %s\n", tmpfname);
#else /* !SYSV */
@@ -1999,8 +1988,6 @@ ReadLine(FILE *tmpfd, char *tmpfname)
#endif /* !SYSV */
initialized = TRUE;
fprintf (tmpfd, "# Makefile generated by imake - do not edit!\n");
- fprintf (tmpfd, "# %s\n",
- "$Xorg: imake.c,v 1.6 2001/02/09 02:03:15 xorgcvs Exp $");
}
for (p1 = pline; p1 < end; p1++) {
@@ -2036,7 +2023,7 @@ ReadLine(FILE *tmpfd, char *tmpfname)
}
void
-writetmpfile(FILE *fd, char *buf, int cnt, char *fname)
+writetmpfile(FILE *fd, const char *buf, int cnt, const char *fname)
{
if (fwrite(buf, sizeof(char), cnt, fd) == -1)
LogFatal("Cannot write to %s.", fname);
@@ -2048,7 +2035,7 @@ Emalloc(int size)
char *p;
if ((p = malloc(size)) == NULL)
- LogFatalI("Cannot allocate %d bytes", size);
+ LogFatal("Cannot allocate %d bytes", size);
return(p);
}
@@ -2066,10 +2053,10 @@ KludgeOutputLine(char **pline)
break;
case ' ': /*May need a tab*/
default:
-#ifdef CROSSCOMPILE
+# ifdef CROSSCOMPILE
if (inline_syntax)
-#endif
-#if defined CROSSCOMPILE || defined INLINE_SYNTAX
+# endif
+# if defined CROSSCOMPILE || defined INLINE_SYNTAX
{
if (*p == '<' && p[1] == '<') { /* inline file close */
InInline--;
@@ -2077,7 +2064,7 @@ KludgeOutputLine(char **pline)
break;
}
}
-#endif
+# endif
/*
* The following cases should not be treated as beginning of
* rules:
@@ -2116,26 +2103,26 @@ KludgeOutputLine(char **pline)
quotechar = ']';
break;
case '=':
-#ifdef CROSSCOMPILE
+# ifdef CROSSCOMPILE
if (remove_cpp_leadspace)
-#endif
-#if defined CROSSCOMPILE || defined REMOVE_CPP_LEADSPACE
+# endif
+# if defined CROSSCOMPILE || defined REMOVE_CPP_LEADSPACE
{
if (!InRule && **pline == ' ') {
while (**pline == ' ')
(*pline)++;
}
}
-#endif
+# endif
goto breakfor;
-#if defined CROSSCOMPILE || defined INLINE_SYNTAX
+# if defined CROSSCOMPILE || defined INLINE_SYNTAX
case '<':
if (inline_syntax) {
if (p[1] == '<') /* inline file start */
InInline++;
}
break;
-#endif
+# endif
case ':':
if (p[1] == '=')
goto breakfor;
@@ -2159,7 +2146,7 @@ KludgeResetRule(void)
}
#endif
char *
-Strdup(char *cp)
+Strdup(const char *cp)
{
char *new = Emalloc(strlen(cp) + 1);
055_nx-X11_imake-Werror-format-security.full.patch
056_nx-X11_Werror-format-security.full.patch 056_nx-X11_Werror-format-security.full.patch
057_nx-X11_sanitize-eventmasks.full.patch 057_nx-X11_sanitize-eventmasks.full.patch
101_nxagent_set-rgb-path.full.patch 101_nxagent_set-rgb-path.full.patch
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
* be passed to the template file. * * be passed to the template file. *
* * * *
***************************************************************************/ ***************************************************************************/
/* $XFree86: xc/config/imake/imake.c,v 3.63tsi Exp $ */
/* /*
* *
Copyright (c) 1985, 1986, 1987, 1998 The Open Group Copyright (c) 1985, 1986, 1987, 1998 The Open Group
...@@ -153,23 +151,14 @@ in this Software without prior written authorization from The Open Group. ...@@ -153,23 +151,14 @@ in this Software without prior written authorization from The Open Group.
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#ifdef MONOLITH #include <stdarg.h>
# include "Xosdefs.h" #include <X11/Xfuncproto.h>
#else #include <X11/Xosdefs.h>
# include <X11/Xosdefs.h>
#endif
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#ifdef WIN32 #ifdef WIN32
# include "Xw32defs.h" # include "Xw32defs.h"
#endif #endif
#if 0
#ifndef X_NOT_POSIX
# ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
# endif
#endif
#endif
#include <sys/types.h> #include <sys/types.h>
#include <fcntl.h> #include <fcntl.h>
#ifdef X_NOT_POSIX #ifdef X_NOT_POSIX
...@@ -231,22 +220,16 @@ typedef union wait waitType; ...@@ -231,22 +220,16 @@ typedef union wait waitType;
# define WIFEXITED(w) waitCode(w) # define WIFEXITED(w) waitCode(w)
# endif # endif
#endif /* X_NOT_POSIX */ #endif /* X_NOT_POSIX */
# include <stdlib.h> #include <stdlib.h>
#if defined(macII) && !defined(__STDC__) /* stdlib.h fails to define these */
char *malloc(), *realloc();
#endif /* macII */
#include <errno.h> #include <errno.h>
#ifdef __minix_vmd #ifdef __minix_vmd
#define USE_FREOPEN 1 # define USE_FREOPEN 1
#endif #endif
#if !((defined(sun) && !defined(SVR4)) || defined(macII))
#define USE_STRERROR 1
#endif
#ifndef WIN32 #ifndef WIN32
#include <sys/utsname.h> # include <sys/utsname.h>
#else #else
#include <windows.h> # include <windows.h>
#endif #endif
#ifndef SYS_NMLN #ifndef SYS_NMLN
# ifdef _SYS_NMLN # ifdef _SYS_NMLN
...@@ -256,39 +239,22 @@ char *malloc(), *realloc(); ...@@ -256,39 +239,22 @@ char *malloc(), *realloc();
# endif # endif
#endif #endif
#if defined(linux) || defined(__GNU__) || defined(__GLIBC__) #if defined(linux) || defined(__GNU__) || defined(__GLIBC__)
#include <limits.h> # include <limits.h>
#include <stdio.h> # include <stdio.h>
#endif #endif
#ifdef __QNX__ #ifdef __QNX__
#include <unix.h> # include <unix.h>
#endif
/*
* This define of strerror is copied from (and should be identical to)
* Xos.h, which we don't want to include here for bootstrapping reasons.
*/
#ifndef USE_STRERROR
# ifndef strerror
extern char *sys_errlist[];
extern int sys_nerr;
# define strerror(n) \
(((n) >= 0 && (n) < sys_nerr) ? sys_errlist[n] : "unknown error")
# endif
#endif #endif
#if defined(__NetBSD__) /* see code clock in init() below */ #if defined(__NetBSD__) /* see code clock in init() below */
#include <sys/utsname.h> # include <sys/utsname.h>
#endif
#if !(defined(Lynx) || defined(__Lynx__) || (defined(SVR4) && !defined(sun))) && !defined (__CYGWIN__)
#define HAS_MKSTEMP
#endif #endif
typedef unsigned char boolean; typedef unsigned char boolean;
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
# include "imakemdep.h" #include "imakemdep.h"
#ifdef CROSSCOMPILE #ifdef CROSSCOMPILE
# include "imakemdep_cpp.h" # include "imakemdep_cpp.h"
#endif #endif
...@@ -305,7 +271,7 @@ int xvariables[10]; ...@@ -305,7 +271,7 @@ int xvariables[10];
#endif #endif
#ifndef PATH_MAX #ifndef PATH_MAX
#define PATH_MAX 1024 # define PATH_MAX 1024
#endif #endif
/* /*
...@@ -331,11 +297,13 @@ void KludgeOutputLine(char **), KludgeResetRule(void); ...@@ -331,11 +297,13 @@ void KludgeOutputLine(char **), KludgeResetRule(void);
# endif # endif
#endif #endif
char *cpp = NULL; const char *cpp = NULL;
char *tmpMakefile = "/tmp/Imf.XXXXXX"; const char *tmpMakefile;
char *tmpImakefile = "/tmp/IIf.XXXXXX"; const char *tmpMakefileTemplate = "/tmp/Imf.XXXXXX";
char *make_argv[ ARGUMENTS ] = { const char *tmpImakefile;
const char *tmpImakefileTemplate = "/tmp/IIf.XXXXXX";
const char *make_argv[ ARGUMENTS ] = {
#ifdef WIN32 #ifdef WIN32
"nmake" "nmake"
#else #else
...@@ -345,53 +313,53 @@ char *make_argv[ ARGUMENTS ] = { ...@@ -345,53 +313,53 @@ char *make_argv[ ARGUMENTS ] = {
int make_argindex; int make_argindex;
int cpp_argindex; int cpp_argindex;
char *Imakefile = NULL; const char *Imakefile = NULL;
char *Makefile = "Makefile"; const char *Makefile = "Makefile";
char *Template = "Imake.tmpl"; const char *Template = "Imake.tmpl";
char *ImakefileC = "Imakefile.c"; const char *ImakefileC = "Imakefile.c";
boolean haveImakefileC = FALSE; boolean haveImakefileC = FALSE;
char *cleanedImakefile = NULL; const char *cleanedImakefile = NULL;
char *program; const char *program;
char *FindImakefile(char *Imakefile); const char *FindImakefile(const char *Imakefile);
char *ReadLine(FILE *tmpfd, char *tmpfname); char *ReadLine(FILE *tmpfd, const char *tmpfname);
char *CleanCppInput(char *imakefile); const char *CleanCppInput(const char *imakefile);
char *Strdup(char *cp); char *Strdup(const char *cp);
char *Emalloc(int size); char *Emalloc(int size);
void LogFatalI(char *s, int i), LogFatal(char *x0, char *x1), void LogFatal(const char *x0, ...) _X_ATTRIBUTE_PRINTF(1, 2);
LogMsg(char *x0, char *x1); void LogMsg(const char *x0, ...) _X_ATTRIBUTE_PRINTF(1, 2);
void showit(FILE *fd); void showit(FILE *fd);
void wrapup(void); void wrapup(void);
void init(void); void init(void);
void AddMakeArg(char *arg); void AddMakeArg(const char *arg);
void AddCppArg(char *arg); void AddCppArg(const char *arg);
#ifdef CROSSCOMPILE #ifdef CROSSCOMPILE
char *CrossCompileCPP(void); char *CrossCompileCPP(void);
#endif #endif
void SetOpts(int argc, char **argv); void SetOpts(int argc, char **argv);
void CheckImakefileC(char *masterc); void CheckImakefileC(const char *masterc);
void cppit(char *imakefile, char *template, char *masterc, void cppit(const char *imakefile, const char *template, const char *masterc,
FILE *outfd, char *outfname); FILE *outfd, const char *outfname);
void makeit(void); void makeit(void);
void CleanCppOutput(FILE *tmpfd, char *tmpfname); void CleanCppOutput(FILE *tmpfd, const char *tmpfname);
boolean isempty(char *line); boolean isempty(char *line);
void writetmpfile(FILE *fd, char *buf, int cnt, char *fname); void writetmpfile(FILE *fd, const char *buf, int cnt, const char *fname);
#ifdef SIGNALRETURNSINT #ifdef SIGNALRETURNSINT
int catch(int sig); int catch(int sig);
#else #else
void catch(int sig); void catch(int sig);
#endif #endif
void showargs(char **argv); void showargs(const char **argv);
boolean optional_include(FILE *inFile, char *defsym, char *fname); boolean optional_include(FILE *inFile, const char *defsym, const char *fname);
void doit(FILE *outfd, char *cmd, char **argv); void doit(FILE *outfd, const char *cmd, const char **argv);
boolean define_os_defaults(FILE *inFile); boolean define_os_defaults(FILE *inFile);
#ifdef CROSSCOMPILE #ifdef CROSSCOMPILE
static void get_cross_compile_dir(FILE *inFile); static void get_cross_compile_dir(FILE *inFile);
#endif #endif
#ifdef CROSSCOMPILEDIR #ifdef CROSSCOMPILEDIR
char *CrossCompileDir = CROSSCOMPILEDIR; const char *CrossCompileDir = CROSSCOMPILEDIR;
#else #else
char *CrossCompileDir = ""; const char *CrossCompileDir = "";
#endif #endif
boolean CrossCompiling = FALSE; boolean CrossCompiling = FALSE;
...@@ -428,24 +396,25 @@ main(int argc, char *argv[]) ...@@ -428,24 +396,25 @@ main(int argc, char *argv[])
if ((tmpfd = fopen(tmpMakefile, "w+")) == NULL) if ((tmpfd = fopen(tmpMakefile, "w+")) == NULL)
LogFatal("Cannot create temporary file %s.", tmpMakefile); LogFatal("Cannot create temporary file %s.", tmpMakefile);
} else { } else {
#ifdef HAS_MKSTEMP #ifdef HAVE_MKSTEMP
int fd; int fd;
#endif #endif
tmpMakefile = Strdup(tmpMakefile); char *tmpMakefileName = Strdup(tmpMakefileTemplate);
#ifndef HAS_MKSTEMP #ifndef HAVE_MKSTEMP
if (mktemp(tmpMakefile) == NULL || if (mktemp(tmpMakefileName) == NULL ||
(tmpfd = fopen(tmpMakefile, "w+")) == NULL) { (tmpfd = fopen(tmpMakefileName, "w+")) == NULL) {
LogFatal("Cannot create temporary file %s.", tmpMakefile); LogFatal("Cannot create temporary file %s.", tmpMakefileName);
} }
#else #else
fd = mkstemp(tmpMakefile); fd = mkstemp(tmpMakefileName);
if (fd == -1 || (tmpfd = fdopen(fd, "w+")) == NULL) { if (fd == -1 || (tmpfd = fdopen(fd, "w+")) == NULL) {
if (fd != -1) { if (fd != -1) {
unlink(tmpMakefile); close(fd); unlink(tmpMakefileName); close(fd);
} }
LogFatal("Cannot create temporary file %s.", tmpMakefile); LogFatal("Cannot create temporary file %s.", tmpMakefileName);
} }
#endif #endif
tmpMakefile = tmpMakefileName;
} }
AddMakeArg("-f"); AddMakeArg("-f");
AddMakeArg( tmpMakefile ); AddMakeArg( tmpMakefile );
...@@ -498,7 +467,7 @@ void ...@@ -498,7 +467,7 @@ void
catch(int sig) catch(int sig)
{ {
errno = 0; errno = 0;
LogFatalI("Signal %d.", sig); LogFatal("Signal %d.", sig);
} }
/* /*
...@@ -572,21 +541,21 @@ init(void) ...@@ -572,21 +541,21 @@ init(void)
} }
void void
AddMakeArg(char *arg) AddMakeArg(const char *arg)
{ {
errno = 0; errno = 0;
if (make_argindex >= ARGUMENTS-1) if (make_argindex >= ARGUMENTS-1)
LogFatal("Out of internal storage.", ""); LogFatal("Out of internal storage.");
make_argv[ make_argindex++ ] = arg; make_argv[ make_argindex++ ] = arg;
make_argv[ make_argindex ] = NULL; make_argv[ make_argindex ] = NULL;
} }
void void
AddCppArg(char *arg) AddCppArg(const char *arg)
{ {
errno = 0; errno = 0;
if (cpp_argindex >= ARGUMENTS-1) if (cpp_argindex >= ARGUMENTS-1)
LogFatal("Out of internal storage.", ""); LogFatal("Out of internal storage.");
cpp_argv[ cpp_argindex++ ] = arg; cpp_argv[ cpp_argindex++ ] = arg;
cpp_argv[ cpp_argindex ] = NULL; cpp_argv[ cpp_argindex ] = NULL;
} }
...@@ -618,7 +587,7 @@ SetOpts(int argc, char **argv) ...@@ -618,7 +587,7 @@ SetOpts(int argc, char **argv)
else { else {
argc--, argv++; argc--, argv++;
if (! argc) if (! argc)
LogFatal("No description arg after -f flag", ""); LogFatal("No description arg after -f flag");
Imakefile = argv[0]; Imakefile = argv[0];
} }
} else if (argv[0][1] == 's') { } else if (argv[0][1] == 's') {
...@@ -628,7 +597,7 @@ SetOpts(int argc, char **argv) ...@@ -628,7 +597,7 @@ SetOpts(int argc, char **argv)
else { else {
argc--, argv++; argc--, argv++;
if (!argc) if (!argc)
LogFatal("No description arg after -s flag", ""); LogFatal("No description arg after -s flag");
Makefile = ((argv[0][0] == '-') && !argv[0][1]) ? Makefile = ((argv[0][0] == '-') && !argv[0][1]) ?
NULL : argv[0]; NULL : argv[0];
} }
...@@ -642,7 +611,7 @@ SetOpts(int argc, char **argv) ...@@ -642,7 +611,7 @@ SetOpts(int argc, char **argv)
else { else {
argc--, argv++; argc--, argv++;
if (! argc) if (! argc)
LogFatal("No description arg after -T flag", ""); LogFatal("No description arg after -T flag");
Template = argv[0]; Template = argv[0];
} }
} else if (argv[0][1] == 'C') { } else if (argv[0][1] == 'C') {
...@@ -651,7 +620,7 @@ SetOpts(int argc, char **argv) ...@@ -651,7 +620,7 @@ SetOpts(int argc, char **argv)
else { else {
argc--, argv++; argc--, argv++;
if (! argc) if (! argc)
LogFatal("No imakeCfile arg after -C flag", ""); LogFatal("No imakeCfile arg after -C flag");
ImakefileC = argv[0]; ImakefileC = argv[0];
} }
} else if (argv[0][1] == 'v') { } else if (argv[0][1] == 'v') {
...@@ -667,10 +636,10 @@ SetOpts(int argc, char **argv) ...@@ -667,10 +636,10 @@ SetOpts(int argc, char **argv)
if (!cpp) if (!cpp)
{ {
AddCppArg("-E"); AddCppArg("-E");
#ifdef __GNUC__ # ifdef __GNUC__
if (verbose) if (verbose)
AddCppArg("-v"); AddCppArg("-v");
#endif # endif
cpp = DEFAULT_CC; cpp = DEFAULT_CC;
} }
# else # else
...@@ -686,8 +655,8 @@ SetOpts(int argc, char **argv) ...@@ -686,8 +655,8 @@ SetOpts(int argc, char **argv)
AddCppArg(ImakefileC); AddCppArg(ImakefileC);
} }
char * const char *
FindImakefile(char *Imakefile) FindImakefile(const char *Imakefile)
{ {
if (Imakefile) { if (Imakefile) {
if (access(Imakefile, R_OK) < 0) if (access(Imakefile, R_OK) < 0)
...@@ -695,7 +664,7 @@ FindImakefile(char *Imakefile) ...@@ -695,7 +664,7 @@ FindImakefile(char *Imakefile)
} else { } else {
if (access("Imakefile", R_OK) < 0) { if (access("Imakefile", R_OK) < 0) {
if (access("imakefile", R_OK) < 0) if (access("imakefile", R_OK) < 0)
LogFatal("No description file.", ""); LogFatal("No description file.");
else else
Imakefile = "imakefile"; Imakefile = "imakefile";
} else } else
...@@ -704,44 +673,50 @@ FindImakefile(char *Imakefile) ...@@ -704,44 +673,50 @@ FindImakefile(char *Imakefile)
return(Imakefile); return(Imakefile);
} }
void static void _X_ATTRIBUTE_PRINTF(1, 0)
LogFatalI(char *s, int i) vLogMsg(const char *fmt, va_list args)
{ {
/*NOSTRICT*/ int error_number = errno;
LogFatal(s, (char *)(long)i);
if (error_number) {
fprintf(stderr, "%s: ", program);
fprintf(stderr, "%s\n", strerror(error_number));
}
fprintf(stderr, "%s: ", program);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
} }
void void
LogFatal(char *x0, char *x1) LogFatal(const char *fmt, ...)
{ {
static boolean entered = FALSE; static boolean entered = FALSE;
va_list args;
if (entered) if (entered)
return; return;
entered = TRUE; entered = TRUE;
LogMsg(x0, x1); va_start(args, fmt);
vLogMsg(fmt, args);
va_end(args);
fprintf(stderr, " Stop.\n"); fprintf(stderr, " Stop.\n");
wrapup(); wrapup();
exit(1); exit(1);
} }
void void
LogMsg(char *x0, char *x1) LogMsg(const char *fmt, ...)
{ {
int error_number = errno; va_list args;
if (error_number) { va_start(args, fmt);
fprintf(stderr, "%s: ", program); vLogMsg(fmt, args);
fprintf(stderr, "%s\n", strerror(error_number)); va_end(args);
}
fprintf(stderr, "%s: ", program);
fprintf(stderr, x0, x1);
fprintf(stderr, "\n");
} }
void void
showargs(char **argv) showargs(const char **argv)
{ {
for (; *argv; argv++) for (; *argv; argv++)
fprintf(stderr, "%s ", *argv); fprintf(stderr, "%s ", *argv);
...@@ -751,7 +726,7 @@ showargs(char **argv) ...@@ -751,7 +726,7 @@ showargs(char **argv)
#define ImakefileCHeader "/* imake - temporary file */" #define ImakefileCHeader "/* imake - temporary file */"
void void
CheckImakefileC(char *masterc) CheckImakefileC(const char *masterc)
{ {
char mkcbuf[1024]; char mkcbuf[1024];
FILE *inFile; FILE *inFile;
...@@ -767,7 +742,8 @@ CheckImakefileC(char *masterc) ...@@ -767,7 +742,8 @@ CheckImakefileC(char *masterc)
fclose(inFile); fclose(inFile);
LogFatal("Refuse to overwrite: %s", masterc); LogFatal("Refuse to overwrite: %s", masterc);
} }
fclose(inFile); else
fclose(inFile);
} }
} }
...@@ -778,7 +754,7 @@ CheckImakefileC(char *masterc) ...@@ -778,7 +754,7 @@ CheckImakefileC(char *masterc)
#define OverrideWarning "Warning: local file \"%s\" overrides global macros." #define OverrideWarning "Warning: local file \"%s\" overrides global macros."
boolean boolean
optional_include(FILE *inFile, char *defsym, char *fname) optional_include(FILE *inFile, const char *defsym, const char *fname)
{ {
errno = 0; errno = 0;
if (access(fname, R_OK) == 0) { if (access(fname, R_OK) == 0) {
...@@ -790,7 +766,7 @@ optional_include(FILE *inFile, char *defsym, char *fname) ...@@ -790,7 +766,7 @@ optional_include(FILE *inFile, char *defsym, char *fname)
} }
void void
doit(FILE *outfd, char *cmd, char **argv) doit(FILE *outfd, const char *cmd, const char **argv)
{ {
int pid; int pid;
waitType status; waitType status;
...@@ -805,18 +781,18 @@ doit(FILE *outfd, char *cmd, char **argv) ...@@ -805,18 +781,18 @@ doit(FILE *outfd, char *cmd, char **argv)
if (status < 0) if (status < 0)
LogFatal("Cannot spawn %s.", cmd); LogFatal("Cannot spawn %s.", cmd);
if (status > 0) if (status > 0)
LogFatalI("Exit code %d.", status); LogFatal("Exit code %d.", status);
#else #else
pid = fork(); pid = fork();
if (pid < 0) if (pid < 0)
LogFatal("Cannot fork.", ""); LogFatal("Cannot fork.");
if (pid) { /* parent... simply wait */ if (pid) { /* parent... simply wait */
while (wait(&status) > 0) { while (wait(&status) > 0) {
errno = 0; errno = 0;
if (WIFSIGNALED(status)) if (WIFSIGNALED(status))
LogFatalI("Signal %d.", waitSig(status)); LogFatal("Signal %d.", waitSig(status));
if (WIFEXITED(status) && waitCode(status)) if (WIFEXITED(status) && waitCode(status))
LogFatalI("Exit code %d.", waitCode(status)); LogFatal("Exit code %d.", waitCode(status));
} }
} }
else { /* child... dup and exec cmd */ else { /* child... dup and exec cmd */
...@@ -832,7 +808,7 @@ doit(FILE *outfd, char *cmd, char **argv) ...@@ -832,7 +808,7 @@ doit(FILE *outfd, char *cmd, char **argv)
#if !defined WIN32 #if !defined WIN32
static void static void
parse_utsname(struct utsname *name, char *fmt, char *result, char *msg) parse_utsname(struct utsname *name, const char *fmt, char *result, const char *msg)
{ {
char buf[SYS_NMLN * 5 + 1]; char buf[SYS_NMLN * 5 + 1];
char *ptr = buf; char *ptr = buf;
...@@ -892,7 +868,7 @@ parse_utsname(struct utsname *name, char *fmt, char *result, char *msg) ...@@ -892,7 +868,7 @@ parse_utsname(struct utsname *name, char *fmt, char *result, char *msg)
/* Just in case... */ /* Just in case... */
if (strlen(buf) >= sizeof(buf)) if (strlen(buf) >= sizeof(buf))
LogFatal("Buffer overflow parsing uname.", ""); LogFatal("Buffer overflow parsing uname.");
/* Parse the buffer. The sscanf() return value is rarely correct. */ /* Parse the buffer. The sscanf() return value is rarely correct. */
*result = '\0'; *result = '\0';
...@@ -978,13 +954,23 @@ const char *libc_c= ...@@ -978,13 +954,23 @@ const char *libc_c=
static void static void
get_libc_version(FILE *inFile) get_libc_version(FILE *inFile)
{ {
char aout[] = "/tmp/imakeXXXXXX"; char aout[4096], *tmpdir;
FILE *fp; FILE *fp;
const char *format = "%s -o %s -x c -"; const char *format = "%s -o %s -x c -";
char *cc; char *cc;
int len; int len;
char *command; char *command;
/* If $TMPDIR is defined and has an acceptable length,
* use that as tmp dir, else use /tmp. That fixes
* problems with /tmp mounted "noexec".
*/
if((tmpdir = getenv("TMPDIR")) != NULL && strlen(tmpdir) < (4096-13))
strcpy(aout, tmpdir);
else
strcpy(aout, "/tmp");
strcat(aout, "/imakeXXXXXX");
/* Pre-create temp file safely */ /* Pre-create temp file safely */
{ {
/* Linux + ELF has mkstemp() */ /* Linux + ELF has mkstemp() */
...@@ -1000,7 +986,8 @@ get_libc_version(FILE *inFile) ...@@ -1000,7 +986,8 @@ get_libc_version(FILE *inFile)
cc = "gcc"; cc = "gcc";
len = strlen (aout) + strlen (format) + strlen (cc); len = strlen (aout) + strlen (format) + strlen (cc);
if (len < 128) len = 128; if (len < 128) len = 128;
command = alloca (len); if((command = alloca (len)) == NULL)
abort();
if (snprintf (command , len, format, cc, aout) == len) if (snprintf (command , len, format, cc, aout) == len)
abort (); abort ();
...@@ -1015,12 +1002,16 @@ get_libc_version(FILE *inFile) ...@@ -1015,12 +1002,16 @@ get_libc_version(FILE *inFile)
abort (); abort ();
while (fgets (command, len, fp)) while (fgets (command, len, fp))
fprintf (inFile, command); fputs (command, inFile);
len = pclose (fp); len = pclose (fp);
remove (aout); remove (aout);
if (len) if (len) {
abort (); /* handwave furiously */
printf("#define DefaultLinuxCLibMajorVersion 6\n");
printf("#define DefaultLinuxCLibMinorVersion 12\n");
printf("#define DefaultLinuxCLibTeenyVersion 0\n");
}
} }
#endif #endif
...@@ -1031,14 +1022,14 @@ get_stackprotector(FILE *inFile) ...@@ -1031,14 +1022,14 @@ get_stackprotector(FILE *inFile)
FILE *fp; FILE *fp;
char *cc; char *cc;
char command[1024], buf[1024]; char command[1024], buf[1024];
cc = getenv("CC"); cc = getenv("CC");
if (cc == NULL) { if (cc == NULL) {
cc = "cc"; cc = "cc";
} }
snprintf(command, sizeof(command), "%s -v 2>&1", cc); snprintf(command, sizeof(command), "%s -v 2>&1", cc);
fp = popen(command, "r"); fp = popen(command, "r");
if (fp == NULL) if (fp == NULL)
abort(); abort();
while (fgets(buf, sizeof(buf), fp)) { while (fgets(buf, sizeof(buf), fp)) {
if (strstr(buf, "propolice") != NULL) { if (strstr(buf, "propolice") != NULL) {
...@@ -1046,11 +1037,10 @@ get_stackprotector(FILE *inFile) ...@@ -1046,11 +1037,10 @@ get_stackprotector(FILE *inFile)
break; break;
} }
} }
if (pclose(fp)) pclose(fp);
abort();
} }
#endif #endif
#if defined CROSSCOMPILE || defined linux || defined(__GLIBC__) #if defined CROSSCOMPILE || defined linux || defined(__GLIBC__)
static void static void
...@@ -1058,9 +1048,9 @@ get_distrib(FILE *inFile) ...@@ -1058,9 +1048,9 @@ get_distrib(FILE *inFile)
{ {
struct stat sb; struct stat sb;
static char* suse = "/etc/SuSE-release"; static const char* suse = "/etc/SuSE-release";
static char* redhat = "/etc/redhat-release"; static const char* redhat = "/etc/redhat-release";
static char* debian = "/etc/debian_version"; static const char* debian = "/etc/debian_version";
fprintf (inFile, "%s\n", "#define LinuxUnknown 0"); fprintf (inFile, "%s\n", "#define LinuxUnknown 0");
fprintf (inFile, "%s\n", "#define LinuxSuSE 1"); fprintf (inFile, "%s\n", "#define LinuxSuSE 1");
...@@ -1076,14 +1066,14 @@ get_distrib(FILE *inFile) ...@@ -1076,14 +1066,14 @@ get_distrib(FILE *inFile)
fprintf (inFile, "%s\n", "#define LinuxWare 11"); fprintf (inFile, "%s\n", "#define LinuxWare 11");
fprintf (inFile, "%s\n", "#define LinuxYggdrasil 12"); fprintf (inFile, "%s\n", "#define LinuxYggdrasil 12");
#ifdef CROSSCOMPILE # ifdef CROSSCOMPILE
if (CrossCompiling) { if (CrossCompiling) {
fprintf (inFile, "%s\n", fprintf (inFile, "%s\n",
"#define DefaultLinuxDistribution LinuxUnknown"); "#define DefaultLinuxDistribution LinuxUnknown");
fprintf (inFile, "%s\n", "#define DefaultLinuxDistName Unknown"); fprintf (inFile, "%s\n", "#define DefaultLinuxDistName Unknown");
return; return;
} }
#endif # endif
if (lstat (suse, &sb) == 0) { if (lstat (suse, &sb) == 0) {
fprintf (inFile, "%s\n", "#define DefaultLinuxDistribution LinuxSuSE"); fprintf (inFile, "%s\n", "#define DefaultLinuxDistribution LinuxSuSE");
fprintf (inFile, "%s\n", "#define DefaultLinuxDistName SuSE"); fprintf (inFile, "%s\n", "#define DefaultLinuxDistName SuSE");
...@@ -1116,7 +1106,7 @@ get_ld_version(FILE *inFile) ...@@ -1116,7 +1106,7 @@ get_ld_version(FILE *inFile)
int ldmajor, ldminor; int ldmajor, ldminor;
const char *ld = "ld -v"; const char *ld = "ld -v";
#ifdef CROSSCOMPILE # ifdef CROSSCOMPILE
if (CrossCompiling) { if (CrossCompiling) {
char cmd[PATH_MAX]; char cmd[PATH_MAX];
strcpy (cmd, CrossCompileDir); strcpy (cmd, CrossCompileDir);
...@@ -1124,7 +1114,7 @@ get_ld_version(FILE *inFile) ...@@ -1124,7 +1114,7 @@ get_ld_version(FILE *inFile)
strcat (cmd,ld); strcat (cmd,ld);
ldprog = popen (cmd, "r"); ldprog = popen (cmd, "r");
} else } else
#endif # endif
ldprog = popen (ld, "r"); ldprog = popen (ld, "r");
if (ldprog) { if (ldprog) {
...@@ -1192,7 +1182,7 @@ get_binary_format(FILE *inFile) ...@@ -1192,7 +1182,7 @@ get_binary_format(FILE *inFile)
* Returns: 0 if successful, -1 if not. * Returns: 0 if successful, -1 if not.
*/ */
static int static int
ask_sun_compiler_for_versions(const char *cmd, const char *path, ask_sun_compiler_for_versions(const char *cmd, const char *path,
int *cmajor, int *cminor) int *cmajor, int *cminor)
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];
...@@ -1201,7 +1191,7 @@ ask_sun_compiler_for_versions(const char *cmd, const char *path, ...@@ -1201,7 +1191,7 @@ ask_sun_compiler_for_versions(const char *cmd, const char *path,
FILE* ccproc; FILE* ccproc;
const char vflag[] = " -V 2>&1"; const char vflag[] = " -V 2>&1";
int retval = -1; int retval = -1;
int len = strlen(cmd) + sizeof(vflag); int len = strlen(cmd) + sizeof(vflag);
if (path != NULL) { if (path != NULL) {
...@@ -1229,7 +1219,7 @@ ask_sun_compiler_for_versions(const char *cmd, const char *path, ...@@ -1229,7 +1219,7 @@ ask_sun_compiler_for_versions(const char *cmd, const char *path,
} }
} }
if (retval != 0) { if (retval != 0) {
fprintf(stderr, fprintf(stderr,
"warning: could not parse version number in output of:\n" "warning: could not parse version number in output of:\n"
" %s\n", cmdtorun); " %s\n", cmdtorun);
} }
...@@ -1247,23 +1237,22 @@ get_sun_compiler_versions (FILE *inFile) ...@@ -1247,23 +1237,22 @@ get_sun_compiler_versions (FILE *inFile)
{ {
const char* sunpro_path = "/opt/SUNWspro/bin"; const char* sunpro_path = "/opt/SUNWspro/bin";
int cmajor, cminor, found = 0; int cmajor, cminor, found = 0;
struct stat sb;
/* If cross-compiling, only check CrossCompilerDir for compilers. /* If cross-compiling, only check CrossCompilerDir for compilers.
* If not cross-compiling, first check cc in users $PATH, * If not cross-compiling, first check cc in users $PATH,
* then try /opt/SUNWspro if not found in the users $PATH * then try /opt/SUNWspro if not found in the users $PATH
*/ */
#if defined CROSSCOMPILE # if defined CROSSCOMPILE
if (CrossCompiling) { if (CrossCompiling) {
if (ask_sun_compiler_for_versions("cc", CrossCompileDir, if (ask_sun_compiler_for_versions("cc", CrossCompileDir,
&cmajor, &cminor) == 0) { &cmajor, &cminor) == 0) {
found = 1; found = 1;
} }
} }
else else
#endif # endif
{ {
if (ask_sun_compiler_for_versions("cc", NULL, &cmajor, &cminor) == 0) { if (ask_sun_compiler_for_versions("cc", NULL, &cmajor, &cminor) == 0) {
found = 1; found = 1;
} else if (ask_sun_compiler_for_versions("cc", sunpro_path, } else if (ask_sun_compiler_for_versions("cc", sunpro_path,
...@@ -1282,22 +1271,22 @@ get_sun_compiler_versions (FILE *inFile) ...@@ -1282,22 +1271,22 @@ get_sun_compiler_versions (FILE *inFile)
/* Now do it again for C++ compiler (CC) */ /* Now do it again for C++ compiler (CC) */
found = 0; found = 0;
#if defined CROSSCOMPILE # if defined CROSSCOMPILE
if (CrossCompiling) { if (CrossCompiling) {
if (ask_sun_compiler_for_versions("CC", CrossCompileDir, if (ask_sun_compiler_for_versions("CC", CrossCompileDir,
&cmajor, &cminor) == 0) { &cmajor, &cminor) == 0) {
found = 1; found = 1;
} }
} }
else else
#endif # endif
{ {
if (ask_sun_compiler_for_versions("CC", NULL, &cmajor, &cminor) == 0) { if (ask_sun_compiler_for_versions("CC", NULL, &cmajor, &cminor) == 0) {
found = 1; found = 1;
} else if (ask_sun_compiler_for_versions("CC", sunpro_path, } else if (ask_sun_compiler_for_versions("CC", sunpro_path,
&cmajor, &cminor) == 0) { &cmajor, &cminor) == 0) {
found = 1; found = 1;
fprintf(inFile, fprintf(inFile,
"#define DefaultSunProCplusplusCompilerDir %s", sunpro_path); "#define DefaultSunProCplusplusCompilerDir %s", sunpro_path);
} }
} }
...@@ -1318,7 +1307,7 @@ static void ...@@ -1318,7 +1307,7 @@ static void
get_gcc_version(FILE *inFile, char *name) get_gcc_version(FILE *inFile, char *name)
{ {
fprintf (inFile, "#define HasGcc 1\n"); fprintf (inFile, "#define HasGcc 1\n");
#ifdef CROSSCOMPILE # ifdef CROSSCOMPILE
if (CrossCompiling) if (CrossCompiling)
{ {
if (gnu_c > 1) { if (gnu_c > 1) {
...@@ -1329,20 +1318,20 @@ get_gcc_version(FILE *inFile, char *name) ...@@ -1329,20 +1318,20 @@ get_gcc_version(FILE *inFile, char *name)
fprintf (inFile, "#define GccMajorVersion %d\n", gnu_c); fprintf (inFile, "#define GccMajorVersion %d\n", gnu_c);
fprintf (inFile, "#define GccMinorVersion %d\n", gnu_c_minor); fprintf (inFile, "#define GccMinorVersion %d\n", gnu_c_minor);
} else } else
#endif # endif
{ {
#if __GNUC__ > 1 # if __GNUC__ > 1
fprintf (inFile, "#define HasGcc2 1\n"); fprintf (inFile, "#define HasGcc2 1\n");
# if __GNUC__ > 2 # if __GNUC__ > 2
fprintf (inFile, "#define HasGcc3 1\n"); fprintf (inFile, "#define HasGcc3 1\n");
# endif
# endif # endif
#endif
fprintf (inFile, "#define GccMajorVersion %d\n", __GNUC__); fprintf (inFile, "#define GccMajorVersion %d\n", __GNUC__);
fprintf (inFile, "#define GccMinorVersion %d\n", __GNUC_MINOR__); fprintf (inFile, "#define GccMinorVersion %d\n", __GNUC_MINOR__);
} }
#if defined(HAS_MERGE_CONSTANTS) # if defined(HAS_MERGE_CONSTANTS)
fprintf (inFile, "#define HasGccMergeConstants %d\n", HAS_MERGE_CONSTANTS); fprintf (inFile, "#define HasGccMergeConstants %d\n", HAS_MERGE_CONSTANTS);
#endif # endif
} }
#endif #endif
...@@ -1350,8 +1339,8 @@ static boolean ...@@ -1350,8 +1339,8 @@ static boolean
get_gcc(char *cmd) get_gcc(char *cmd)
{ {
struct stat sb; struct stat sb;
static char* gcc_path[] = { static const char* gcc_path[] = {
# if defined(linux) || \ #if defined(linux) || \
defined(__NetBSD__) || \ defined(__NetBSD__) || \
defined(__OpenBSD__) || \ defined(__OpenBSD__) || \
defined(__FreeBSD__) || \ defined(__FreeBSD__) || \
...@@ -1362,14 +1351,14 @@ get_gcc(char *cmd) ...@@ -1362,14 +1351,14 @@ get_gcc(char *cmd)
defined(__GNU__) || \ defined(__GNU__) || \
defined(__GLIBC__) defined(__GLIBC__)
"/usr/bin/cc", /* for Linux PostIncDir */ "/usr/bin/cc", /* for Linux PostIncDir */
# endif #endif
"/usr/local/bin/gcc", "/usr/local/bin/gcc",
"/opt/gnu/bin/gcc", "/opt/gnu/bin/gcc",
"/usr/pkg/bin/gcc" "/usr/pkg/bin/gcc"
}; };
#ifdef CROSSCOMPILE #ifdef CROSSCOMPILE
static char* cross_cc_name[] = { static const char* cross_cc_name[] = {
"cc", "cc",
"gcc" "gcc"
}; };
...@@ -1399,7 +1388,7 @@ get_gcc(char *cmd) ...@@ -1399,7 +1388,7 @@ get_gcc(char *cmd)
return FALSE; return FALSE;
} }
#if defined CROSSCOMPILE || !defined __UNIXOS2__ #ifdef CROSSCOMPILE
static void static void
get_gcc_incdir(FILE *inFile, char* name) get_gcc_incdir(FILE *inFile, char* name)
{ {
...@@ -1428,14 +1417,14 @@ get_gcc_incdir(FILE *inFile, char* name) ...@@ -1428,14 +1417,14 @@ get_gcc_incdir(FILE *inFile, char* name)
boolean boolean
define_os_defaults(FILE *inFile) define_os_defaults(FILE *inFile)
{ {
#if defined CROSSCOMPILE || ( !defined(WIN32) && !defined(__UNIXOS2__) ) #if defined CROSSCOMPILE || !defined(WIN32)
#ifdef CROSSCOMPILE # ifdef CROSSCOMPILE
#ifdef __GNUC__ # ifdef __GNUC__
if (1) if (1)
#else # else
if ((sys != win32) && (sys != emx)) if ((sys != win32) && (sys != emx))
#endif # endif
#endif # endif
{ {
# if (defined(DEFAULT_OS_NAME) || defined(DEFAULT_OS_MAJOR_REV) || \ # if (defined(DEFAULT_OS_NAME) || defined(DEFAULT_OS_MAJOR_REV) || \
defined(DEFAULT_OS_MINOR_REV) || defined(DEFAULT_OS_TEENY_REV)) defined(DEFAULT_OS_MINOR_REV) || defined(DEFAULT_OS_TEENY_REV))
...@@ -1444,16 +1433,16 @@ define_os_defaults(FILE *inFile) ...@@ -1444,16 +1433,16 @@ define_os_defaults(FILE *inFile)
char buf[SYS_NMLN * 5 + 1]; char buf[SYS_NMLN * 5 + 1];
/* Obtain the system information. */ /* Obtain the system information. */
#ifdef CROSSCOMPILE # ifdef CROSSCOMPILE
if (!CrossCompiling) if (!CrossCompiling)
#endif # endif
{ {
if (uname(&uts_name) < 0) if (uname(&uts_name) < 0)
LogFatal("Cannot invoke uname", ""); LogFatal("Cannot invoke uname");
else else
name = &uts_name; name = &uts_name;
} }
#if defined CROSSCOMPILE && (defined linux || defined(__GLIBC__)) # if defined CROSSCOMPILE && (defined linux || defined(__GLIBC__))
else { else {
strncpy(uts_name.sysname,cross_uts_sysname,SYS_NMLN); strncpy(uts_name.sysname,cross_uts_sysname,SYS_NMLN);
strncpy(uts_name.release,cross_uts_release,SYS_NMLN); strncpy(uts_name.release,cross_uts_release,SYS_NMLN);
...@@ -1461,14 +1450,14 @@ define_os_defaults(FILE *inFile) ...@@ -1461,14 +1450,14 @@ define_os_defaults(FILE *inFile)
strncpy(uts_name.machine,cross_uts_machine,SYS_NMLN); strncpy(uts_name.machine,cross_uts_machine,SYS_NMLN);
name = &uts_name; name = &uts_name;
} }
#endif # endif
# ifdef __FreeBSD__ # ifdef __FreeBSD__
/* Override for compiling in chroot of other OS version, such as /* Override for compiling in chroot of other OS version, such as
* in the bento build cluster. * in the bento build cluster.
*/ */
{ {
char *e; char *e;
if ((e = getenv("OSREL")) != NULL && if ((e = getenv("OSREL")) != NULL &&
strlen(name->sysname) + strlen(e) + 1 < SYS_NMLN) { strlen(name->sysname) + strlen(e) + 1 < SYS_NMLN) {
strcpy(name->release, e); strcpy(name->release, e);
strcpy(name->version, name->sysname); strcpy(name->version, name->sysname);
...@@ -1476,7 +1465,7 @@ define_os_defaults(FILE *inFile) ...@@ -1476,7 +1465,7 @@ define_os_defaults(FILE *inFile)
strcat(name->version, e); strcat(name->version, e);
} }
} }
# endif # endif
# if defined DEFAULT_OS_NAME # if defined DEFAULT_OS_NAME
# if defined CROSSCOMPILE # if defined CROSSCOMPILE
...@@ -1648,10 +1637,8 @@ define_os_defaults(FILE *inFile) ...@@ -1648,10 +1637,8 @@ define_os_defaults(FILE *inFile)
char name[PATH_MAX]; char name[PATH_MAX];
if (get_gcc(name)) { if (get_gcc(name)) {
get_gcc_version (inFile,name); get_gcc_version (inFile,name);
# if defined CROSSCOMPILE || !defined __UNIXOS2__ # if defined CROSSCOMPILE
# if defined CROSSCOMPILE
if (sys != emx) if (sys != emx)
# endif
get_gcc_incdir(inFile,name); get_gcc_incdir(inFile,name);
# endif # endif
} }
...@@ -1664,7 +1651,7 @@ define_os_defaults(FILE *inFile) ...@@ -1664,7 +1651,7 @@ define_os_defaults(FILE *inFile)
get_binary_format(inFile); get_binary_format(inFile);
# endif # endif
} }
#endif /* !WIN32 && !__UNIXOS2__*/ #endif /* !WIN32 */
#if defined WIN32 #if defined WIN32
# ifdef CROSSCOMPILE # ifdef CROSSCOMPILE
else if (sys == win32 && !CrossCompiling) else if (sys == win32 && !CrossCompiling)
...@@ -1688,8 +1675,6 @@ define_os_defaults(FILE *inFile) ...@@ -1688,8 +1675,6 @@ define_os_defaults(FILE *inFile)
#endif /* WIN32 */ #endif /* WIN32 */
#ifdef CROSSCOMPILE #ifdef CROSSCOMPILE
else if (sys == emx) else if (sys == emx)
#endif
#if defined CROSSCOMPILE || defined __UNIXOS2__
{ {
fprintf(inFile, "#define DefaultOSMajorVersion 4\n"); fprintf(inFile, "#define DefaultOSMajorVersion 4\n");
fprintf(inFile, "#define DefaultOSMinorVersion 0\n"); fprintf(inFile, "#define DefaultOSMinorVersion 0\n");
...@@ -1703,8 +1688,8 @@ define_os_defaults(FILE *inFile) ...@@ -1703,8 +1688,8 @@ define_os_defaults(FILE *inFile)
} }
void void
cppit(char *imakefile, char *template, char *masterc, cppit(const char *imakefile, const char *template, const char *masterc,
FILE *outfd, char *outfname) FILE *outfd, const char *outfname)
{ {
FILE *inFile; FILE *inFile;
...@@ -1721,8 +1706,11 @@ cppit(char *imakefile, char *template, char *masterc, ...@@ -1721,8 +1706,11 @@ cppit(char *imakefile, char *template, char *masterc,
fprintf(inFile, IncludeFmt, ImakeTmplSym) < 0 || fprintf(inFile, IncludeFmt, ImakeTmplSym) < 0 ||
optional_include(inFile, "IMAKE_ADMIN_MACROS", "adminmacros") || optional_include(inFile, "IMAKE_ADMIN_MACROS", "adminmacros") ||
optional_include(inFile, "IMAKE_LOCAL_MACROS", "localmacros") || optional_include(inFile, "IMAKE_LOCAL_MACROS", "localmacros") ||
fflush(inFile) || fflush(inFile)) {
fclose(inFile)) fclose(inFile);
LogFatal("Cannot write to %s.", masterc);
}
else if (fclose(inFile))
LogFatal("Cannot write to %s.", masterc); LogFatal("Cannot write to %s.", masterc);
/* /*
* Fork and exec cpp * Fork and exec cpp
...@@ -1737,8 +1725,8 @@ makeit(void) ...@@ -1737,8 +1725,8 @@ makeit(void)
doit(NULL, make_argv[0], make_argv); doit(NULL, make_argv[0], make_argv);
} }
char * const char *
CleanCppInput(char *imakefile) CleanCppInput(const char *imakefile)
{ {
FILE *outFile = NULL; FILE *outFile = NULL;
FILE *inFile; FILE *inFile;
...@@ -1792,28 +1780,29 @@ CleanCppInput(char *imakefile) ...@@ -1792,28 +1780,29 @@ CleanCppInput(char *imakefile)
strcmp(ptoken, "pragma") && strcmp(ptoken, "pragma") &&
strcmp(ptoken, "undef")) { strcmp(ptoken, "undef")) {
if (outFile == NULL) { if (outFile == NULL) {
#ifdef HAS_MKSTEMP #ifdef HAVE_MKSTEMP
int fd; int fd;
#endif #endif
tmpImakefile = Strdup(tmpImakefile); char *tmpImakefileName = Strdup(tmpImakefileTemplate);
#ifndef HAS_MKSTEMP #ifndef HAVE_MKSTEMP
if (mktemp(tmpImakefile) == NULL || if (mktemp(tmpImakefileName) == NULL ||
(outFile = fopen(tmpImakefile, "w+")) == NULL) { (outFile = fopen(tmpImakefileName, "w+")) == NULL) {
LogFatal("Cannot open %s for write.", LogFatal("Cannot open %s for write.",
tmpImakefile); tmpImakefileName);
} }
#else #else
fd=mkstemp(tmpImakefile); fd=mkstemp(tmpImakefileName);
if (fd != -1) if (fd != -1)
outFile = fdopen(fd, "w"); outFile = fdopen(fd, "w");
if (outFile == NULL) { if (outFile == NULL) {
if (fd != -1) { if (fd != -1) {
unlink(tmpImakefile); close(fd); unlink(tmpImakefileName); close(fd);
} }
LogFatal("Cannot open %s for write.", LogFatal("Cannot open %s for write.",
tmpImakefile); tmpImakefileName);
} }
#endif #endif
tmpImakefile = tmpImakefileName;
} }
writetmpfile(outFile, punwritten, pbuf-punwritten, writetmpfile(outFile, punwritten, pbuf-punwritten,
tmpImakefile); tmpImakefile);
...@@ -1838,7 +1827,7 @@ CleanCppInput(char *imakefile) ...@@ -1838,7 +1827,7 @@ CleanCppInput(char *imakefile)
} }
void void
CleanCppOutput(FILE *tmpfd, char *tmpfname) CleanCppOutput(FILE *tmpfd, const char *tmpfname)
{ {
char *input; char *input;
int blankline = 0; int blankline = 0;
...@@ -1960,7 +1949,7 @@ isempty(char *line) ...@@ -1960,7 +1949,7 @@ isempty(char *line)
/*ARGSUSED*/ /*ARGSUSED*/
char * char *
ReadLine(FILE *tmpfd, char *tmpfname) ReadLine(FILE *tmpfd, const char *tmpfname)
{ {
static boolean initialized = FALSE; static boolean initialized = FALSE;
static char *buf, *pline, *end; static char *buf, *pline, *end;
...@@ -1988,10 +1977,10 @@ ReadLine(FILE *tmpfd, char *tmpfname) ...@@ -1988,10 +1977,10 @@ ReadLine(FILE *tmpfd, char *tmpfname)
fseek(tmpfd, 0, 0); fseek(tmpfd, 0, 0);
#if defined(SYSV) || defined(WIN32) || defined(USE_FREOPEN) #if defined(SYSV) || defined(WIN32) || defined(USE_FREOPEN)
tmpfd = freopen(tmpfname, "w+", tmpfd); tmpfd = freopen(tmpfname, "w+", tmpfd);
#ifdef WIN32 # ifdef WIN32
if (! tmpfd) /* if failed try again */ if (! tmpfd) /* if failed try again */
tmpfd = freopen(tmpfname, "w+", fp); tmpfd = freopen(tmpfname, "w+", fp);
#endif # endif
if (! tmpfd) if (! tmpfd)
LogFatal("cannot reopen %s\n", tmpfname); LogFatal("cannot reopen %s\n", tmpfname);
#else /* !SYSV */ #else /* !SYSV */
...@@ -1999,8 +1988,6 @@ ReadLine(FILE *tmpfd, char *tmpfname) ...@@ -1999,8 +1988,6 @@ ReadLine(FILE *tmpfd, char *tmpfname)
#endif /* !SYSV */ #endif /* !SYSV */
initialized = TRUE; initialized = TRUE;
fprintf (tmpfd, "# Makefile generated by imake - do not edit!\n"); fprintf (tmpfd, "# Makefile generated by imake - do not edit!\n");
fprintf (tmpfd, "# %s\n",
"$Xorg: imake.c,v 1.6 2001/02/09 02:03:15 xorgcvs Exp $");
} }
for (p1 = pline; p1 < end; p1++) { for (p1 = pline; p1 < end; p1++) {
...@@ -2036,7 +2023,7 @@ ReadLine(FILE *tmpfd, char *tmpfname) ...@@ -2036,7 +2023,7 @@ ReadLine(FILE *tmpfd, char *tmpfname)
} }
void void
writetmpfile(FILE *fd, char *buf, int cnt, char *fname) writetmpfile(FILE *fd, const char *buf, int cnt, const char *fname)
{ {
if (fwrite(buf, sizeof(char), cnt, fd) == -1) if (fwrite(buf, sizeof(char), cnt, fd) == -1)
LogFatal("Cannot write to %s.", fname); LogFatal("Cannot write to %s.", fname);
...@@ -2048,7 +2035,7 @@ Emalloc(int size) ...@@ -2048,7 +2035,7 @@ Emalloc(int size)
char *p; char *p;
if ((p = malloc(size)) == NULL) if ((p = malloc(size)) == NULL)
LogFatalI("Cannot allocate %d bytes", size); LogFatal("Cannot allocate %d bytes", size);
return(p); return(p);
} }
...@@ -2066,10 +2053,10 @@ KludgeOutputLine(char **pline) ...@@ -2066,10 +2053,10 @@ KludgeOutputLine(char **pline)
break; break;
case ' ': /*May need a tab*/ case ' ': /*May need a tab*/
default: default:
#ifdef CROSSCOMPILE # ifdef CROSSCOMPILE
if (inline_syntax) if (inline_syntax)
#endif # endif
#if defined CROSSCOMPILE || defined INLINE_SYNTAX # if defined CROSSCOMPILE || defined INLINE_SYNTAX
{ {
if (*p == '<' && p[1] == '<') { /* inline file close */ if (*p == '<' && p[1] == '<') { /* inline file close */
InInline--; InInline--;
...@@ -2077,7 +2064,7 @@ KludgeOutputLine(char **pline) ...@@ -2077,7 +2064,7 @@ KludgeOutputLine(char **pline)
break; break;
} }
} }
#endif # endif
/* /*
* The following cases should not be treated as beginning of * The following cases should not be treated as beginning of
* rules: * rules:
...@@ -2116,26 +2103,26 @@ KludgeOutputLine(char **pline) ...@@ -2116,26 +2103,26 @@ KludgeOutputLine(char **pline)
quotechar = ']'; quotechar = ']';
break; break;
case '=': case '=':
#ifdef CROSSCOMPILE # ifdef CROSSCOMPILE
if (remove_cpp_leadspace) if (remove_cpp_leadspace)
#endif # endif
#if defined CROSSCOMPILE || defined REMOVE_CPP_LEADSPACE # if defined CROSSCOMPILE || defined REMOVE_CPP_LEADSPACE
{ {
if (!InRule && **pline == ' ') { if (!InRule && **pline == ' ') {
while (**pline == ' ') while (**pline == ' ')
(*pline)++; (*pline)++;
} }
} }
#endif # endif
goto breakfor; goto breakfor;
#if defined CROSSCOMPILE || defined INLINE_SYNTAX # if defined CROSSCOMPILE || defined INLINE_SYNTAX
case '<': case '<':
if (inline_syntax) { if (inline_syntax) {
if (p[1] == '<') /* inline file start */ if (p[1] == '<') /* inline file start */
InInline++; InInline++;
} }
break; break;
#endif # endif
case ':': case ':':
if (p[1] == '=') if (p[1] == '=')
goto breakfor; goto breakfor;
...@@ -2159,7 +2146,7 @@ KludgeResetRule(void) ...@@ -2159,7 +2146,7 @@ KludgeResetRule(void)
} }
#endif #endif
char * char *
Strdup(char *cp) Strdup(const char *cp)
{ {
char *new = Emalloc(strlen(cp) + 1); char *new = Emalloc(strlen(cp) + 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment