diff options
author | Hinidu <hinidu@gmail.com> | 2014-04-07 00:24:21 +0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-07 12:15:28 -0300 |
commit | 8a2ffb2b010e02dd8dcbb3182d5a6e27006f6e46 (patch) | |
tree | 0f815b3f51dc2e383b6a2a5c8b9805885cae2ec2 /src/os | |
parent | c3cea30cb7952c44c3452d9e7926fe50397d43ae (diff) | |
download | rneovim-8a2ffb2b010e02dd8dcbb3182d5a6e27006f6e46.tar.gz rneovim-8a2ffb2b010e02dd8dcbb3182d5a6e27006f6e46.tar.bz2 rneovim-8a2ffb2b010e02dd8dcbb3182d5a6e27006f6e46.zip |
Use stdbool in os module
Diffstat (limited to 'src/os')
-rw-r--r-- | src/os/fs.c | 50 | ||||
-rw-r--r-- | src/os/os.h | 20 | ||||
-rw-r--r-- | src/os/shell.c | 2 | ||||
-rw-r--r-- | src/os/signal.c | 2 | ||||
-rw-r--r-- | src/os/users.c | 2 |
5 files changed, 36 insertions, 40 deletions
diff --git a/src/os/fs.c b/src/os/fs.c index c472ad0da8..9d09e5eb25 100644 --- a/src/os/fs.c +++ b/src/os/fs.c @@ -141,24 +141,24 @@ int os_is_absolute_path(const char_u *fname) return *fname == '/' || *fname == '~'; } -int os_isdir(const char_u *name) +bool os_isdir(const char_u *name) { int32_t mode = os_getperm(name); if (mode < 0) { - return FALSE; + return false; } if (!S_ISDIR(mode)) { - return FALSE; + return false; } - return TRUE; + return true; } -static int is_executable(const char_u *name); -static int is_executable_in_path(const char_u *name); +static bool is_executable(const char_u *name); +static bool is_executable_in_path(const char_u *name); -int os_can_exe(const char_u *name) +bool os_can_exe(const char_u *name) { // If it's an absolute or relative path don't need to use $PATH. if (os_is_absolute_path(name) || @@ -170,32 +170,32 @@ int os_can_exe(const char_u *name) return is_executable_in_path(name); } -// Return TRUE if "name" is an executable file, FALSE if not or it doesn't +// Return true if "name" is an executable file, false if not or it doesn't // exist. -static int is_executable(const char_u *name) +static bool is_executable(const char_u *name) { int32_t mode = os_getperm(name); if (mode < 0) { - return FALSE; + return false; } if (S_ISREG(mode) && (S_IEXEC & mode)) { - return TRUE; + return true; } - return FALSE; + return false; } /// Check if a file is inside the $PATH and is executable. /// -/// @return `TRUE` if `name` is an executable inside $PATH. -static int is_executable_in_path(const char_u *name) +/// @return `true` if `name` is an executable inside $PATH. +static bool is_executable_in_path(const char_u *name) { const char *path = getenv("PATH"); // PATH environment variable does not exist or is empty. if (path == NULL || *path == NUL) { - return FALSE; + return false; } int buf_len = STRLEN(name) + STRLEN(path) + 2; @@ -217,13 +217,13 @@ static int is_executable_in_path(const char_u *name) if (is_executable(buf)) { // Found our executable. Free buf and return. vim_free(buf); - return OK; + return true; } if (*e != ':') { // End of $PATH without finding any executable called name. vim_free(buf); - return FALSE; + return false; } path = e + 1; @@ -231,7 +231,7 @@ static int is_executable_in_path(const char_u *name) // We should never get to this point. assert(false); - return FALSE; + return false; } int os_stat(const char_u *name, uv_stat_t *statbuf) @@ -273,23 +273,19 @@ int os_setperm(const char_u *name, int perm) return FAIL; } -int os_file_exists(const char_u *name) +bool os_file_exists(const char_u *name) { uv_stat_t statbuf; if (os_stat(name, &statbuf) == OK) { - return TRUE; + return true; } - return FALSE; + return false; } -int os_file_is_readonly(const char *name) +bool os_file_is_readonly(const char *name) { - if (access(name, W_OK) == 0) { - return FALSE; - } - - return TRUE; + return access(name, W_OK) != 0; } int os_file_is_writable(const char *name) diff --git a/src/os/os.h b/src/os/os.h index 8456f87473..fc66307d34 100644 --- a/src/os/os.h +++ b/src/os/os.h @@ -28,23 +28,23 @@ int os_get_absolute_path(char_u *fname, char_u *buf, int len, int force); /// Check if the given file is absolute. /// /// This just checks if the file name starts with '/' or '~'. -/// @return `TRUE` if "fname" is absolute. +/// @return `true` if "fname" is absolute. int os_is_absolute_path(const char_u *fname); /// Check if the given path is a directory or not. /// -/// @return `TRUE` if `fname` is a directory. -int os_isdir(const char_u *name); +/// @return `true` if `fname` is a directory. +bool os_isdir(const char_u *name); /// Check if the given path represents an executable file. /// -/// @return `TRUE` if `name` is executable and +/// @return `true` if `name` is executable and /// - can be found in $PATH, /// - is relative to current dir or /// - is absolute. /// -/// @return `FALSE` otherwise. -int os_can_exe(const char_u *name); +/// @return `false` otherwise. +bool os_can_exe(const char_u *name); /// Get the file permissions for a given file. /// @@ -58,13 +58,13 @@ int os_setperm(const char_u *name, int perm); /// Check if a file exists. /// -/// @return `TRUE` if `name` exists. -int os_file_exists(const char_u *name); +/// @return `true` if `name` exists. +bool os_file_exists(const char_u *name); /// Check if a file is readonly. /// -/// @return `True` if `name` is readonly. -int os_file_is_readonly(const char *name); +/// @return `true` if `name` is readonly. +bool os_file_is_readonly(const char *name); /// Check if a file is writable. /// diff --git a/src/os/shell.c b/src/os/shell.c index e00c9b8d07..bc562474df 100644 --- a/src/os/shell.c +++ b/src/os/shell.c @@ -222,7 +222,7 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) // TODO for now this is only needed if the terminal is in raw mode, but // when the UI is externalized we'll also need it, so leave it here uv_process_kill(&proc, SIGINT); - got_int = FALSE; + got_int = false; } } diff --git a/src/os/signal.c b/src/os/signal.c index dc404a6e99..3595c63acb 100644 --- a/src/os/signal.c +++ b/src/os/signal.c @@ -73,7 +73,7 @@ void signal_handle(Event event) switch (signum) { case SIGINT: - got_int = TRUE; + got_int = true; break; #ifdef SIGPWR case SIGPWR: diff --git a/src/os/users.c b/src/os/users.c index c8c2e773de..5972e3f1e8 100644 --- a/src/os/users.c +++ b/src/os/users.c @@ -14,7 +14,7 @@ int os_get_usernames(garray_T *users) { if (users == NULL) { - return FALSE; + return FAIL; } ga_init(users, sizeof(char *), 20); |