Skip to content

Commit

Permalink
Update sponsors. More comments in path.c3
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Oct 26, 2024
1 parent fd1898b commit 83f8d24
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,6 @@ Editor plugins can be found at https://github.com/c3lang/editor-plugins.

## Thank yous

A huge "thank you" goes out to all contributors and sponsors.
A huge **THANK YOU** goes out to all contributors and sponsors.

A special thank you to sponsor [Caleb-o](https://github.com/Caleb-o) for going the extra mile.
A special thank you to sponsors [Caleb-o](https://github.com/Caleb-o) and [devdad](https://github.com/devdad) for going the extra mile.
34 changes: 34 additions & 0 deletions lib/std/io/path.c3
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ enum MkdirPermissions
USER_AND_ADMIN
}

<*
Create a directory on a given path, optionally recursive.

@param path `The path to create`
@param recursive `If directories in between should be created if they're missing, defaults to false`
@param permissions `The permissions to set on the directory`
*>
fn bool! mkdir(Path path, bool recursive = false, MkdirPermissions permissions = NORMAL)
{
if (!path.path_string.len) return PathResult.INVALID_PATH?;
Expand All @@ -111,12 +118,22 @@ fn bool! mkdir(Path path, bool recursive = false, MkdirPermissions permissions =
return os::native_mkdir(path, permissions);
}

<*
Tries to delete directory, which must be empty.

@param path `The path to delete`
@return `true if there was a directory to delete, false otherwise`
@return! PathResult.INVALID_PATH `if the path was invalid`
*>
fn bool! rmdir(Path path)
{
if (!path.path_string.len) return PathResult.INVALID_PATH?;
return os::native_rmdir(path);
}

<*
Like [rmdir] but deletes a directory even if it contains items.
*>
fn void! rmtree(Path path)
{
if (!path.path_string.len) return PathResult.INVALID_PATH?;
Expand All @@ -127,11 +144,21 @@ fn void! rmtree(Path path)
$endif
}

<*
Creates a new path.

@return! PathResult.INVALID_PATH `if the path was invalid`
*>
fn Path! new(String path, Allocator allocator = allocator::heap(), PathEnv path_env = DEFAULT_PATH_ENV)
{
return { normalize(path.copy(allocator), path_env), path_env };
}

<*
Creates a new path using the temp allocator.

@return! PathResult.INVALID_PATH `if the path was invalid`
*>
fn Path! temp_new(String path, PathEnv path_env = DEFAULT_PATH_ENV)
{
return new(path, allocator::temp(), path_env);
Expand Down Expand Up @@ -352,6 +379,13 @@ fn usz! volume_name_len(String path, PathEnv path_env) @local
}
}

<*
Get the path of the parent. This does not allocate, but returns a slice
of the path itself.

@return `The parent of the path as a non-allocated path`
@return! PathResult.NO_PARENT `if this path does not have a parent`
*>
fn Path! Path.parent(self)
{
if (self.path_string.len == 1 && is_separator(self.path_string[0], self.env)) return PathResult.NO_PARENT?;
Expand Down

0 comments on commit 83f8d24

Please sign in to comment.