summaryrefslogtreecommitdiff
path: root/os.h
diff options
context:
space:
mode:
Diffstat (limited to 'os.h')
-rw-r--r--os.h64
1 files changed, 32 insertions, 32 deletions
diff --git a/os.h b/os.h
index 4769063..23e94f2 100644
--- a/os.h
+++ b/os.h
@@ -16,6 +16,7 @@ enum {
FS_PERMISSION_READ = 0x01,
FS_PERMISSION_WRITE = 0x02,
};
+/// permission bits
typedef u8 FsPermission;
typedef struct {
@@ -25,43 +26,52 @@ typedef struct {
/// returns what kind of thing this is.
FsType fs_path_type(const char *path);
+/// get which permissions user has for file
FsPermission fs_path_permission(const char *path);
/// Does this file exist? Returns false for directories.
bool fs_file_exists(const char *path);
-/// Returns a NULL-terminated array of the files/directories in this directory, or NULL if the directory does not exist/out of memory.
-/// When you're done with the entries, call fs_dir_entries_free (or call free on each entry, then on the whole array).
+/// returns size of file or -1 on error
+int64_t fs_file_size(const char *path);
+/// Returns a `NULL`-terminated array of the files/directories in this directory, or `NULL` on error.
+///
+/// When you're done with the entries, call \ref fs_dir_entries_free (or call free on each entry, then on the whole array).
/// NOTE: The files/directories aren't returned in any particular order!
FsDirectoryEntry **fs_list_directory(const char *dirname);
-/// Create the directory specified by `path`\n
-/// Returns:\n
+/// Create the directory specified by `path`
+///
+/// \returns
/// 1 if the directory was created successfully\n
/// 0 if the directory already exists\n
-/// -1 if the path already exists, but it's not a directory, or if there's another error (e.g. don't have permission to create directory).\n
+/// -1 if the path already exists, but it's not a directory, or if there's another error (e.g. don't have permission to create directory).
int fs_mkdir(const char *path);
-// Puts the current working directory into buf, including a null-terminator, writing at most buflen bytes.\n
-// Returns:\n
-// 1 if the working directory was inserted into buf successfully\n
-// 0 if buf is too short to hold the cwd\n
-// -1 if we can't get the cwd for whatever reason.\n
+/// Puts the current working directory into `buf`, including a null-terminator, writing at most `buflen` bytes.
+///
+/// \returns
+/// 1 if the working directory was inserted into buf successfully\n
+/// 0 if buf is too short to hold the cwd\n
+/// -1 if we can't get the cwd for whatever reason.
int os_get_cwd(char *buf, size_t buflen);
-// Unlike ISO C rename() function, this will overwrite `newname` if it exists.\n
-// Returns:\n
-// >= 0 if successful\n
-// < 0 on error\n
+/// Unlike ISO C rename() function, this will overwrite `newname` if it exists.
+///
+/// \returns
+/// >= 0 if successful\n
+/// < 0 on error
int os_rename_overwrite(const char *oldname, const char *newname);
+/// get last modification time of file
struct timespec time_last_modified(const char *filename);
+/// get time since some arbitrary point
struct timespec time_get(void);
/// sleep for a certain number of nanoseconds
void time_sleep_ns(u64 ns);
/// runs xdg-open or equivalent on the given path, which can be a URL.
///
-/// returns `true` on success.
+/// \returns `true` on success.
bool open_with_default_application(const char *path);
-/// equivalent to POSIX function chdir, but returns `true` on success and `false` on failure.
+/// equivalent to POSIX function `chdir`, but returns `true` on success and `false` on failure.
bool change_directory(const char *path);
-/// free the entries generated by fs_list_directory.
+/// free the entries generated by \ref fs_list_directory.
static void fs_dir_entries_free(FsDirectoryEntry **entries) {
for (int i = 0; entries[i]; ++i)
free(entries[i]);
@@ -75,21 +85,10 @@ static double time_get_seconds(void) {
+ (double)t.tv_nsec * 1e-9;
}
-
-
-/// sleep for microseconds
-static void time_sleep_us(u64 us) {
- time_sleep_ns(us * 1000);
-}
-
-/// sleep for milliseconds
-static void time_sleep_ms(u64 ms) {
- time_sleep_ns(ms * 1000000);
-}
-
/// sleep for seconds
-static void time_sleep_s(u64 s) {
- time_sleep_ns(s * 1000000000);
+static void time_sleep_seconds(double s) {
+ if (s <= 0) return;
+ time_sleep_ns((u64)(s * 1000000000));
}
/// a process
@@ -179,7 +178,8 @@ const char *socket_get_error(Socket *socket);
/// -2 on error\n
/// -1 on end of file\n
/// 0 if no data is available right now\n
-/// or a positive number indicating the number of bytes read to `data` (at most `size`)\n
+/// or a positive number indicating the number of bytes read to `data` (at most `size`)
+///
/// This does a nonblocking read.
long long socket_read(Socket *socket, char *data, size_t size);
/// write to socket