On 01/29/2013 11:34 AM, Simon Marlow wrote:
> On 25/01/13 08:55, Nathan Hüsken wrote:
>> These patches are for libraries/unix.
>> They may need some discussing, because I am not sure if this is the
>> right thing.
>>
>> 1. On android the passwd struct does not define pw_gecos. The first
>> patch therefor sets it to the empty string.
>>
>> 2. The android ndk does not define _POSIX_VDISABLE, but it defines
>> _PC_VDISABLE. The second patch defines _POSIX_VDISABLE to _PC_VIDISABLE,
>> which is (as I undestand it) what the POSIX programmer guide suggests.
>>
>> 3. The android ndk does not define telldir and seekdir. The third patch
>> removes them when compiling for android.
> 
> Thanks for the patch.  A better way to do these things is to add
> detection logic to the configure script, rather than platform-specific
> #ifdefs.
> 
> See:
> 
> http://hackage.haskell.org/trac/ghc/wiki/Commentary/Rts/Conventions#Otherportabilityconventions
> 
> 
> (the point about "avoid conditional code")
> 
> There should be plenty of examples in the configure script that you can
> copy and modify.
> 

Appended are update patches for 1 und 3.
Regards,
Nathan

>From 41479b71a582c4988c09831f95d686c4f4fa3d4e Mon Sep 17 00:00:00 2001
From: Nathan <[email protected]>
Date: Tue, 29 Jan 2013 23:32:38 +0100
Subject: [PATCH] Replace pw_gecos by empty string if not supported

---
 System/Posix/User.hsc |    4 ++++
 configure.ac          |    2 ++
 2 files changed, 6 insertions(+)

diff --git a/System/Posix/User.hsc b/System/Posix/User.hsc
index a62648d..de08314 100644
--- a/System/Posix/User.hsc
+++ b/System/Posix/User.hsc
@@ -453,7 +453,11 @@ unpackUserEntry ptr = do
    passwd <- (#peek struct passwd, pw_passwd) ptr >>= peekCAString
    uid    <- (#peek struct passwd, pw_uid)    ptr
    gid    <- (#peek struct passwd, pw_gid)    ptr
+#ifdef HAVE_NO_PASSWD_PW_GECOS
+   gecos  <- return ""  -- pw_gecos does not exist on android
+#else
    gecos  <- (#peek struct passwd, pw_gecos)  ptr >>= peekCAString
+#endif
    dir    <- (#peek struct passwd, pw_dir)    ptr >>= peekCAString
    shell  <- (#peek struct passwd, pw_shell)  ptr >>= peekCAString
    return (UserEntry name passwd uid gid gecos dir shell)
diff --git a/configure.ac b/configure.ac
index 50763a4..e1eb68c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,6 +52,8 @@ AC_CHECK_MEMBERS([struct stat.st_uatime])
 AC_CHECK_MEMBERS([struct stat.st_umtime])
 AC_CHECK_MEMBERS([struct stat.st_uctime])
 
+AC_CHECK_MEMBER([struct passwd.pw_gecos], [], [AC_DEFINE([HAVE_NO_PASSWD_PW_GECOS],[],[Ignore the pw_gecos member of passwd where it does not exist])], [[#include <pwd.h>]])
+
 # Functions for changing file timestamps
 AC_CHECK_FUNCS([utimensat futimens])
 AC_CHECK_FUNCS([lutimes futimes])
-- 
1.7.10.4

>From 4a609a4b81c89437c8d6fb62c50458752643ac48 Mon Sep 17 00:00:00 2001
From: Nathan <[email protected]>
Date: Tue, 29 Jan 2013 23:30:37 +0100
Subject: [PATCH] Online define haskell functions for telldir and seekdir if
 they are supported

---
 System/Posix/Directory.hsc            |    4 ++++
 System/Posix/Directory/ByteString.hsc |    4 ++++
 System/Posix/Directory/Common.hsc     |    8 ++++++++
 configure.ac                          |    2 ++
 4 files changed, 18 insertions(+)

diff --git a/System/Posix/Directory.hsc b/System/Posix/Directory.hsc
index 71a70ce..d0ef4c0 100644
--- a/System/Posix/Directory.hsc
+++ b/System/Posix/Directory.hsc
@@ -29,8 +29,12 @@ module System.Posix.Directory (
    rewindDirStream,   
    closeDirStream,
    DirStreamOffset,
+#ifdef HAVE_TELLDIR
    tellDirStream,
+#endif
+#ifdef HAVE_SEEKDIR
    seekDirStream,
+#endif
 
    -- * The working dirctory
    getWorkingDirectory,
diff --git a/System/Posix/Directory/ByteString.hsc b/System/Posix/Directory/ByteString.hsc
index 3ac642b..bb9100c 100644
--- a/System/Posix/Directory/ByteString.hsc
+++ b/System/Posix/Directory/ByteString.hsc
@@ -29,8 +29,12 @@ module System.Posix.Directory.ByteString (
    rewindDirStream,   
    closeDirStream,
    DirStreamOffset,
+#ifdef HAVE_TELLDIR
    tellDirStream,
+#endif
+#ifdef HAVE_SEEKDIR
    seekDirStream,
+#endif
 
    -- * The working dirctory
    getWorkingDirectory,
diff --git a/System/Posix/Directory/Common.hsc b/System/Posix/Directory/Common.hsc
index a608be3..7e2dfc6 100644
--- a/System/Posix/Directory/Common.hsc
+++ b/System/Posix/Directory/Common.hsc
@@ -22,8 +22,12 @@ module System.Posix.Directory.Common (
        DirStream(..), CDir, CDirent, DirStreamOffset(..),
        rewindDirStream,
        closeDirStream,
+#ifdef HAVE_SEEKDIR
        seekDirStream,
+#endif
+#ifdef HAVE_TELLDIR
        tellDirStream,
+#endif
        changeWorkingDirectoryFd,
   ) where
 
@@ -57,13 +61,16 @@ foreign import ccall unsafe "closedir"
 
 newtype DirStreamOffset = DirStreamOffset COff
 
+#ifdef HAVE_SEEKDIR
 seekDirStream :: DirStream -> DirStreamOffset -> IO ()
 seekDirStream (DirStream dirp) (DirStreamOffset off) =
   c_seekdir dirp off
 
 foreign import ccall unsafe "seekdir"
   c_seekdir :: Ptr CDir -> COff -> IO ()
+#endif
 
+#ifdef HAVE_TELLDIR
 tellDirStream :: DirStream -> IO DirStreamOffset
 tellDirStream (DirStream dirp) = do
   off <- c_telldir dirp
@@ -71,6 +78,7 @@ tellDirStream (DirStream dirp) = do
 
 foreign import ccall unsafe "telldir"
   c_telldir :: Ptr CDir -> IO COff
+#endif
 
 changeWorkingDirectoryFd :: Fd -> IO ()
 changeWorkingDirectoryFd (Fd fd) = 
diff --git a/configure.ac b/configure.ac
index 818303b..50763a4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,6 +33,8 @@ AC_CHECK_FUNCS([nanosleep])
 AC_CHECK_FUNCS([ptsname])
 AC_CHECK_FUNCS([setitimer])
 AC_CHECK_FUNCS([readdir_r])
+dnl not available on android so check for it
+AC_CHECK_FUNCS([telldir seekdir])
 
 AC_CHECK_MEMBERS([struct stat.st_atim])
 AC_CHECK_MEMBERS([struct stat.st_mtim])
-- 
1.7.10.4

_______________________________________________
ghc-devs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/ghc-devs

Reply via email to