From 3939a8bf93e27d8151aa1d92bf3ce10bbbc96a72 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date: Sun, 15 Sep 2024 15:57:52 +0200
Subject: [PATCH] GNU/Hurd: Add getExecutablePath support

GNU/Hurd exposes it as /proc/self/exe just like on Linux.
---
 .../src/GHC/Internal/System/Environment/ExecutablePath.hsc  | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Index: ghc-9.10.3/libraries/ghc-internal/src/GHC/Internal/System/Environment/ExecutablePath.hsc
===================================================================
--- ghc-9.10.3.orig/libraries/ghc-internal/src/GHC/Internal/System/Environment/ExecutablePath.hsc
+++ ghc-9.10.3/libraries/ghc-internal/src/GHC/Internal/System/Environment/ExecutablePath.hsc
@@ -51,7 +51,7 @@ import GHC.Internal.Foreign.Ptr
 import GHC.Internal.Foreign.Storable
 import GHC.Internal.System.IO.Error (isDoesNotExistError)
 import GHC.Internal.System.Posix.Internals
-#elif defined(linux_HOST_OS)
+#elif defined(linux_HOST_OS) || defined(gnu_HOST_OS)
 import GHC.Internal.Data.Functor
 import GHC.Internal.Data.List (isSuffixOf)
 import GHC.Internal.Foreign.C.Types
@@ -200,9 +200,9 @@ executablePath = Just (fmap Just getExec
       | otherwise             = throw e
 
 --------------------------------------------------------------------------------
--- Linux / Solaris
+-- Linux / Solaris / Hurd
 
-#elif defined(linux_HOST_OS) || defined(solaris2_HOST_OS)
+#elif defined(linux_HOST_OS) || defined(solaris2_HOST_OS) || defined(gnu_HOST_OS)
 
 foreign import ccall unsafe "readlink"
     c_readlink :: CString -> CString -> CSize -> IO CInt
@@ -219,7 +219,7 @@ readSymbolicLink file =
                    c_readlink s buf 4096
             peekFilePathLen (buf,fromIntegral len)
 
-#  if defined(linux_HOST_OS)
+#  if defined(linux_HOST_OS) || defined(gnu_HOST_OS)
 getExecutablePath = readSymbolicLink $ "/proc/self/exe"
 
 executablePath = Just (check <$> getExecutablePath) where
