Blob Blame Raw
Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 gcl (2.6.12-78) unstable; urgency=medium
 .
   * rebuild against latest compilers and tools
   * Version_2_6_13pre69
Author: Camm Maguire <camm@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: 2018-10-29

--- gcl-2.6.12.orig/h/linux.h
+++ gcl-2.6.12/h/linux.h
@@ -132,17 +132,10 @@ do { int c = 0; \
 
 #include <limits.h>
 #include <sys/stat.h>
-#define GET_FULL_PATH_SELF(a_) do {		\
-    static char q[PATH_MAX];			\
-    const char *s="/proc/self/exe";		\
-    struct stat ss;				\
-    if (stat(s,&ss))				\
-      (a_)=argv[0];				\
-    else {					\
-      if (!realpath(s,q))			\
-	error("realpath error");		\
-      (a_)=q;					\
-    }						\
+#define GET_FULL_PATH_SELF(a_) do {				\
+    static char q[PATH_MAX];					\
+    massert(which("/proc/self/exe",q) || which(argv[0],q));	\
+    (a_)=q;							\
   } while(0)
 
 
--- gcl-2.6.12.orig/o/main.c
+++ gcl-2.6.12/o/main.c
@@ -460,18 +460,49 @@ DEFUN_NEW("EQUAL-TAIL-RECURSION-CHECK",o
   RETURN1((object)(w-u));
 }
 
+static int
+mbin(const char *s,char *o) {
+
+  struct stat ss;
+
+  if (!stat(s,&ss) && (ss.st_mode&S_IFMT)==S_IFREG && !access(s,R_OK|X_OK)) {
+    massert(realpath(s,o));
+    return 1;
+  }
+
+  return 0;
+
+}
+
+static int
+which(const char *n,char *o) {
+
+  char *s;
+
+  if (strchr(n,'/'))
+    return mbin(n,o);
+
+  massert(snprintf(FN1,sizeof(FN1),"%s",getenv("PATH"))>1);
+  for (s=NULL;(s=strtok(s ? NULL : FN1,":"));) {
+
+    massert(snprintf(FN2,sizeof(FN2),"%s/%s",s,n));
+    if (mbin(FN2,o))
+      return 1;
+
+  }
+
+  return 0;
+
+}
+
+
 
 int
 main(int argc, char **argv, char **envp) {
 
-#ifdef GET_FULL_PATH_SELF
   GET_FULL_PATH_SELF(kcl_self);
-#else
-  kcl_self = argv[0];
-#endif
-
   *argv=kcl_self;
-  
+
 #ifdef CAN_UNRANDOMIZE_SBRK
 #include <stdio.h>
 #include <stdlib.h>