]> gitweb.factorcode.org Git - factor.git/commitdiff
Revert "io.directories.unix: switch to readdir(3) since readdir_r(3) is deprecated"
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 12 Feb 2022 03:53:57 +0000 (19:53 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 12 Feb 2022 03:53:57 +0000 (19:53 -0800)
This reverts commit e0531ea85337e9d1e5af26568436ea23bdaf8e34.

basis/io/directories/unix/unix.factor

index 4da0b85d15c6f6a8e5a2323a88be2ec8646b557a..32b9df10b40f1b03cacbb870b251481e43ee0862 100644 (file)
@@ -39,7 +39,7 @@ M: unix copy-file
     [ call-next-method ]
     [ [ file-permissions ] dip swap set-file-permissions ] 2bi ;
 
-: with-unix-directory ( ..a path quot: ( ..a DIR* -- ..b ) -- ..b )
+: with-unix-directory ( path quot -- )
     dupd '[ _ _
         [ opendir dup [ throw-errno ] unless ] dip
         dupd curry swap '[ _ closedir io-error ] finally
@@ -60,10 +60,10 @@ M: unix copy-file
 ! An easy way to return +unknown+ is to mount a .iso on OSX and
 ! call directory-entries on the mount point.
 
-: next-dirent ( DIR* -- dirent*/f )
-    readdir dup [
-        errno dup ENOENT = [ drop ] [ (throw-errno) ] if
-    ] unless ; inline
+: next-dirent ( DIR* dirent* -- dirent* ? )
+    f void* <ref> [
+        readdir_r [ (throw-errno) ] unless-zero
+    ] 2keep void* deref ; inline
 
 : >directory-entry ( dirent* -- directory-entry )
     [ d_name>> alien>native-string ]
@@ -73,7 +73,8 @@ M: unix copy-file
 
 M: unix (directory-entries)
     [
-        '[ _ next-dirent dup ] [ >directory-entry ] produce nip
+        dirent new
+        '[ _ _ next-dirent ] [ >directory-entry ] produce nip
     ] with-unix-directory ;
 
 os linux? [ "io.directories.unix.linux" require ] when