diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/os/env.c | 19 | ||||
-rw-r--r-- | src/os/event.c | 41 | ||||
-rw-r--r-- | src/os/event.h | 2 | ||||
-rw-r--r-- | src/os/fs.c | 164 | ||||
-rw-r--r-- | src/os/input.c | 92 | ||||
-rw-r--r-- | src/os/input.h | 5 | ||||
-rw-r--r-- | src/os/mem.c | 23 | ||||
-rw-r--r-- | src/os/os.h | 8 | ||||
-rw-r--r-- | src/os/time.c | 8 | ||||
-rw-r--r-- | src/os/time.h | 3 | ||||
-rw-r--r-- | src/os/users.c | 45 |
11 files changed, 159 insertions, 251 deletions
diff --git a/src/os/env.c b/src/os/env.c index 91b27e67a9..cf08a33f96 100644 --- a/src/os/env.c +++ b/src/os/env.c @@ -1,15 +1,4 @@ -/* vi:set ts=2 sts=2 sw=2: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -/* - * env.c -- environment variable access - */ +// env.c -- environment variable access #include <uv.h> @@ -33,15 +22,13 @@ int os_setenv(const char *name, const char *value, int overwrite) char *os_getenvname_at_index(size_t index) { # if defined(AMIGA) || defined(__MRC__) || defined(__SC__) - /* - * No environ[] on the Amiga and on the Mac (using MPW). - */ + // No environ[] on the Amiga and on the Mac (using MPW). return NULL; # else # if defined(HAVE__NSGETENVIRON) char **environ = *_NSGetEnviron(); # elif !defined(__WIN32__) - /* Borland C++ 5.2 has this in a header file. */ + // Borland C++ 5.2 has this in a header file. extern char **environ; # endif // check if index is inside the environ array diff --git a/src/os/event.c b/src/os/event.c index 798bf03946..eb7960c219 100644 --- a/src/os/event.c +++ b/src/os/event.c @@ -13,23 +13,23 @@ static void timer_prepare_cb(uv_prepare_t *, int); void event_init() { - /* Initialize input events */ + // Initialize input events input_init(); - /* Timer to wake the event loop if a timeout argument is passed to - * `event_poll` */ + // Timer to wake the event loop if a timeout argument is passed to + // `event_poll` uv_timer_init(uv_default_loop(), &timer); - /* This prepare handle that actually starts the timer */ + // This prepare handle that actually starts the timer uv_prepare_init(uv_default_loop(), &timer_prepare); } -/* Wait for some event */ +// Wait for some event bool event_poll(int32_t ms) { bool timed_out; uv_run_mode run_mode = UV_RUN_ONCE; if (input_ready()) { - /* If there's a pending input event to be consumed, do it now */ + // If there's a pending input event to be consumed, do it now return true; } @@ -37,42 +37,39 @@ bool event_poll(int32_t ms) timed_out = false; if (ms > 0) { - /* Timeout passed as argument to the timer */ + // Timeout passed as argument to the timer timer.data = &timed_out; - /* We only start the timer after the loop is running, for that we - * use an prepare handle(pass the interval as data to it) */ + // We only start the timer after the loop is running, for that we + // use an prepare handle(pass the interval as data to it) timer_prepare.data = &ms; uv_prepare_start(&timer_prepare, timer_prepare_cb); } else if (ms == 0) { - /* - * For ms == 0, we need to do a non-blocking event poll by - * setting the run mode to UV_RUN_NOWAIT. - */ + // For ms == 0, we need to do a non-blocking event poll by + // setting the run mode to UV_RUN_NOWAIT. run_mode = UV_RUN_NOWAIT; } do { - /* Run one event loop iteration, blocking for events if run_mode is - * UV_RUN_ONCE */ + // Run one event loop iteration, blocking for events if run_mode is + // UV_RUN_ONCE uv_run(uv_default_loop(), run_mode); } while ( - /* Continue running if ... */ - !input_ready() && /* ... we have no input */ - run_mode != UV_RUN_NOWAIT && /* ... ms != 0 */ - !timed_out /* ... we didn't get a timeout */ - ); + // Continue running if ... + !input_ready() // ... we have no input + && run_mode != UV_RUN_NOWAIT // ... ms != 0 + && !timed_out); // ... we didn't get a timeout input_stop(); if (ms > 0) { - /* Stop the timer */ + // Stop the timer uv_timer_stop(&timer); } return input_ready(); } -/* Set a flag in the `event_poll` loop for signaling of a timeout */ +// Set a flag in the `event_poll` loop for signaling of a timeout static void timer_cb(uv_timer_t *handle, int status) { *((bool *)handle->data) = true; diff --git a/src/os/event.h b/src/os/event.h index 874d7130bf..d13103373d 100644 --- a/src/os/event.h +++ b/src/os/event.h @@ -7,5 +7,5 @@ void event_init(void); bool event_poll(int32_t ms); -#endif +#endif // NEOVIM_OS_EVENT_H diff --git a/src/os/fs.c b/src/os/fs.c index 2207cdbab6..8d3e8d1627 100644 --- a/src/os/fs.c +++ b/src/os/fs.c @@ -1,15 +1,4 @@ -/* vi:set ts=2 sts=2 sw=2: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -/* - * fs.c -- filesystem access - */ +// fs.c -- filesystem access #include <uv.h> @@ -18,7 +7,7 @@ #include "misc1.h" #include "misc2.h" -int os_chdir(char *path) { +int os_chdir(const char *path) { if (p_verbose >= 5) { verbose_enter(); smsg((char_u *)"chdir(%s)", path); @@ -27,10 +16,8 @@ int os_chdir(char *path) { return uv_chdir(path); } -/* - * Get name of current directory into buffer 'buf' of length 'len' bytes. - * Return OK for success, FAIL for failure. - */ +// Get name of current directory into buffer 'buf' of length 'len' bytes. +// Return OK for success, FAIL for failure. int os_dirname(char_u *buf, size_t len) { assert(buf && len); @@ -43,44 +30,42 @@ int os_dirname(char_u *buf, size_t len) return OK; } -/* - * Get the absolute name of the given relative directory. - * - * parameter directory: Directory name, relative to current directory. - * return FAIL for failure, OK for success - */ +// Get the absolute name of the given relative directory. +// +// parameter directory: Directory name, relative to current directory. +// return FAIL for failure, OK for success int os_full_dir_name(char *directory, char *buffer, int len) { int retval = OK; - if(STRLEN(directory) == 0) { + if (STRLEN(directory) == 0) { return os_dirname((char_u *) buffer, len); } char old_dir[MAXPATHL]; - /* Get current directory name. */ + // Get current directory name. if (os_dirname((char_u *) old_dir, MAXPATHL) == FAIL) { return FAIL; } - /* We have to get back to the current dir at the end, check if that works. */ + // We have to get back to the current dir at the end, check if that works. if (os_chdir(old_dir) != 0) { return FAIL; } if (os_chdir(directory) != 0) { - /* Do not return immediatly since we may be in the wrong directory. */ + // Do not return immediatly since we may be in the wrong directory. retval = FAIL; } if (retval == FAIL || os_dirname((char_u *) buffer, len) == FAIL) { - /* Do not return immediatly since we are in the wrong directory. */ + // Do not return immediatly since we are in the wrong directory. retval = FAIL; } - + if (os_chdir(old_dir) != 0) { - /* That shouldn't happen, since we've tested if it works. */ + // That shouldn't happen, since we've tested if it works. retval = FAIL; EMSG(_(e_prev_dir)); } @@ -88,38 +73,36 @@ int os_full_dir_name(char *directory, char *buffer, int len) return retval; } -/* - * Append to_append to path with a slash in between. - */ +// Append to_append to path with a slash in between. int append_path(char *path, const char *to_append, int max_len) { int current_length = STRLEN(path); int to_append_length = STRLEN(to_append); - /* Do not append empty strings. */ + // Do not append empty strings. if (to_append_length == 0) { return OK; } - /* Do not append a dot. */ + // Do not append a dot. if (STRCMP(to_append, ".") == 0) { return OK; } - /* Glue both paths with a slash. */ + // Glue both paths with a slash. if (current_length > 0 && path[current_length-1] != '/') { - current_length += 1; /* Count the trailing slash. */ + current_length += 1; // Count the trailing slash. - /* +1 for the NUL at the end. */ - if (current_length +1 > max_len) { + // +1 for the NUL at the end. + if (current_length + 1 > max_len) { return FAIL; } STRCAT(path, "/"); } - /* +1 for the NUL at the end. */ - if (current_length + to_append_length +1 > max_len) { + // +1 for the NUL at the end. + if (current_length + to_append_length + 1 > max_len) { return FAIL; } @@ -127,14 +110,12 @@ int append_path(char *path, const char *to_append, int max_len) return OK; } -/* - * Get absolute file name into "buf[len]". - * - * parameter force: Also expand when the given path in fname is already - * absolute. - * - * return FAIL for failure, OK for success - */ +// Get absolute file name into "buf[len]". +// +// parameter force: Also expand when the given path in fname is already +// absolute. +// +// return FAIL for failure, OK for success int os_get_absolute_path(char_u *fname, char_u *buf, int len, int force) { char_u *p; @@ -143,10 +124,9 @@ int os_get_absolute_path(char_u *fname, char_u *buf, int len, int force) char relative_directory[len]; char *end_of_path = (char *) fname; - /* expand it if forced or not an absolute path */ + // expand it if forced or not an absolute path if (force || !os_is_absolute_path(fname)) { if ((p = vim_strrchr(fname, '/')) != NULL) { - STRNCPY(relative_directory, fname, p-fname); relative_directory[p-fname] = NUL; end_of_path = (char *) (p + 1); @@ -162,22 +142,18 @@ int os_get_absolute_path(char_u *fname, char_u *buf, int len, int force) return append_path((char *) buf, (char *) end_of_path, len); } -/* - * Return TRUE if "fname" does not depend on the current directory. - */ +// Return TRUE if "fname" does not depend on the current directory. int os_is_absolute_path(const char_u *fname) { return *fname == '/' || *fname == '~'; } -/* - * return TRUE if "name" is a directory - * return FALSE if "name" is not a directory - * return FALSE for error - */ +// return TRUE if "name" is a directory +// return FALSE if "name" is not a directory +// return FALSE for error int os_isdir(const char_u *name) { - long mode = os_getperm(name); + int32_t mode = os_getperm(name); if (mode < 0) { return FALSE; } @@ -192,13 +168,11 @@ int os_isdir(const char_u *name) static int is_executable(const char_u *name); static int is_executable_in_path(const char_u *name); -/* - * Return TRUE if "name" is executable and can be found in $PATH, is absolute - * or relative to current dir, FALSE if not. - */ +// Return TRUE if "name" is executable and can be found in $PATH, is absolute +// or relative to current dir, FALSE if not. int os_can_exe(const char_u *name) { - /* If it's an absolute or relative path don't need to use $PATH. */ + // If it's an absolute or relative path don't need to use $PATH. if (os_is_absolute_path(name) || (name[0] == '.' && (name[1] == '/' || (name[1] == '.' && name[2] == '/')))) { @@ -208,13 +182,11 @@ 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 - * exist. - */ +// Return TRUE if "name" is an executable file, FALSE if not or it doesn't +// exist. static int is_executable(const char_u *name) { - long mode = os_getperm(name); + int32_t mode = os_getperm(name); if (mode < 0) { return FALSE; @@ -227,14 +199,12 @@ static int is_executable(const char_u *name) return FALSE; } -/* - * Return TRUE if "name" can be found in $PATH and executed, FALSE if not or an - * error occurs. - */ +// Return TRUE if "name" can be found in $PATH and executed, FALSE if not or an +// error occurs. static int is_executable_in_path(const char_u *name) { const char *path = getenv("PATH"); - /* PATH environment variable does not exist or is empty. */ + // PATH environment variable does not exist or is empty. if (path == NULL || *path == NUL) { return FALSE; } @@ -245,29 +215,27 @@ static int is_executable_in_path(const char_u *name) return FALSE; } - /* - * Walk through all entries in $PATH to check if "name" exists there and - * is an executable file. - */ + // Walk through all entries in $PATH to check if "name" exists there and + // is an executable file. for (;; ) { const char *e = strchr(path, ':'); if (e == NULL) { e = path + STRLEN(path); } - /* Glue together the given directory from $PATH with name and save into - * buf. */ + // Glue together the given directory from $PATH with name and save into + // buf. vim_strncpy(buf, (char_u *) path, e - path); append_path((char *) buf, (const char *) name, buf_len); if (is_executable(buf)) { - /* Found our executable. Free buf and return. */ + // Found our executable. Free buf and return. vim_free(buf); return OK; } if (*e != ':') { - /* End of $PATH without finding any executable called name. */ + // End of $PATH without finding any executable called name. vim_free(buf); return FALSE; } @@ -275,33 +243,30 @@ static int is_executable_in_path(const char_u *name) path = e + 1; } - /* We should never get to this point. */ + // We should never get to this point. assert(false); return FALSE; } -/* - * Get file permissions for 'name'. - * Returns -1 when it doesn't exist. - */ -long os_getperm(const char_u *name) +// Get file permissions for 'name'. +// Returns -1 when it doesn't exist. +int32_t os_getperm(const char_u *name) { uv_fs_t request; - int result = uv_fs_stat(uv_default_loop(), &request, (const char*) name, NULL); + int result = uv_fs_stat(uv_default_loop(), &request, + (const char *)name, NULL); uint64_t mode = request.statbuf.st_mode; uv_fs_req_cleanup(&request); if (result != 0) { return -1; } else { - return (long) mode; + return (int32_t) mode; } } -/* - * Set file permission for 'name' to 'perm'. - * Returns FAIL for failure, OK otherwise. - */ +// Set file permission for 'name' to 'perm'. +// Returns FAIL for failure, OK otherwise. int os_setperm(const char_u *name, int perm) { uv_fs_t request; @@ -316,13 +281,12 @@ int os_setperm(const char_u *name, int perm) } } -/* - * return TRUE if "name" exists. - */ -int os_file_exists(char_u *name) +// return TRUE if "name" exists. +int os_file_exists(const char_u *name) { uv_fs_t request; - int result = uv_fs_stat(uv_default_loop(), &request, (const char*) name, NULL); + int result = uv_fs_stat(uv_default_loop(), &request, + (const char *)name, NULL); uv_fs_req_cleanup(&request); if (result != 0) { diff --git a/src/os/input.c b/src/os/input.c index 2f4b42467b..1e2d331fc0 100644 --- a/src/os/input.c +++ b/src/os/input.c @@ -31,8 +31,8 @@ typedef struct { static ReadBuffer rbuffer; static uv_pipe_t read_stream; -/* Use an idle handle to make reading from the fs look like a normal libuv - * event */ +// Use an idle handle to make reading from the fs look like a normal libuv +// event static uv_idle_t fread_idle; static uv_handle_type read_channel_type; static bool eof = false; @@ -58,30 +58,30 @@ void input_init() } } -/* Check if there's a pending input event */ +// Check if there's a pending input event bool input_ready() { return rbuffer.rpos < rbuffer.wpos || eof; } -/* Listen for input */ +// Listen for input void input_start() { - /* Pin the buffer used by libuv */ + // Pin the buffer used by libuv rbuffer.uvbuf.len = READ_BUFFER_LENGTH - rbuffer.wpos; rbuffer.uvbuf.base = (char *)(rbuffer.data + rbuffer.wpos); if (read_channel_type == UV_FILE) { - /* Just invoke the `fread_idle_cb` as soon as the loop starts */ + // Just invoke the `fread_idle_cb` as soon as the loop starts uv_idle_start(&fread_idle, fread_idle_cb); } else { - /* Start reading */ + // Start reading rbuffer.reading = false; uv_read_start((uv_stream_t *)&read_stream, alloc_cb, read_cb); } } -/* Stop listening for input */ +// Stop listening for input void input_stop() { if (read_channel_type == UV_FILE) { @@ -91,7 +91,7 @@ void input_stop() } } -/* Copies (at most `count`) of was read from `read_cmd_fd` into `buf` */ +// Copies (at most `count`) of was read from `read_cmd_fd` into `buf` uint32_t input_read(char *buf, uint32_t count) { uint32_t read_count = rbuffer.wpos - rbuffer.rpos; @@ -106,13 +106,12 @@ uint32_t input_read(char *buf, uint32_t count) } if (rbuffer.wpos == READ_BUFFER_LENGTH) { - /* `wpos` is at the end of the buffer, so free some space by moving unread - * data... */ + // `wpos` is at the end of the buffer, so free some space by moving unread + // data... memmove( - rbuffer.data,/* ...To the beginning of the buffer(rpos 0) */ - rbuffer.data + rbuffer.rpos,/* ...From the first unread position */ - rbuffer.wpos - rbuffer.rpos/* ...By the number of unread bytes */ - ); + rbuffer.data, // ...To the beginning of the buffer(rpos 0) + rbuffer.data + rbuffer.rpos, // ...From the first unread position + rbuffer.wpos - rbuffer.rpos); // ...By the number of unread bytes rbuffer.wpos -= rbuffer.rpos; rbuffer.rpos = 0; } @@ -121,8 +120,8 @@ uint32_t input_read(char *buf, uint32_t count) } -/* Low level input function. */ -int os_inchar(char_u *buf, int maxlen, long ms, int tb_change_cnt) +// Low level input function. +int os_inchar(char_u *buf, int maxlen, int32_t ms, int tb_change_cnt) { InbufPollResult result; @@ -132,8 +131,8 @@ int os_inchar(char_u *buf, int maxlen, long ms, int tb_change_cnt) } } else { if ((result = inbuf_poll(p_ut)) != kInputAvail) { - if (trigger_cursorhold() && maxlen >= 3 && - !typebuf_changed(tb_change_cnt)) { + if (trigger_cursorhold() && maxlen >= 3 + && !typebuf_changed(tb_change_cnt)) { buf[0] = K_SPECIAL; buf[1] = KS_EXTRA; buf[2] = KE_CURSORHOLD; @@ -145,7 +144,7 @@ int os_inchar(char_u *buf, int maxlen, long ms, int tb_change_cnt) } } - /* If input was put directly in typeahead buffer bail out here. */ + // If input was put directly in typeahead buffer bail out here. if (typebuf_changed(tb_change_cnt)) return 0; @@ -157,23 +156,21 @@ int os_inchar(char_u *buf, int maxlen, long ms, int tb_change_cnt) return read_from_input_buf(buf, (long)maxlen); } -/* Check if a character is available for reading */ +// Check if a character is available for reading bool os_char_avail() { return inbuf_poll(0) == kInputAvail; } -/* - * Check for CTRL-C typed by reading all available characters. - * In cooked mode we should get SIGINT, no need to check. - */ +// Check for CTRL-C typed by reading all available characters. +// In cooked mode we should get SIGINT, no need to check. void os_breakcheck() { if (curr_tmode == TMODE_RAW && event_poll(0)) fill_input_buf(FALSE); } -/* This is a replacement for the old `WaitForChar` function in os_unix.c */ +// This is a replacement for the old `WaitForChar` function in os_unix.c static InbufPollResult inbuf_poll(int32_t ms) { if (input_available()) @@ -192,23 +189,23 @@ static InbufPollResult inbuf_poll(int32_t ms) static void stderr_switch() { int mode = cur_tmode; - /* We probably set the wrong file descriptor to raw mode. Switch back to - * cooked mode */ + // We probably set the wrong file descriptor to raw mode. Switch back to + // cooked mode settmode(TMODE_COOK); - /* Stop the idle handle */ + // Stop the idle handle uv_idle_stop(&fread_idle); - /* Use stderr for stdin, also works for shell commands. */ + // Use stderr for stdin, also works for shell commands. read_cmd_fd = 2; - /* Initialize and start the input stream */ + // Initialize and start the input stream uv_pipe_init(uv_default_loop(), &read_stream, 0); uv_pipe_open(&read_stream, read_cmd_fd); uv_read_start((uv_stream_t *)&read_stream, alloc_cb, read_cb); rbuffer.reading = false; - /* Set the mode back to what it was */ + // Set the mode back to what it was settmode(mode); } -/* Called by libuv to allocate memory for reading. */ +// Called by libuv to allocate memory for reading. static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf) { if (rbuffer.reading) { @@ -218,36 +215,34 @@ static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf) buf->base = rbuffer.uvbuf.base; buf->len = rbuffer.uvbuf.len; - /* Avoid `alloc_cb`, `alloc_cb` sequences on windows */ + // Avoid `alloc_cb`, `alloc_cb` sequences on windows rbuffer.reading = true; } -/* - * Callback invoked by libuv after it copies the data into the buffer provided - * by `alloc_cb`. This is also called on EOF or when `alloc_cb` returns a - * 0-length buffer. - */ +// Callback invoked by libuv after it copies the data into the buffer provided +// by `alloc_cb`. This is also called on EOF or when `alloc_cb` returns a +// 0-length buffer. static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) { if (cnt <= 0) { if (cnt != UV_ENOBUFS) { - /* Read error or EOF, either way vim must exit */ + // Read error or EOF, either way vim must exit eof = true; } return; } - /* Data was already written, so all we need is to update 'wpos' to reflect - * the space actually used in the buffer. */ + // Data was already written, so all we need is to update 'wpos' to reflect + // the space actually used in the buffer. rbuffer.wpos += cnt; } -/* Called by the by the 'idle' handle to emulate a reading event */ +// Called by the by the 'idle' handle to emulate a reading event static void fread_idle_cb(uv_idle_t *handle, int status) { uv_fs_t req; - /* Synchronous read */ + // Synchronous read uv_fs_read( uv_default_loop(), &req, @@ -255,16 +250,15 @@ static void fread_idle_cb(uv_idle_t *handle, int status) &rbuffer.uvbuf, 1, rbuffer.fpos, - NULL - ); + NULL); uv_fs_req_cleanup(&req); if (req.result <= 0) { if (rbuffer.fpos == 0 && uv_guess_handle(2) == UV_TTY) { - /* Read error. Since stderr is a tty we switch to reading from it. This - * is for handling for cases like "foo | xargs vim" because xargs - * redirects stdin from /dev/null. Previously, this was done in ui.c */ + // Read error. Since stderr is a tty we switch to reading from it. This + // is for handling for cases like "foo | xargs vim" because xargs + // redirects stdin from /dev/null. Previously, this was done in ui.c stderr_switch(); } else { eof = true; diff --git a/src/os/input.h b/src/os/input.h index 2493225622..bff66766d7 100644 --- a/src/os/input.h +++ b/src/os/input.h @@ -11,9 +11,8 @@ bool input_ready(void); void input_start(void); void input_stop(void); uint32_t input_read(char *buf, uint32_t count); -int os_inchar(char_u *, int, long, int); +int os_inchar(char_u *, int, int32_t, int); bool os_char_avail(void); void os_breakcheck(void); -#endif - +#endif // NEOVIM_OS_INPUT_H diff --git a/src/os/mem.c b/src/os/mem.c index 037b5931e4..b4335fd179 100644 --- a/src/os/mem.c +++ b/src/os/mem.c @@ -1,26 +1,13 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -/* - * os.c -- OS-level calls to query hardware, etc. - */ +// os.c -- OS-level calls to query hardware, etc. #include <uv.h> #include "os/os.h" -/* - * Return total amount of memory available in Kbyte. - * Doesn't change when memory has been allocated. - */ +// Return total amount of memory available in Kbyte. +// Doesn't change when memory has been allocated. long_u os_total_mem(int special) { - /* We need to return memory in *Kbytes* but uv_get_total_memory() returns the - * number of bytes of total memory. */ + // We need to return memory in *Kbytes* but uv_get_total_memory() returns the + // number of bytes of total memory. return uv_get_total_memory() >> 10; } diff --git a/src/os/os.h b/src/os/os.h index 3510fad9ca..eb25735d6f 100644 --- a/src/os/os.h +++ b/src/os/os.h @@ -4,7 +4,7 @@ #include "vim.h" long_u os_total_mem(int special); -int os_chdir(char *path); +int os_chdir(const char *path); int os_dirname(char_u *buf, size_t len); int os_get_absolute_path(char_u *fname, char_u *buf, int len, int force); int os_is_absolute_path(const char_u *fname); @@ -17,8 +17,8 @@ int os_get_usernames(garray_T *usernames); int os_get_user_name(char *s, size_t len); int os_get_uname(uid_t uid, char *s, size_t len); char *os_get_user_directory(const char *name); -long os_getperm(const char_u *name); +int32_t os_getperm(const char_u *name); int os_setperm(const char_u *name, int perm); -int os_file_exists(char_u *name); +int os_file_exists(const char_u *name); -#endif +#endif // NEOVIM_OS_OS_H diff --git a/src/os/time.c b/src/os/time.c index f14a69264e..c0436595f6 100644 --- a/src/os/time.c +++ b/src/os/time.c @@ -22,9 +22,9 @@ void os_delay(uint64_t ms, bool ignoreinput) int old_tmode; if (ignoreinput) { - /* Go to cooked mode without echo, to allow SIGINT interrupting us - * here. But we don't want QUIT to kill us (CTRL-\ used in a - * shell may produce SIGQUIT). */ + // Go to cooked mode without echo, to allow SIGINT interrupting us + // here. But we don't want QUIT to kill us (CTRL-\ used in a + // shell may produce SIGQUIT). in_os_delay = true; old_tmode = curr_tmode; @@ -43,7 +43,7 @@ void os_delay(uint64_t ms, bool ignoreinput) static void delay(uint64_t ms) { uint64_t hrtime; - int64_t ns = ms * 1000000; /* convert to nanoseconds */ + int64_t ns = ms * 1000000; // convert to nanoseconds uv_mutex_lock(&delay_mutex); diff --git a/src/os/time.h b/src/os/time.h index 1511977a3e..3d35e422e3 100644 --- a/src/os/time.h +++ b/src/os/time.h @@ -7,5 +7,4 @@ void time_init(void); void os_delay(uint64_t ms, bool ignoreinput); -#endif - +#endif // NEOVIM_OS_TIME_H diff --git a/src/os/users.c b/src/os/users.c index 32bc4bb476..9e1389b994 100644 --- a/src/os/users.c +++ b/src/os/users.c @@ -1,15 +1,4 @@ -/* vi:set ts=2 sts=2 sw=2: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -/* - * users.c -- operating system user information - */ +// users.c -- operating system user information #include <uv.h> @@ -20,10 +9,8 @@ # include <pwd.h> #endif -/* - * Initialize users garray and fill it with os usernames. - * Return Ok for success, FAIL for failure. - */ +// Initialize users garray and fill it with os usernames. +// Return Ok for success, FAIL for failure. int os_get_usernames(garray_T *users) { if (users == NULL) { @@ -37,7 +24,7 @@ int os_get_usernames(garray_T *users) setpwent(); while ((pw = getpwent()) != NULL) { - /* pw->pw_name shouldn't be NULL but just in case... */ + // pw->pw_name shouldn't be NULL but just in case... if (pw->pw_name != NULL) { if (ga_grow(users, 1) == FAIL) { return FAIL; @@ -55,20 +42,16 @@ int os_get_usernames(garray_T *users) return OK; } -/* - * Insert user name in s[len]. - * Return OK if a name found. - */ +// Insert user name in s[len]. +// Return OK if a name found. int os_get_user_name(char *s, size_t len) { return os_get_uname(getuid(), s, len); } -/* - * Insert user name for "uid" in s[len]. - * Return OK if a name found. - * If the name is not found, write the uid into s[len] and return FAIL. - */ +// Insert user name for "uid" in s[len]. +// Return OK if a name found. +// If the name is not found, write the uid into s[len] and return FAIL. int os_get_uname(uid_t uid, char *s, size_t len) { #if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID) @@ -81,14 +64,12 @@ int os_get_uname(uid_t uid, char *s, size_t len) } #endif snprintf(s, len, "%d", (int)uid); - return FAIL; // a number is not a name + return FAIL; // a number is not a name } -/* - * Returns the user directory for the given username. - * The caller has to free() the returned string. - * If the username is not found, NULL is returned. - */ +// Returns the user directory for the given username. +// The caller has to free() the returned string. +// If the username is not found, NULL is returned. char *os_get_user_directory(const char *name) { #if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H) |