Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / gnulib-lib / progreloc.c
index 45d6cf1..1d2b4b3 100644 (file)
@@ -1,5 +1,5 @@
 /* Provide relocatable programs.
-   Copyright (C) 2003-2013 Free Software Foundation, Inc.
+   Copyright (C) 2003-2015 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software: you can redistribute it and/or modify
 # include <windows.h>
 #endif
 
+#ifdef __EMX__
+# define INCL_DOS
+# include <os2.h>
+#endif
+
 #include "relocatable.h"
 
 #ifdef NO_XMALLOC
@@ -89,11 +94,6 @@ extern char * canonicalize_file_name (const char *name);
 # define FILE_SYSTEM_PREFIX_LEN(P) 0
 #endif
 
-/* The results of open() in this file are not used with fchdir,
-   therefore save some unnecessary work in fchdir.c.  */
-#undef open
-#undef close
-
 /* Use the system functions, not the gnulib overrides in this file.  */
 #undef sprintf
 
@@ -162,6 +162,23 @@ find_executable (const char *argv0)
     /* Shouldn't happen.  */
     return NULL;
   return xstrdup (location);
+#elif defined __EMX__
+  PPIB ppib;
+  char location[CCHMAXPATH];
+
+  /* See http://cyberkinetica.homeunix.net/os2tk45/cp1/619_L2H_DosGetInfoBlocksSynt.html
+     for specification of DosGetInfoBlocks().  */
+  if (DosGetInfoBlocks (NULL, &ppib))
+    return NULL;
+
+  /* See http://cyberkinetica.homeunix.net/os2tk45/cp1/1247_L2H_DosQueryModuleNameSy.html
+     for specification of DosQueryModuleName().  */
+  if (DosQueryModuleName (ppib->pib_hmte, sizeof (location), location))
+    return NULL;
+
+  _fnslashify (location);
+
+  return xstrdup (location);
 #else /* Unix */
 # ifdef __linux__
   /* The executable is accessible as /proc/<pid>/exe.  In newer Linux