fix PATH_MAX detection

SVN revision: 45071
This commit is contained in:
Vincent Torri 2010-01-12 22:44:25 +00:00
parent e379beec73
commit 190d1aea83
13 changed files with 55 additions and 67 deletions

View File

@ -35,6 +35,7 @@ case "$host_os" in
esac esac
AC_SUBST(release_info) AC_SUBST(release_info)
EFL_CHECK_PATH_MAX
### Default options with respect to host ### Default options with respect to host

View File

@ -0,0 +1,36 @@
dnl Check for PATH_MAX in limits.h, and define a default value if not found
dnl This is a workaround for systems not providing PATH_MAX, like GNU/Hurd
dnl EFL_CHECK_PATH_MAX([DEFAULT_VALUE_IF_NOT_FOUND])
dnl
dnl If PATH_MAX is not defined in <limits.h>, defines it
dnl to DEFAULT_VALUE_IF_NOT_FOUND if it exists, or fallback
dnl to using 4096
AC_DEFUN([EFL_CHECK_PATH_MAX],
[
default_max=m4_default([$1], "4096")
AC_LANG_PUSH([C])
AC_MSG_CHECKING([for PATH_MAX in limits.h])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[
#include <limits.h>
]],
[[
int i = PATH_MAX;
]])],
[AC_MSG_RESULT([yes])],
[
AC_DEFINE_UNQUOTED([PATH_MAX],
[${default_max}],
[default value since PATH_MAX is not defined])
AC_MSG_RESULT([no: using ${default_max}])
])
AC_LANG_POP([C])
])
dnl end of efl_path_max.m4

View File

@ -15,7 +15,6 @@ bin_PROGRAMS = embryo_cc
embryo_cc_SOURCES = \ embryo_cc_SOURCES = \
embryo_cc_amx.h \ embryo_cc_amx.h \
embryo_cc_osdefs.h \
embryo_cc_sc.h \ embryo_cc_sc.h \
embryo_cc_sc1.c \ embryo_cc_sc1.c \
embryo_cc_sc2.c \ embryo_cc_sc2.c \

View File

@ -21,8 +21,6 @@
* Version: $Id$ * Version: $Id$
*/ */
#include "embryo_cc_osdefs.h"
#ifndef EMBRYO_CC_AMX_H #ifndef EMBRYO_CC_AMX_H
#define EMBRYO_CC_AMX_H #define EMBRYO_CC_AMX_H

View File

@ -1,38 +0,0 @@
/*
* Copyright 1998-2003, ITB CompuPhase, The Netherlands.
* info@compuphase.com.
*/
#ifndef EMBRYO_CC_OSDEFS_H
# define EMBRYO_CC_OSDEFS_H
# ifdef HAVE_STDINT_H
# include <stdint.h>
# endif
/* _MAX_PATH is sometimes called differently and it may be in limits.h instead
* stdio.h.
*/
# if !defined _MAX_PATH
/* not defined, perhaps stdio.h was not included */
# include <stdio.h>
# if !defined _MAX_PATH
/* still undefined, try a common alternative name */
# if defined MAX_PATH
# define _MAX_PATH MAX_PATH
# else
/* no _MAX_PATH and no MAX_PATH, perhaps it is in limits.h */
# include <limits.h>
# if defined PATH_MAX
# define _MAX_PATH PATH_MAX
# elif defined _POSIX_PATH_MAX
# define _MAX_PATH _POSIX_PATH_MAX
# else
/* everything failed, actually we have a problem here... */
# define _MAX_PATH 4096
# endif
# endif
# endif
# endif
#endif

View File

@ -36,7 +36,6 @@
#include <stdio.h> #include <stdio.h>
#include <setjmp.h> #include <setjmp.h>
#include "embryo_cc_osdefs.h"
#include "embryo_cc_amx.h" #include "embryo_cc_amx.h"
/* Note: the "cell" and "ucell" types are defined in AMX.H */ /* Note: the "cell" and "ucell" types are defined in AMX.H */

View File

@ -48,7 +48,6 @@
# include <Evil.h> # include <Evil.h>
#endif /* HAVE_EVIL */ #endif /* HAVE_EVIL */
#include "embryo_cc_osdefs.h"
#include "embryo_cc_sc.h" #include "embryo_cc_sc.h"
#include "embryo_cc_prefix.h" #include "embryo_cc_prefix.h"
@ -121,31 +120,31 @@ static int rettype = 0; /* the type that a "return" expression should h
static int skipinput = 0; /* number of lines to skip from the first input file */ static int skipinput = 0; /* number of lines to skip from the first input file */
static int wq[wqTABSZ]; /* "while queue", internal stack for nested loops */ static int wq[wqTABSZ]; /* "while queue", internal stack for nested loops */
static int *wqptr; /* pointer to next entry */ static int *wqptr; /* pointer to next entry */
static char binfname[_MAX_PATH]; /* binary file name */ static char binfname[PATH_MAX]; /* binary file name */
int int
main(int argc, char *argv[], char *env[] __UNUSED__) main(int argc, char *argv[], char *env[] __UNUSED__)
{ {
char argv0[_MAX_PATH]; char argv0[PATH_MAX];
int i; int i;
snprintf(argv0, _MAX_PATH, "%s", argv[0]); snprintf(argv0, sizeof(argv0), "%s", argv[0]);
/* Linux stores the name of the program in argv[0], but not the path. /* Linux stores the name of the program in argv[0], but not the path.
* To adjust this, I store a string with the path in argv[0]. To do * To adjust this, I store a string with the path in argv[0]. To do
* so, I try to get the current path with getcwd(), and if that fails * so, I try to get the current path with getcwd(), and if that fails
* I search for the PWD= setting in the environment. * I search for the PWD= setting in the environment.
*/ */
if (NULL != getcwd(argv0, _MAX_PATH)) if (NULL != getcwd(argv0, PATH_MAX))
{ {
i = strlen(argv0); i = strlen(argv0);
snprintf(argv0 + i, _MAX_PATH - i, "/%s", argv[0]); snprintf(argv0 + i, sizeof(argv0) - i, "/%s", argv[0]);
} }
else else
{ {
char *pwd = getenv("PWD"); char *pwd = getenv("PWD");
if (pwd != NULL) if (pwd != NULL)
snprintf(argv0, _MAX_PATH, "%s/%s", pwd, argv[0]); snprintf(argv0, sizeof(argv0), "%s/%s", pwd, argv[0]);
} /* if */ } /* if */
argv[0] = argv0; /* set location to new first parameter */ argv[0] = argv0; /* set location to new first parameter */
@ -291,8 +290,8 @@ sc_compile(int argc, char *argv[])
{ {
int entry, i, jmpcode, fd_out; int entry, i, jmpcode, fd_out;
int retcode; int retcode;
char incfname[_MAX_PATH]; char incfname[PATH_MAX];
char reportname[_MAX_PATH]; char reportname[PATH_MAX];
FILE *binf; FILE *binf;
void *inpfmark; void *inpfmark;
char lcl_ctrlchar; char lcl_ctrlchar;
@ -312,7 +311,7 @@ sc_compile(int argc, char *argv[])
goto cleanup; goto cleanup;
/* allocate memory for fixed tables */ /* allocate memory for fixed tables */
inpfname = (char *)malloc(_MAX_PATH); inpfname = (char *)malloc(PATH_MAX);
litq = (cell *) malloc(litmax * sizeof(cell)); litq = (cell *) malloc(litmax * sizeof(cell));
if (litq == NULL) if (litq == NULL)
error(103); /* insufficient memory */ error(103); /* insufficient memory */
@ -330,7 +329,7 @@ sc_compile(int argc, char *argv[])
tmpdir = (char *)evil_tmpdir_get(); tmpdir = (char *)evil_tmpdir_get();
#endif /* ! HAVE_EVIL */ #endif /* ! HAVE_EVIL */
snprintf(outfname, _MAX_PATH, "%s/embryo_cc.asm-tmp-XXXXXX", tmpdir); snprintf(outfname, PATH_MAX, "%s/embryo_cc.asm-tmp-XXXXXX", tmpdir);
fd_out = mkstemp(outfname); fd_out = mkstemp(outfname);
if (fd_out < 0) if (fd_out < 0)
error(101, outfname); error(101, outfname);
@ -681,7 +680,7 @@ setopt(int argc, char **argv, char *iname, char *oname,
static void static void
setconfig(char *root) setconfig(char *root)
{ {
char path[_MAX_PATH]; char path[PATH_MAX];
char *ptr; char *ptr;
int len; int len;

View File

@ -38,7 +38,6 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
#include "embryo_cc_osdefs.h"
#include "embryo_cc_sc.h" #include "embryo_cc_sc.h"
#include "Embryo.h" #include "Embryo.h"
@ -154,7 +153,7 @@ plungefile(char *name, int try_currentpath, int try_includepaths)
{ {
for (i = 0; !result && (ptr = get_path(i)) != NULL; i++) for (i = 0; !result && (ptr = get_path(i)) != NULL; i++)
{ {
char path[_MAX_PATH]; char path[PATH_MAX];
strncpy(path, ptr, sizeof path); strncpy(path, ptr, sizeof path);
path[sizeof path - 1] = '\0'; /* force '\0' termination */ path[sizeof path - 1] = '\0'; /* force '\0' termination */
@ -190,7 +189,7 @@ check_empty(char *lptr)
static void static void
doinclude(void) doinclude(void)
{ {
char name[_MAX_PATH], c; char name[PATH_MAX], c;
int i, result; int i, result;
while (*lptr <= ' ' && *lptr != 0) /* skip leading whitespace */ while (*lptr <= ' ' && *lptr != 0) /* skip leading whitespace */
@ -933,7 +932,7 @@ command(void)
case tpFILE: case tpFILE:
if (skiplevel == 0) if (skiplevel == 0)
{ {
char pathname[_MAX_PATH]; char pathname[PATH_MAX];
lptr = getstring(pathname, sizeof pathname, lptr); lptr = getstring(pathname, sizeof pathname, lptr);
if (pathname[0] != '\0') if (pathname[0] != '\0')

View File

@ -31,7 +31,7 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> /* for _MAX_PATH */ #include <limits.h> /* for PATH_MAX */
#include <string.h> #include <string.h>
#include "embryo_cc_sc.h" #include "embryo_cc_sc.h"

View File

@ -32,7 +32,7 @@
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> /* for _MAX_PATH */ #include <limits.h> /* for PATH_MAX */
#include <string.h> #include <string.h>
#include "embryo_cc_sc.h" #include "embryo_cc_sc.h"

View File

@ -34,7 +34,6 @@
#include <stdlib.h> /* for macro max() */ #include <stdlib.h> /* for macro max() */
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "embryo_cc_osdefs.h"
#include "embryo_cc_sc.h" #include "embryo_cc_sc.h"
typedef cell(*OPCODE_PROC) (FILE * fbin, char *params, cell opcode); typedef cell(*OPCODE_PROC) (FILE * fbin, char *params, cell opcode);

View File

@ -27,7 +27,7 @@
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/ */
#include <stdlib.h> /* for _MAX_PATH */ #include <config.h> /* for PATH_MAX */
#include "embryo_cc_sc.h" #include "embryo_cc_sc.h"
/* global variables /* global variables
@ -45,7 +45,7 @@ constvalue libname_tab = { NULL, "", 0, 0 }; /* library table (#pragma library "
constvalue *curlibrary = NULL; /* current library */ constvalue *curlibrary = NULL; /* current library */
symbol *curfunc; /* pointer to current function */ symbol *curfunc; /* pointer to current function */
char *inpfname; /* pointer to name of the file currently read from */ char *inpfname; /* pointer to name of the file currently read from */
char outfname[_MAX_PATH]; /* output file name */ char outfname[PATH_MAX]; /* output file name */
char sc_ctrlchar = CTRL_CHAR; /* the control character (or escape character) */ char sc_ctrlchar = CTRL_CHAR; /* the control character (or escape character) */
int litidx = 0; /* index to literal table */ int litidx = 0; /* index to literal table */
int litmax = sDEF_LITMAX; /* current size of the literal table */ int litmax = sDEF_LITMAX; /* current size of the literal table */

View File

@ -234,10 +234,6 @@
RelativePath="..\..\src\bin\embryo_cc_amx.h" RelativePath="..\..\src\bin\embryo_cc_amx.h"
> >
</File> </File>
<File
RelativePath="..\..\src\bin\embryo_cc_osdefs.h"
>
</File>
<File <File
RelativePath="..\..\src\bin\embryo_cc_prefix.h" RelativePath="..\..\src\bin\embryo_cc_prefix.h"
> >