No matching definitions.

tur/fs

stdlib/fs.tur

extended file-system operations (stat, readdir, fnmatch, walk).

Since: Phase B1

defn

fs/stat

(fs/stat [path :cstr] :int)

return file metadata for a path.

pathNUL-terminated path cstr

An opaque pointer (as :int) to a { size mtime mode } triple, or 0 if the path is inaccessible. Inspect with fs/stat-size, fs/stat-mtime, fs/stat-mode. Free with fs/stat-free.

(let [s (fs/stat "/etc/hosts")] (fs/stat-size s))

Since: Phase B2

defn

fs/stat-free

(fs/stat-free [s :int] :void)

free the stat result returned by fs/stat.

sstat pointer from fs/stat (may be 0)
(fs/stat-free s)

Since: Phase B2

defn

fs/stat-size

(fs/stat-size [s :int] :int)

extract file size from a stat result.

sstat pointer from fs/stat

File size in bytes as :int.

(fs/stat-size (fs/stat "/etc/hosts"))  ; => 221

Since: Phase B2

defn

fs/stat-mtime

(fs/stat-mtime [s :int] :int)

extract modification time from a stat result.

sstat pointer from fs/stat

Modification time as a Unix timestamp (:int).

(fs/stat-mtime (fs/stat "/etc/hosts"))

Since: Phase B2

defn

fs/stat-mode

(fs/stat-mode [s :int] :int)

extract file mode bits from a stat result.

sstat pointer from fs/stat

File mode bits as :int (same as st_mode from stat(2)).

(fs/stat-mode (fs/stat "/etc/hosts"))  ; => 33188

Since: Phase B2

defn

fs/exists?

(fs/exists? [path :cstr] :bool)

test whether a path exists.

pathNUL-terminated path cstr

true if stat(2) succeeds on the path, false otherwise.

(fs/exists? "/etc/hosts")  ; => true

Since: Phase B2

defn

fs/file?

(fs/file? [path :cstr] :bool)

test whether a path is a regular file.

pathNUL-terminated path cstr

true if path is a regular file.

(fs/file? "/etc/hosts")  ; => true

Since: Phase B2

defn

fs/dir?

(fs/dir? [path :cstr] :bool)

test whether a path is a directory.

pathNUL-terminated path cstr

true if path is a directory.

(fs/dir? "/tmp")  ; => true

Since: Phase B2

defn

fs/mkdir

(fs/mkdir [path :cstr] :int)

create a directory with mode 0755.

pathNUL-terminated path cstr

0 on success, -1 on error (errno set).

(fs/mkdir "/tmp/mydir")  ; => 0

Since: Phase B2

defn

fs/mkdirp

(fs/mkdirp [path :cstr] :int)

create a directory and all missing parent directories.

pathNUL-terminated path cstr

0 on success, -1 if any mkdir call fails for a reason other than the directory already existing.

(fs/mkdirp "/tmp/a/b/c")  ; => 0

Since: Phase B2

defn

fs/rmdir

(fs/rmdir [path :cstr] :int)

remove an empty directory.

pathNUL-terminated path cstr

0 on success, -1 on error.

(fs/rmdir "/tmp/mydir")  ; => 0

Since: Phase B2

defn

fs/rm

(fs/rm [path :cstr] :int)

remove a regular file.

pathNUL-terminated path cstr

0 on success, -1 on error.

(fs/rm "/tmp/tmpfile.txt")  ; => 0

Since: Phase B2

defn

fs/rename

(fs/rename [src :cstr dst :cstr] :int)

rename or move a file.

srcsource path cstr
dstdestination path cstr

0 on success, -1 on error.

(fs/rename "/tmp/a.txt" "/tmp/b.txt")  ; => 0

Since: Phase B2

defn

fs/copy

(fs/copy [src :cstr dst :cstr] :int)

copy a file from src to dst using a read/write loop.

srcsource path cstr
dstdestination path cstr

0 on success, -1 on error.

(fs/copy "/etc/hosts" "/tmp/hosts.bak")  ; => 0

Since: Phase B2

defn

fs/glob

(fs/glob [dir :cstr pattern :cstr] :int)

list directory entries matching a fnmatch(3) pattern.

dirdirectory to search (e.g., "/tmp")
patternfnmatch pattern applied to entry names (e.g., "*.txt")

A cons list of heap-allocated full-path cstrs for matching entries. Returns 0 (empty list) if the directory cannot be opened. Free with fs/glob-free.

(fs/glob "/tmp" "*.txt")  ; => cons list of paths

Since: Phase B2

defn

fs/glob-free

(fs/glob-free [lst :int] :void)

free a cons list of paths returned by fs/glob.

lstcons list returned by fs/glob
(fs/glob-free my-list)

Since: Phase B2

defn

fs/tmpfile

(fs/tmpfile :int)

create a unique temporary file via mkstemp(3).

An opaque pointer (as :int) to a pair { path-cstr, fd }. The path is heap-allocated; the fd is the open descriptor. Free with fs/tmpfile-free. Returns 0 on mkstemp failure.

(let [t (fs/tmpfile)] (fs/tmpfile-path t))

Since: Phase B2

defn

fs/tmpfile-path

(fs/tmpfile-path [t :int] :cstr)

extract the path from an fs/tmpfile pair.

ttmpfile pair from fs/tmpfile

The path cstr (owned by the pair; do not free separately).

(fs/tmpfile-path my-tmp)  ; => "/tmp/tur_aB3xYz"

Since: Phase B2

defn

fs/tmpfile-fd

(fs/tmpfile-fd [t :int] :int)

extract the file descriptor from an fs/tmpfile pair.

ttmpfile pair from fs/tmpfile

The open file descriptor as :int.

(fs/tmpfile-fd my-tmp)  ; => 5

Since: Phase B2

defn

fs/tmpfile-free

(fs/tmpfile-free [t :int] :void)

close the fd and free the tmpfile pair.

ttmpfile pair from fs/tmpfile (may be 0)
(fs/tmpfile-free my-tmp)

Since: Phase B2

defn

fs/read-text

(fs/read-text [path :cstr] :cstr)

read an entire file into a NUL-terminated heap buffer.

pathNUL-terminated path cstr

A heap-allocated NUL-terminated cstr of the file contents, or NULL on error. The caller must free the returned buffer.

(fs/read-text "/etc/hostname")  ; => "myhost\n"

Since: Phase B2

defn

fs/write-text

(fs/write-text [path :cstr content :cstr] :int)

write a NUL-terminated string to a file.

pathNUL-terminated destination path cstr
contentNUL-terminated string to write

0 on success, -1 on error.

(fs/write-text "/tmp/out.txt" "hello\n")  ; => 0

Since: Phase B2