Directory

← Reference
Io

C implementation of Directory — a thin Io wrapper around POSIX opendir/readdir/closedir. IoDirectoryData holds a single symbol (the path); each items/at/size call reopens the directory rather than keeping a persistent DIR* open, which keeps clone semantics trivial and avoids leaking descriptors on GC. Under WASI the evaluator must have been started with --dir= for any path to be openable; otherwise opendir fails and Io sees an "unable to open directory" exception. isDirectory prefers the d_type fast path when the host dirent exposes it, falling back to a stat call otherwise.

IoDirectory_CurrentWorkingDirectoryAsUArray(void)

Wraps getcwd(3) and returns a newly-allocated UArray containing the cwd (or "." on failure). The allocated buf is deliberately not freed — OSX MallocDebug flags that free as a bug despite the man page, and WASI does not need it.

IoDirectory_SetCurrentWorkingDirectory(path)

Thin wrapper around chdir so non-VM C code can change the process cwd without including directly.

IoDirectory_cloneWithPath_(self, path)

Clones self and overrides its path — used when walking filesystem trees so subdirectories inherit any Io-level slots the caller may have attached to the parent Directory object.

IoDirectory_free(self)

Registered as the tag's freeFunc. No OS handles to close — DIR* handles are opened and closed per operation, so only the IoDirectoryData payload needs to be released.

IoDirectory_itemForDirent_(self, dp)

Builds the Io-visible entry for one readdir result. Joins the parent path with dp->d_name (inserting a separator only if missing), then uses isDirectory to pick between constructing an IoDirectory or an IoFile. Used by the Io-level `items` method to materialize a directory listing as a List of typed objects.

IoDirectory_justAt(self, name)

Looks up a child by name using stat(2) and returns a Directory or File depending on the result; returns ioNil if the path does not exist. Shared between the Io-level `at` and `createSubdirectory` methods.

IoDirectory_justFullPath(self, name)

Joins the directory's path with a relative name into a fresh interned symbol. Used by at/createSubdirectory so path composition is done in one place with uniform separator handling via UArray_appendPath_.

IoDirectory_mark(self)

Registered as the tag's markFunc. The path symbol is the only Io object on IoDirectoryData.

IoDirectory_new(state)

Convenience constructor: look up the Directory proto and clone it.

IoDirectory_newTag(state)

Builds the Directory tag with clone / mark / free function pointers.

IoDirectory_newWithPath_(state, path)

Constructs a Directory clone with the given path. Does not touch the filesystem; callers typically follow with exists/items.

IoDirectory_proto(state)

Creates the Directory proto: allocates IoDirectoryData with the default path of "." (launch dir), registers the proto, and installs the Io-visible method table.

IoDirectory_rawClone(proto)

Registered as the tag's cloneFunc. Copies the proto's IoDirectoryData so the clone inherits the path; both Directory clones and the proto therefore share nothing but an initial path string.

isDirectory(dp, path)

Module-local helper that decides whether a readdir entry refers to a directory. Prefers the inline d_type byte when the platform exposes it (avoids a stat syscall per entry); if d_type is DT_UNKNOWN or DT_LNK, falls back to a full stat so symlink targets are resolved correctly. Shared by the items/at implementations below.