fix PATH_MAX detection
authorcaro <caro@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 12 Jan 2010 22:44:25 +0000 (22:44 +0000)
committercaro <caro@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 12 Jan 2010 22:44:25 +0000 (22:44 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/embryo@45071 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

13 files changed:
configure.ac
m4/efl_path_max.m4 [new file with mode: 0644]
src/bin/Makefile.am
src/bin/embryo_cc_amx.h
src/bin/embryo_cc_osdefs.h
src/bin/embryo_cc_sc.h
src/bin/embryo_cc_sc1.c
src/bin/embryo_cc_sc2.c
src/bin/embryo_cc_sc3.c
src/bin/embryo_cc_sc4.c
src/bin/embryo_cc_sc6.c
src/bin/embryo_cc_scvars.c
win32/vs9/embryo_cc.vcproj

index c32a537..b7d5d11 100644 (file)
@@ -35,6 +35,7 @@ case "$host_os" in
 esac
 AC_SUBST(release_info)
 
+EFL_CHECK_PATH_MAX
 
 ### Default options with respect to host
 
diff --git a/m4/efl_path_max.m4 b/m4/efl_path_max.m4
new file mode 100644 (file)
index 0000000..f57bfd2
--- /dev/null
@@ -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
index 93143c6..d918be5 100644 (file)
@@ -15,7 +15,6 @@ bin_PROGRAMS = embryo_cc
 
 embryo_cc_SOURCES = \
 embryo_cc_amx.h \
-embryo_cc_osdefs.h \
 embryo_cc_sc.h \
 embryo_cc_sc1.c \
 embryo_cc_sc2.c \
index dbf612f..b775391 100644 (file)
@@ -21,8 +21,6 @@
  *  Version: $Id$
  */
 
-#include "embryo_cc_osdefs.h"
-
 #ifndef EMBRYO_CC_AMX_H
 #define EMBRYO_CC_AMX_H
 
index 3e21814..e69de29 100644 (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
index afa8df0..ea4c9a6 100644 (file)
@@ -36,7 +36,6 @@
 #include <stdio.h>
 #include <setjmp.h>
 
-#include "embryo_cc_osdefs.h"
 #include "embryo_cc_amx.h"
 
 /* Note: the "cell" and "ucell" types are defined in AMX.H */
index ef6e4f0..96760fb 100644 (file)
@@ -48,7 +48,6 @@
 # include <Evil.h>
 #endif /* HAVE_EVIL */
 
-#include "embryo_cc_osdefs.h"
 #include "embryo_cc_sc.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          wq[wqTABSZ];       /* "while queue", internal stack for nested loops */
 static int         *wqptr;     /* pointer to next entry */
-static char         binfname[_MAX_PATH];       /* binary file name */
+static char         binfname[PATH_MAX];        /* binary file name */
 
 int
 main(int argc, char *argv[], char *env[] __UNUSED__)
 {
-   char                argv0[_MAX_PATH];
+   char                argv0[PATH_MAX];
    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.
     * 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
     * I search for the PWD= setting in the environment.
     */
-   if (NULL != getcwd(argv0, _MAX_PATH))
+   if (NULL != getcwd(argv0, PATH_MAX))
      {
        i = strlen(argv0);
-       snprintf(argv0 + i, _MAX_PATH - i, "/%s", argv[0]);
+       snprintf(argv0 + i, sizeof(argv0) - i, "/%s", argv[0]);
      }
    else
      {
        char               *pwd = getenv("PWD");
 
        if (pwd != NULL)
-          snprintf(argv0, _MAX_PATH, "%s/%s", pwd, argv[0]);
+          snprintf(argv0, sizeof(argv0), "%s/%s", pwd, argv[0]);
      }                         /* if */
    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                 retcode;
-   char                incfname[_MAX_PATH];
-   char                reportname[_MAX_PATH];
+   char                incfname[PATH_MAX];
+   char                reportname[PATH_MAX];
    FILE               *binf;
    void               *inpfmark;
    char                lcl_ctrlchar;
@@ -312,7 +311,7 @@ sc_compile(int argc, char *argv[])
       goto cleanup;
 
    /* allocate memory for fixed tables */
-   inpfname = (char *)malloc(_MAX_PATH);
+   inpfname = (char *)malloc(PATH_MAX);
    litq = (cell *) malloc(litmax * sizeof(cell));
    if (litq == NULL)
       error(103);              /* insufficient memory */
@@ -330,7 +329,7 @@ sc_compile(int argc, char *argv[])
    tmpdir = (char *)evil_tmpdir_get();
 #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);
    if (fd_out < 0)
      error(101, outfname);
@@ -681,7 +680,7 @@ setopt(int argc, char **argv, char *iname, char *oname,
 static void
 setconfig(char *root)
 {
-   char                path[_MAX_PATH];
+   char                path[PATH_MAX];
    char               *ptr;
    int                 len;
 
index be3bc5d..de04fe0 100644 (file)
@@ -38,7 +38,6 @@
 #include <string.h>
 #include <ctype.h>
 #include <math.h>
-#include "embryo_cc_osdefs.h"
 #include "embryo_cc_sc.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++)
          {
-            char                path[_MAX_PATH];
+            char                path[PATH_MAX];
 
             strncpy(path, ptr, sizeof path);
             path[sizeof path - 1] = '\0';      /* force '\0' termination */
@@ -190,7 +189,7 @@ check_empty(char *lptr)
 static void
 doinclude(void)
 {
-   char                name[_MAX_PATH], c;
+   char                name[PATH_MAX], c;
    int                 i, result;
 
    while (*lptr <= ' ' && *lptr != 0)  /* skip leading whitespace */
@@ -933,7 +932,7 @@ command(void)
      case tpFILE:
        if (skiplevel == 0)
          {
-            char                pathname[_MAX_PATH];
+            char                pathname[PATH_MAX];
 
             lptr = getstring(pathname, sizeof pathname, lptr);
             if (pathname[0] != '\0')
index ca1b466..9502784 100644 (file)
@@ -31,7 +31,7 @@
 
 #include <assert.h>
 #include <stdio.h>
-#include <stdlib.h>            /* for _MAX_PATH */
+#include <limits.h>            /* for PATH_MAX */
 #include <string.h>
 
 #include "embryo_cc_sc.h"
index 600112f..858f8d5 100644 (file)
@@ -32,7 +32,7 @@
 #include <assert.h>
 #include <ctype.h>
 #include <stdio.h>
-#include <stdlib.h>            /* for _MAX_PATH */
+#include <limits.h>            /* for PATH_MAX */
 #include <string.h>
 
 #include "embryo_cc_sc.h"
index 3c2fca2..7c16a98 100644 (file)
@@ -34,7 +34,6 @@
 #include <stdlib.h>            /* for macro max() */
 #include <string.h>
 #include <ctype.h>
-#include "embryo_cc_osdefs.h"
 #include "embryo_cc_sc.h"
 
 typedef             cell(*OPCODE_PROC) (FILE * fbin, char *params, cell opcode);
index 0fa802a..163bbc9 100644 (file)
@@ -27,7 +27,7 @@
  * 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"
 
 /*  global variables
@@ -45,7 +45,7 @@ constvalue libname_tab = { NULL, "", 0, 0 };  /* library table (#pragma library "
 constvalue *curlibrary = NULL; /* current library */
 symbol  *curfunc;      /* pointer to current function */
 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) */
 int      litidx = 0;   /* index to literal table */
 int      litmax = sDEF_LITMAX; /* current size of the literal table */
index 6aa5ea6..47dd254 100644 (file)
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\..\src\bin\embryo_cc_osdefs.h"\r
-                               >\r
-                       </File>\r
-                       <File\r
                                RelativePath="..\..\src\bin\embryo_cc_prefix.h"\r
                                >\r
                        </File>\r