win32 portability fixes

This commit is contained in:
Bill Currie 2001-11-15 03:54:35 +00:00
parent 267e51eaaf
commit 40d47e91cb
7 changed files with 66 additions and 28 deletions

View file

@ -39,7 +39,7 @@ AC_CHECK_LIB(z, gztell,,
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(sys/types.h sys/wait.h unistd.h)
AC_CHECK_HEADERS(process.h string.h strings.h sys/types.h sys/wait.h unistd.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_ARG_ENABLE(profile,
@ -60,6 +60,8 @@ AC_DEFINE_UNQUOTED(PATH_SEPARATOR, '/')
dnl Checks for library functions.
AC_CHECK_FUNCS(snprintf _snprintf vsnprintf _vsnprintf)
AC_MSG_CHECKING(for timeGetTime in -lwinmm)
save_LIBS="$LIBS"
LIBS="$LIBS -lwinmm"

View file

@ -17,6 +17,9 @@
See file, 'COPYING', for details.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "cmdlib.h"
#include <stdio.h>
@ -25,6 +28,16 @@
#include "QF/pr_comp.h"
#include "QF/pr_debug.h"
/* These may be underscored... */
#if defined(HAVE__SNPRINTF)
# undef snprintf
# define snprintf _snprintf
#endif
#if defined(HAVE__VSNPRINTF)
# undef vsnprintf
# define vsnprintf _vsnprintf
#endif
/*
TODO:
o "stopped at 10 errors"

View file

@ -301,7 +301,7 @@ new_label_name (void)
char *lname = malloc (len);
if (!lname)
Sys_Error ("new_label_expr: Memory Allocation Failure\n");
sprintf (lname, "$%s_%d", fname, lnum);
snprintf (lname, len, "$%s_%d", fname, lnum);
return lname;
}

View file

@ -200,7 +200,8 @@ static char *posixly_correct;
# if HAVE_STRING_H
# include <string.h>
# else
# endif
# if HAVE_STRINGS_H
# include <strings.h>
# endif

View file

@ -131,17 +131,17 @@ PR_GetDef (type_t *type, const char *name, def_t *scope, int *allocate)
if (type->type == ev_vector) {
def_t *d;
sprintf (element, "%s_x", name);
snprintf (element, sizeof (element), "%s_x", name);
d = PR_GetDef (&type_float, element, scope, allocate);
d->used = 1;
d->parent = def;
sprintf (element, "%s_y", name);
snprintf (element, sizeof (element), "%s_y", name);
d = PR_GetDef (&type_float, element, scope, allocate);
d->used = 1;
d->parent = def;
sprintf (element, "%s_z", name);
snprintf (element, sizeof (element), "%s_z", name);
d = PR_GetDef (&type_float, element, scope, allocate);
d->used = 1;
d->parent = def;
@ -155,17 +155,17 @@ PR_GetDef (type_t *type, const char *name, def_t *scope, int *allocate)
if (type->aux_type->type == ev_vector) {
def_t *d;
sprintf (element, "%s_x", name);
snprintf (element, sizeof (element), "%s_x", name);
d = PR_GetDef (&type_floatfield, element, scope, allocate);
d->used = 1; // always `used'
d->parent = def;
sprintf (element, "%s_y", name);
snprintf (element, sizeof (element), "%s_y", name);
d = PR_GetDef (&type_floatfield, element, scope, allocate);
d->used = 1; // always `used'
d->parent = def;
sprintf (element, "%s_z", name);
snprintf (element, sizeof (element), "%s_z", name);
d = PR_GetDef (&type_floatfield, element, scope, allocate);
d->used = 1; // always `used'
d->parent = def;

View file

@ -48,7 +48,7 @@ float_imm_get_key (void *_def, void *unused)
{
def_t *def = (def_t*)_def;
static char rep[20];
sprintf (rep, "\001float:%08X\001", G_INT(def->ofs));
snprintf (rep, sizeof (rep), "\001float:%08X\001", G_INT(def->ofs));
return rep;
}
@ -57,7 +57,7 @@ vector_imm_get_key (void *_def, void *unused)
{
def_t *def = (def_t*)_def;
static char rep[60];
sprintf (rep, "\001vector:%08X\001%08X\001%08X\001",
snprintf (rep, sizeof (rep), "\001vector:%08X\001%08X\001%08X\001",
G_INT(def->ofs), G_INT(def->ofs+1), G_INT(def->ofs+2));
return rep;
}
@ -67,7 +67,8 @@ quaternion_imm_get_key (void *_def, void *unused)
{
def_t *def = (def_t*)_def;
static char rep[60];
sprintf (rep, "\001quaternion:%08X\001%08X\001%08X\001%08X\001",
snprintf (rep, sizeof (rep),
"\001quaternion:%08X\001%08X\001%08X\001%08X\001",
G_INT(def->ofs), G_INT(def->ofs+1),
G_INT(def->ofs+2), G_INT(def->ofs+3));
return rep;
@ -79,7 +80,7 @@ int_imm_get_key (void *_def, void *_str)
def_t *def = (def_t*)_def;
static char rep[60];
char *str = (char*)_str;
sprintf (rep, "\001%s:%08X\001", str, G_INT(def->ofs));
snprintf (rep, sizeof (rep), "\001%s:%08X\001", str, G_INT(def->ofs));
return rep;
}
@ -112,29 +113,29 @@ PR_ReuseConstant (expr_t *expr, def_t *def)
}
switch (e.type) {
case ex_entity:
sprintf (rep, "\001entity:%08X\001", e.e.integer_val);
snprintf (rep, sizeof (rep), "\001entity:%08X\001", e.e.integer_val);
tab = entity_imm_defs;
type = &type_entity;
break;
case ex_field:
sprintf (rep, "\001field:%08X\001", e.e.integer_val);
snprintf (rep, sizeof (rep), "\001field:%08X\001", e.e.integer_val);
tab = field_imm_defs;
type = &type_field;
break;
case ex_func:
sprintf (rep, "\001func:%08X\001", e.e.integer_val);
snprintf (rep, sizeof (rep), "\001func:%08X\001", e.e.integer_val);
tab = func_imm_defs;
type = &type_function;
break;
case ex_pointer:
sprintf (rep, "\001pointer:%08X\001", e.e.integer_val);
snprintf (rep, sizeof (rep), "\001pointer:%08X\001", e.e.integer_val);
tab = pointer_imm_defs;
type = &type_pointer;
break;
case ex_integer:
case ex_uinteger:
if (!def || def->type != &type_float) {
sprintf (rep, "\001integer:%08X\001", e.e.integer_val);
snprintf (rep, sizeof (rep), "\001integer:%08X\001", e.e.integer_val);
tab = integer_imm_defs;
if (e.type == ex_uinteger)
type = &type_uinteger;
@ -147,7 +148,7 @@ PR_ReuseConstant (expr_t *expr, def_t *def)
else
e.e.float_val = e.e.integer_val;
case ex_float:
sprintf (rep, "\001float:%08X\001", e.e.integer_val);
snprintf (rep, sizeof (rep), "\001float:%08X\001", e.e.integer_val);
tab = float_imm_defs;
type = &type_float;
break;
@ -157,7 +158,7 @@ PR_ReuseConstant (expr_t *expr, def_t *def)
type = &type_string;
break;
case ex_vector:
sprintf (rep, "\001vector:%08X\001%08X\001%08X\001",
snprintf (rep, sizeof (rep), "\001vector:%08X\001%08X\001%08X\001",
*(int*)&e.e.vector_val[0],
*(int*)&e.e.vector_val[1],
*(int*)&e.e.vector_val[2]);
@ -165,7 +166,7 @@ PR_ReuseConstant (expr_t *expr, def_t *def)
type = &type_vector;
break;
case ex_quaternion:
sprintf (rep, "\001quaternion:%08X\001%08X\001%08X\001%08X\001",
snprintf (rep, sizeof (rep), "\001quaternion:%08X\001%08X\001%08X\001%08X\001",
*(int*)&e.e.quaternion_val[0],
*(int*)&e.e.quaternion_val[1],
*(int*)&e.e.quaternion_val[2],

View file

@ -41,6 +41,9 @@
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_PROCESS_H
# include <process.h>
#endif
#include <stdio.h>
@ -136,7 +139,7 @@ WriteFiles (void)
int i;
char filename[1024];
sprintf (filename, "%s%cfiles.dat", sourcedir, PATH_SEPARATOR);
snprintf (filename, sizeof (filename), "%s%cfiles.dat", sourcedir, PATH_SEPARATOR);
f = fopen (filename, "w");
if (!f)
Error ("Couldn't open %s", filename);
@ -899,7 +902,7 @@ main (int argc, char **argv)
InitData ();
sprintf (filename, "%s/progs.src", sourcedir);
snprintf (filename, sizeof (filename), "%s/progs.src", sourcedir);
LoadFile (filename, (void *) &src);
if (!(src = Parse (src)))
@ -932,11 +935,13 @@ main (int argc, char **argv)
// compile all the files
while ((src = Parse (src))) {
#ifdef USE_CPP
# ifndef _WIN32
pid_t pid;
int tempfd;
# endif
char *temp1;
char *temp2 = strrchr (argv[0], PATH_SEPARATOR);
char tempname[1024];
int tempfd;
#endif
int error;
@ -947,7 +952,7 @@ main (int argc, char **argv)
//extern int yydebug;
//yydebug = 1;
sprintf (filename, "%s%c%s", sourcedir, PATH_SEPARATOR, com_token);
snprintf (filename, sizeof (filename), "%s%c%s", sourcedir, PATH_SEPARATOR, com_token);
if (options.verbosity >= 2)
printf ("compiling %s\n", filename);
@ -963,13 +968,29 @@ main (int argc, char **argv)
snprintf (tempname, sizeof (tempname), "%s%c%sXXXXXX", temp1,
PATH_SEPARATOR, temp2 ? temp2 + 1 : argv[0]);
tempfd = mkstemp (tempname);
# ifdef _WIN32
mktemp (tempname);
yyin = fopen (tempname, "wt");
fclose (yyin);
{
int status = spawnvp (_P_WAIT, "cpp", cpp_argv);
if (status) {
fprintf (stderr, "cpp returned error code %d", status);
exit (1);
}
}
yyin = fopen (tempname, "rt");
# else
tempfd = mkstemp (tempname);
if ((pid = fork ()) == -1) {
perror ("fork");
return 1;
}
if (!pid) { // we're a child, check for abuse
cpp_argv[cpp_argc++] = "-o";
cpp_argv[cpp_argc++] = tempname;
@ -1004,8 +1025,8 @@ main (int argc, char **argv)
exit (1);
}
}
yyin = fdopen (tempfd, "r+t");
# endif
} else {
yyin = fopen (filename, "rt");
}