Description: Fix compile errors on hurd-i386.
The following are the issues I found (and how I fixed them), and
other changes needed:
* __MACH__ identifies the Mach microkernel which both Mac OSX and
Hurd use (well, different versions/forks of it), so do not use it
for identifying Mac OSX.
* Introduce new NEKO_HURD and OS_HURD defines, making them being
considered as POSIX (as Hurd is).
* realpath: we don't have PATH_MAX on Hurd (since we have no limits
on paths); given that glibc's realpath has, since years, the POSIX
2008 behaviour (i.e. if called with NULL as second argument,
return a newly allocated buffer), then make use of it in
glibc-based OSes.
* /proc/self is a Linux-specific feature, so limit its usage (in two
places) to just Linux, providing a fallback for the remaining
cases (which include Hurd).
Author: Pino Toscano <toscano.pino@tiscali.it>
Origin: debian-hurd@lists.debian.org
Bug-Debian: http://bugs.debian.org/626260
Forwarded: Nicolas Cannasse <ncannasse@motion-twin.com>
Last-Update: 2011-05-15
Index: neko/vm/neko.h
===================================================================
--- neko.orig/vm/neko.h 2011-05-15 19:13:09.000000000 +0200
+++ neko/vm/neko.h 2011-05-15 19:13:17.000000000 +0200
@@ -22,7 +22,7 @@
# define NEKO_WINDOWS
#endif
-#if defined(__APPLE__) || defined(__MACH__) || defined(macintosh)
+#if defined(__APPLE__) || defined(macintosh)
# define NEKO_MAC
#endif
@@ -38,6 +38,10 @@
# define NEKO_BSD
#endif
+#if defined(__GNU__)
+# define NEKO_HURD
+#endif
+
// COMPILER/PROCESSOR FLAGS
#if defined(__GNUC__)
# define NEKO_GCC
@@ -63,7 +67,7 @@
# define NEKO_64BITS
#endif
-#if defined(NEKO_LINUX) || defined(NEKO_MAC) || defined(NEKO_BSD) || defined(NEKO_GNUKBSD)
+#if defined(NEKO_LINUX) || defined(NEKO_MAC) || defined(NEKO_BSD) || defined(NEKO_GNUKBSD) || defined(NEKO_HURD)
# define NEKO_POSIX
#endif
Index: neko/libs/std/sys.c
===================================================================
--- neko.orig/libs/std/sys.c 2011-05-15 19:13:05.000000000 +0200
+++ neko/libs/std/sys.c 2011-05-15 19:13:17.000000000 +0200
@@ -194,6 +194,8 @@
return alloc_string("BSD");
#elif defined(NEKO_MAC)
return alloc_string("Mac");
+#elif defined(NEKO_HURD)
+ return alloc_string("GNU/Hurd");
#else
#error Unknow system string
#endif
@@ -504,6 +506,14 @@
if( GetFullPathName(val_string(path),MAX_PATH+1,buf,NULL) == 0 )
neko_error();
return alloc_string(buf);
+#elif defined(__GLIBC__)
+ val_check(path,string);
+ char *buf = realpath(val_string(path), NULL);
+ if( buf == NULL )
+ neko_error();
+ value ret = alloc_string(buf);
+ free(buf);
+ return ret;
#else
char buf[PATH_MAX];
val_check(path,string);
@@ -529,7 +539,7 @@
if( _NSGetExecutablePath(path, &path_len) )
neko_error();
return alloc_string(path);
-#else
+#elif defined(NEKO_LINUX)
const char *p = getenv("_");
if( p != NULL )
return alloc_string(p);
@@ -541,6 +551,11 @@
path[length] = '\0';
return alloc_string(path);
}
+#else
+ const char *p = getenv("_");
+ if( p != NULL )
+ return alloc_string(p);
+ neko_error();
#endif
}
Index: neko/libs/common/osdef.h
===================================================================
--- neko.orig/libs/common/osdef.h 2011-05-15 19:03:14.000000000 +0200
+++ neko/libs/common/osdef.h 2011-05-15 19:13:17.000000000 +0200
@@ -25,7 +25,7 @@
# define OS_WINDOWS
#endif
-#if defined(__APPLE__) || defined(__MACH__) || defined(macintosh)
+#if defined(__APPLE__) || defined(macintosh)
# define OS_MAC
#endif
@@ -37,7 +37,11 @@
# define OS_BSD
#endif
-#if defined(NEKO_LINUX) || defined(NEKO_MAC) || defined(NEKO_BSD) || defined(NEKO_GNUKBSD)
+#if defined(__GNU__)
+# define OS_HURD
+#endif
+
+#if defined(NEKO_LINUX) || defined(NEKO_MAC) || defined(NEKO_BSD) || defined(NEKO_GNUKBSD) || defined(NEKO_HURD)
# define OS_POSIX
#endif
Index: neko/vm/main.c
===================================================================
--- neko.orig/vm/main.c 2011-05-15 19:09:30.000000000 +0200
+++ neko/vm/main.c 2011-05-15 19:13:17.000000000 +0200
@@ -74,7 +74,7 @@
}
path[length] = '\0';
return path;
-#else
+#elif defined(NEKO_LINUX)
static char path[1024];
int length = readlink("/proc/self/exe", path, sizeof(path));
if( length < 0 || length >= 1024 ) {
@@ -85,6 +85,8 @@
}
path[length] = '\0';
return path;
+#else
+ return getenv("_");
#endif
}