Browse Source

Make FileSystem.cake C-compatible

* Include stdbool
* Properly check features in preprocessor for selecting strerror_r
* Properly mark dirent as struct dirent
master
Macoy Madson 5 months ago
parent
commit
f3eb9336fc
  1. 14
      src/FileSystem.cake

14
src/FileSystem.cake

@ -4,7 +4,7 @@
&with-decls "DynamicArray.cake")
(c-import "<stdio.h>"
&with-decls "<stddef.h>") ;; for size_t
&with-decls "<stddef.h>" "<stdbool.h>") ;; for size_t
(var filesystem-verbose-logging bool false)
;; (var filesystem-verbose-logging bool true)
@ -107,9 +107,9 @@
(defun-local set-error-string (error-string-buffer (addr char) error-string-buffer-length size_t)
;; See man strerror(3)
(if (and (>= _POSIX_C_SOURCE 200112L) (not _GNU_SOURCE))
;; XSI-complient version always writes error string to buffer
(scope (var return-str (addr (const char))
(if-c-preprocessor (and (>= _POSIX_C_SOURCE 200112L) (not _GNU_SOURCE))
;; XSI-compliant version always writes error string to buffer
(scope (var return-value int
(strerror_r errno error-string-buffer error-string-buffer-length)))
;; GNU version only writes to buffer sometimes; we need to copy to our buffer in that case
(scope
@ -140,7 +140,7 @@
(set-error-string error-string-buffer error-string-buffer-length)
(perror "read-directory")
(return false))
(c-for (var entry (addr dirent) (readdir directory))
(c-for (var entry (addr (struct dirent)) (readdir directory))
entry
(set entry (readdir directory))
(fsdebugf "%s" (path entry > d_name))
@ -204,7 +204,7 @@
(if (token-splice os-directory-variable)
(scope
(var (token-splice entry-full-path-variable) (array 2048 char) (array 0))
(c-for (var (token-splice os-entry-variable) (addr dirent)
(c-for (var (token-splice os-entry-variable) (addr (struct dirent))
(readdir (token-splice os-directory-variable)))
(token-splice os-entry-variable)
(set (token-splice os-entry-variable) (readdir (token-splice os-directory-variable)))
@ -266,7 +266,7 @@
(perror "read-directory")
(return false))
(defer (closedir directory))
(c-for (var entry (addr dirent) (readdir directory))
(c-for (var entry (addr (struct dirent)) (readdir directory))
entry
(set entry (readdir directory))
(fsdebugf "%s" (path entry > d_name))

Loading…
Cancel
Save