mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 20:38:18 +00:00
Address clint warnings and other style issues.
* Add const. * Fix conditions (move && from end to start of line). * Use int32_t instead of long. * Use //-style comments.
This commit is contained in:

committed by
Thiago de Arruda

parent
5762c4e528
commit
4e29a820b6
19
src/os/env.c
19
src/os/env.c
@@ -1,15 +1,4 @@
|
|||||||
/* vi:set ts=2 sts=2 sw=2:
|
// env.c -- environment variable access
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <uv.h>
|
#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)
|
char *os_getenvname_at_index(size_t index)
|
||||||
{
|
{
|
||||||
# if defined(AMIGA) || defined(__MRC__) || defined(__SC__)
|
# 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;
|
return NULL;
|
||||||
# else
|
# else
|
||||||
# if defined(HAVE__NSGETENVIRON)
|
# if defined(HAVE__NSGETENVIRON)
|
||||||
char **environ = *_NSGetEnviron();
|
char **environ = *_NSGetEnviron();
|
||||||
# elif !defined(__WIN32__)
|
# 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;
|
extern char **environ;
|
||||||
# endif
|
# endif
|
||||||
// check if index is inside the environ array
|
// check if index is inside the environ array
|
||||||
|
@@ -13,23 +13,23 @@ static void timer_prepare_cb(uv_prepare_t *, int);
|
|||||||
|
|
||||||
void event_init()
|
void event_init()
|
||||||
{
|
{
|
||||||
/* Initialize input events */
|
// Initialize input events
|
||||||
input_init();
|
input_init();
|
||||||
/* Timer to wake the event loop if a timeout argument is passed to
|
// Timer to wake the event loop if a timeout argument is passed to
|
||||||
* `event_poll` */
|
// `event_poll`
|
||||||
uv_timer_init(uv_default_loop(), &timer);
|
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);
|
uv_prepare_init(uv_default_loop(), &timer_prepare);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for some event */
|
// Wait for some event
|
||||||
bool event_poll(int32_t ms)
|
bool event_poll(int32_t ms)
|
||||||
{
|
{
|
||||||
bool timed_out;
|
bool timed_out;
|
||||||
uv_run_mode run_mode = UV_RUN_ONCE;
|
uv_run_mode run_mode = UV_RUN_ONCE;
|
||||||
|
|
||||||
if (input_ready()) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,42 +37,39 @@ bool event_poll(int32_t ms)
|
|||||||
timed_out = false;
|
timed_out = false;
|
||||||
|
|
||||||
if (ms > 0) {
|
if (ms > 0) {
|
||||||
/* Timeout passed as argument to the timer */
|
// Timeout passed as argument to the timer
|
||||||
timer.data = &timed_out;
|
timer.data = &timed_out;
|
||||||
/* We only start the timer after the loop is running, for that we
|
// We only start the timer after the loop is running, for that we
|
||||||
* use an prepare handle(pass the interval as data to it) */
|
// use an prepare handle(pass the interval as data to it)
|
||||||
timer_prepare.data = &ms;
|
timer_prepare.data = &ms;
|
||||||
uv_prepare_start(&timer_prepare, timer_prepare_cb);
|
uv_prepare_start(&timer_prepare, timer_prepare_cb);
|
||||||
} else if (ms == 0) {
|
} else if (ms == 0) {
|
||||||
/*
|
// For ms == 0, we need to do a non-blocking event poll by
|
||||||
* For ms == 0, we need to do a non-blocking event poll by
|
// setting the run mode to UV_RUN_NOWAIT.
|
||||||
* setting the run mode to UV_RUN_NOWAIT.
|
|
||||||
*/
|
|
||||||
run_mode = UV_RUN_NOWAIT;
|
run_mode = UV_RUN_NOWAIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* Run one event loop iteration, blocking for events if run_mode is
|
// Run one event loop iteration, blocking for events if run_mode is
|
||||||
* UV_RUN_ONCE */
|
// UV_RUN_ONCE
|
||||||
uv_run(uv_default_loop(), run_mode);
|
uv_run(uv_default_loop(), run_mode);
|
||||||
} while (
|
} while (
|
||||||
/* Continue running if ... */
|
// Continue running if ...
|
||||||
!input_ready() && /* ... we have no input */
|
!input_ready() // ... we have no input
|
||||||
run_mode != UV_RUN_NOWAIT && /* ... ms != 0 */
|
&& run_mode != UV_RUN_NOWAIT // ... ms != 0
|
||||||
!timed_out /* ... we didn't get a timeout */
|
&& !timed_out); // ... we didn't get a timeout
|
||||||
);
|
|
||||||
|
|
||||||
input_stop();
|
input_stop();
|
||||||
|
|
||||||
if (ms > 0) {
|
if (ms > 0) {
|
||||||
/* Stop the timer */
|
// Stop the timer
|
||||||
uv_timer_stop(&timer);
|
uv_timer_stop(&timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return input_ready();
|
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)
|
static void timer_cb(uv_timer_t *handle, int status)
|
||||||
{
|
{
|
||||||
*((bool *)handle->data) = true;
|
*((bool *)handle->data) = true;
|
||||||
|
@@ -7,5 +7,5 @@
|
|||||||
void event_init(void);
|
void event_init(void);
|
||||||
bool event_poll(int32_t ms);
|
bool event_poll(int32_t ms);
|
||||||
|
|
||||||
#endif
|
#endif // NEOVIM_OS_EVENT_H
|
||||||
|
|
||||||
|
162
src/os/fs.c
162
src/os/fs.c
@@ -1,15 +1,4 @@
|
|||||||
/* vi:set ts=2 sts=2 sw=2:
|
// fs.c -- filesystem access
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
@@ -18,7 +7,7 @@
|
|||||||
#include "misc1.h"
|
#include "misc1.h"
|
||||||
#include "misc2.h"
|
#include "misc2.h"
|
||||||
|
|
||||||
int os_chdir(char *path) {
|
int os_chdir(const char *path) {
|
||||||
if (p_verbose >= 5) {
|
if (p_verbose >= 5) {
|
||||||
verbose_enter();
|
verbose_enter();
|
||||||
smsg((char_u *)"chdir(%s)", path);
|
smsg((char_u *)"chdir(%s)", path);
|
||||||
@@ -27,10 +16,8 @@ int os_chdir(char *path) {
|
|||||||
return uv_chdir(path);
|
return uv_chdir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Get name of current directory into buffer 'buf' of length 'len' bytes.
|
||||||
* Get name of current directory into buffer 'buf' of length 'len' bytes.
|
// Return OK for success, FAIL for failure.
|
||||||
* Return OK for success, FAIL for failure.
|
|
||||||
*/
|
|
||||||
int os_dirname(char_u *buf, size_t len)
|
int os_dirname(char_u *buf, size_t len)
|
||||||
{
|
{
|
||||||
assert(buf && len);
|
assert(buf && len);
|
||||||
@@ -43,44 +30,42 @@ int os_dirname(char_u *buf, size_t len)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Get the absolute name of the given relative directory.
|
||||||
* Get the absolute name of the given relative directory.
|
//
|
||||||
*
|
// parameter directory: Directory name, relative to current directory.
|
||||||
* parameter directory: Directory name, relative to current directory.
|
// return FAIL for failure, OK for success
|
||||||
* return FAIL for failure, OK for success
|
|
||||||
*/
|
|
||||||
int os_full_dir_name(char *directory, char *buffer, int len)
|
int os_full_dir_name(char *directory, char *buffer, int len)
|
||||||
{
|
{
|
||||||
int retval = OK;
|
int retval = OK;
|
||||||
|
|
||||||
if(STRLEN(directory) == 0) {
|
if (STRLEN(directory) == 0) {
|
||||||
return os_dirname((char_u *) buffer, len);
|
return os_dirname((char_u *) buffer, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
char old_dir[MAXPATHL];
|
char old_dir[MAXPATHL];
|
||||||
|
|
||||||
/* Get current directory name. */
|
// Get current directory name.
|
||||||
if (os_dirname((char_u *) old_dir, MAXPATHL) == FAIL) {
|
if (os_dirname((char_u *) old_dir, MAXPATHL) == FAIL) {
|
||||||
return 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) {
|
if (os_chdir(old_dir) != 0) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (os_chdir(directory) != 0) {
|
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;
|
retval = FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval == FAIL || os_dirname((char_u *) buffer, len) == 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;
|
retval = FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (os_chdir(old_dir) != 0) {
|
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;
|
retval = FAIL;
|
||||||
EMSG(_(e_prev_dir));
|
EMSG(_(e_prev_dir));
|
||||||
}
|
}
|
||||||
@@ -88,38 +73,36 @@ int os_full_dir_name(char *directory, char *buffer, int len)
|
|||||||
return retval;
|
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 append_path(char *path, const char *to_append, int max_len)
|
||||||
{
|
{
|
||||||
int current_length = STRLEN(path);
|
int current_length = STRLEN(path);
|
||||||
int to_append_length = STRLEN(to_append);
|
int to_append_length = STRLEN(to_append);
|
||||||
|
|
||||||
/* Do not append empty strings. */
|
// Do not append empty strings.
|
||||||
if (to_append_length == 0) {
|
if (to_append_length == 0) {
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do not append a dot. */
|
// Do not append a dot.
|
||||||
if (STRCMP(to_append, ".") == 0) {
|
if (STRCMP(to_append, ".") == 0) {
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Glue both paths with a slash. */
|
// Glue both paths with a slash.
|
||||||
if (current_length > 0 && path[current_length-1] != '/') {
|
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. */
|
// +1 for the NUL at the end.
|
||||||
if (current_length +1 > max_len) {
|
if (current_length + 1 > max_len) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
STRCAT(path, "/");
|
STRCAT(path, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* +1 for the NUL at the end. */
|
// +1 for the NUL at the end.
|
||||||
if (current_length + to_append_length +1 > max_len) {
|
if (current_length + to_append_length + 1 > max_len) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,14 +110,12 @@ int append_path(char *path, const char *to_append, int max_len)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Get absolute file name into "buf[len]".
|
||||||
* Get absolute file name into "buf[len]".
|
//
|
||||||
*
|
// parameter force: Also expand when the given path in fname is already
|
||||||
* parameter force: Also expand when the given path in fname is already
|
// absolute.
|
||||||
* absolute.
|
//
|
||||||
*
|
// return FAIL for failure, OK for success
|
||||||
* return FAIL for failure, OK for success
|
|
||||||
*/
|
|
||||||
int os_get_absolute_path(char_u *fname, char_u *buf, int len, int force)
|
int os_get_absolute_path(char_u *fname, char_u *buf, int len, int force)
|
||||||
{
|
{
|
||||||
char_u *p;
|
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 relative_directory[len];
|
||||||
char *end_of_path = (char *) fname;
|
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 (force || !os_is_absolute_path(fname)) {
|
||||||
if ((p = vim_strrchr(fname, '/')) != NULL) {
|
if ((p = vim_strrchr(fname, '/')) != NULL) {
|
||||||
|
|
||||||
STRNCPY(relative_directory, fname, p-fname);
|
STRNCPY(relative_directory, fname, p-fname);
|
||||||
relative_directory[p-fname] = NUL;
|
relative_directory[p-fname] = NUL;
|
||||||
end_of_path = (char *) (p + 1);
|
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 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)
|
int os_is_absolute_path(const char_u *fname)
|
||||||
{
|
{
|
||||||
return *fname == '/' || *fname == '~';
|
return *fname == '/' || *fname == '~';
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// return TRUE if "name" is a directory
|
||||||
* return TRUE if "name" is a directory
|
// return FALSE if "name" is not a directory
|
||||||
* return FALSE if "name" is not a directory
|
// return FALSE for error
|
||||||
* return FALSE for error
|
|
||||||
*/
|
|
||||||
int os_isdir(const char_u *name)
|
int os_isdir(const char_u *name)
|
||||||
{
|
{
|
||||||
long mode = os_getperm(name);
|
int32_t mode = os_getperm(name);
|
||||||
if (mode < 0) {
|
if (mode < 0) {
|
||||||
return FALSE;
|
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(const char_u *name);
|
||||||
static int is_executable_in_path(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
|
||||||
* Return TRUE if "name" is executable and can be found in $PATH, is absolute
|
// or relative to current dir, FALSE if not.
|
||||||
* or relative to current dir, FALSE if not.
|
|
||||||
*/
|
|
||||||
int os_can_exe(const char_u *name)
|
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) ||
|
if (os_is_absolute_path(name) ||
|
||||||
(name[0] == '.' && (name[1] == '/' ||
|
(name[0] == '.' && (name[1] == '/' ||
|
||||||
(name[1] == '.' && name[2] == '/')))) {
|
(name[1] == '.' && name[2] == '/')))) {
|
||||||
@@ -208,13 +182,11 @@ int os_can_exe(const char_u *name)
|
|||||||
return is_executable_in_path(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.
|
||||||
* exist.
|
|
||||||
*/
|
|
||||||
static int is_executable(const char_u *name)
|
static int is_executable(const char_u *name)
|
||||||
{
|
{
|
||||||
long mode = os_getperm(name);
|
int32_t mode = os_getperm(name);
|
||||||
|
|
||||||
if (mode < 0) {
|
if (mode < 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -227,14 +199,12 @@ static int is_executable(const char_u *name)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Return TRUE if "name" can be found in $PATH and executed, FALSE if not or an
|
||||||
* Return TRUE if "name" can be found in $PATH and executed, FALSE if not or an
|
// error occurs.
|
||||||
* error occurs.
|
|
||||||
*/
|
|
||||||
static int is_executable_in_path(const char_u *name)
|
static int is_executable_in_path(const char_u *name)
|
||||||
{
|
{
|
||||||
const char *path = getenv("PATH");
|
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) {
|
if (path == NULL || *path == NUL) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -245,29 +215,27 @@ static int is_executable_in_path(const char_u *name)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Walk through all entries in $PATH to check if "name" exists there and
|
||||||
* Walk through all entries in $PATH to check if "name" exists there and
|
// is an executable file.
|
||||||
* is an executable file.
|
|
||||||
*/
|
|
||||||
for (;; ) {
|
for (;; ) {
|
||||||
const char *e = strchr(path, ':');
|
const char *e = strchr(path, ':');
|
||||||
if (e == NULL) {
|
if (e == NULL) {
|
||||||
e = path + STRLEN(path);
|
e = path + STRLEN(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Glue together the given directory from $PATH with name and save into
|
// Glue together the given directory from $PATH with name and save into
|
||||||
* buf. */
|
// buf.
|
||||||
vim_strncpy(buf, (char_u *) path, e - path);
|
vim_strncpy(buf, (char_u *) path, e - path);
|
||||||
append_path((char *) buf, (const char *) name, buf_len);
|
append_path((char *) buf, (const char *) name, buf_len);
|
||||||
|
|
||||||
if (is_executable(buf)) {
|
if (is_executable(buf)) {
|
||||||
/* Found our executable. Free buf and return. */
|
// Found our executable. Free buf and return.
|
||||||
vim_free(buf);
|
vim_free(buf);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*e != ':') {
|
if (*e != ':') {
|
||||||
/* End of $PATH without finding any executable called name. */
|
// End of $PATH without finding any executable called name.
|
||||||
vim_free(buf);
|
vim_free(buf);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -275,33 +243,30 @@ static int is_executable_in_path(const char_u *name)
|
|||||||
path = e + 1;
|
path = e + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We should never get to this point. */
|
// We should never get to this point.
|
||||||
assert(false);
|
assert(false);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Get file permissions for 'name'.
|
||||||
* Get file permissions for 'name'.
|
// Returns -1 when it doesn't exist.
|
||||||
* Returns -1 when it doesn't exist.
|
int32_t os_getperm(const char_u *name)
|
||||||
*/
|
|
||||||
long os_getperm(const char_u *name)
|
|
||||||
{
|
{
|
||||||
uv_fs_t request;
|
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;
|
uint64_t mode = request.statbuf.st_mode;
|
||||||
uv_fs_req_cleanup(&request);
|
uv_fs_req_cleanup(&request);
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return (long) mode;
|
return (int32_t) mode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Set file permission for 'name' to 'perm'.
|
||||||
* Set file permission for 'name' to 'perm'.
|
// Returns FAIL for failure, OK otherwise.
|
||||||
* Returns FAIL for failure, OK otherwise.
|
|
||||||
*/
|
|
||||||
int os_setperm(const char_u *name, int perm)
|
int os_setperm(const char_u *name, int perm)
|
||||||
{
|
{
|
||||||
uv_fs_t request;
|
uv_fs_t request;
|
||||||
@@ -316,13 +281,12 @@ int os_setperm(const char_u *name, int perm)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// return TRUE if "name" exists.
|
||||||
* return TRUE if "name" exists.
|
int os_file_exists(const char_u *name)
|
||||||
*/
|
|
||||||
int os_file_exists(char_u *name)
|
|
||||||
{
|
{
|
||||||
uv_fs_t request;
|
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);
|
uv_fs_req_cleanup(&request);
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
|
@@ -31,8 +31,8 @@ typedef struct {
|
|||||||
|
|
||||||
static ReadBuffer rbuffer;
|
static ReadBuffer rbuffer;
|
||||||
static uv_pipe_t read_stream;
|
static uv_pipe_t read_stream;
|
||||||
/* Use an idle handle to make reading from the fs look like a normal libuv
|
// Use an idle handle to make reading from the fs look like a normal libuv
|
||||||
* event */
|
// event
|
||||||
static uv_idle_t fread_idle;
|
static uv_idle_t fread_idle;
|
||||||
static uv_handle_type read_channel_type;
|
static uv_handle_type read_channel_type;
|
||||||
static bool eof = false;
|
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()
|
bool input_ready()
|
||||||
{
|
{
|
||||||
return rbuffer.rpos < rbuffer.wpos || eof;
|
return rbuffer.rpos < rbuffer.wpos || eof;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Listen for input */
|
// Listen for input
|
||||||
void input_start()
|
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.len = READ_BUFFER_LENGTH - rbuffer.wpos;
|
||||||
rbuffer.uvbuf.base = (char *)(rbuffer.data + rbuffer.wpos);
|
rbuffer.uvbuf.base = (char *)(rbuffer.data + rbuffer.wpos);
|
||||||
|
|
||||||
if (read_channel_type == UV_FILE) {
|
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);
|
uv_idle_start(&fread_idle, fread_idle_cb);
|
||||||
} else {
|
} else {
|
||||||
/* Start reading */
|
// Start reading
|
||||||
rbuffer.reading = false;
|
rbuffer.reading = false;
|
||||||
uv_read_start((uv_stream_t *)&read_stream, alloc_cb, read_cb);
|
uv_read_start((uv_stream_t *)&read_stream, alloc_cb, read_cb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop listening for input */
|
// Stop listening for input
|
||||||
void input_stop()
|
void input_stop()
|
||||||
{
|
{
|
||||||
if (read_channel_type == UV_FILE) {
|
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 input_read(char *buf, uint32_t count)
|
||||||
{
|
{
|
||||||
uint32_t read_count = rbuffer.wpos - rbuffer.rpos;
|
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) {
|
if (rbuffer.wpos == READ_BUFFER_LENGTH) {
|
||||||
/* `wpos` is at the end of the buffer, so free some space by moving unread
|
// `wpos` is at the end of the buffer, so free some space by moving unread
|
||||||
* data... */
|
// data...
|
||||||
memmove(
|
memmove(
|
||||||
rbuffer.data,/* ...To the beginning of the buffer(rpos 0) */
|
rbuffer.data, // ...To the beginning of the buffer(rpos 0)
|
||||||
rbuffer.data + rbuffer.rpos,/* ...From the first unread position */
|
rbuffer.data + rbuffer.rpos, // ...From the first unread position
|
||||||
rbuffer.wpos - rbuffer.rpos/* ...By the number of unread bytes */
|
rbuffer.wpos - rbuffer.rpos); // ...By the number of unread bytes
|
||||||
);
|
|
||||||
rbuffer.wpos -= rbuffer.rpos;
|
rbuffer.wpos -= rbuffer.rpos;
|
||||||
rbuffer.rpos = 0;
|
rbuffer.rpos = 0;
|
||||||
}
|
}
|
||||||
@@ -121,8 +120,8 @@ uint32_t input_read(char *buf, uint32_t count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Low level input function. */
|
// Low level input function.
|
||||||
int os_inchar(char_u *buf, int maxlen, long ms, int tb_change_cnt)
|
int os_inchar(char_u *buf, int maxlen, int32_t ms, int tb_change_cnt)
|
||||||
{
|
{
|
||||||
InbufPollResult result;
|
InbufPollResult result;
|
||||||
|
|
||||||
@@ -132,8 +131,8 @@ int os_inchar(char_u *buf, int maxlen, long ms, int tb_change_cnt)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((result = inbuf_poll(p_ut)) != kInputAvail) {
|
if ((result = inbuf_poll(p_ut)) != kInputAvail) {
|
||||||
if (trigger_cursorhold() && maxlen >= 3 &&
|
if (trigger_cursorhold() && maxlen >= 3
|
||||||
!typebuf_changed(tb_change_cnt)) {
|
&& !typebuf_changed(tb_change_cnt)) {
|
||||||
buf[0] = K_SPECIAL;
|
buf[0] = K_SPECIAL;
|
||||||
buf[1] = KS_EXTRA;
|
buf[1] = KS_EXTRA;
|
||||||
buf[2] = KE_CURSORHOLD;
|
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))
|
if (typebuf_changed(tb_change_cnt))
|
||||||
return 0;
|
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);
|
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()
|
bool os_char_avail()
|
||||||
{
|
{
|
||||||
return inbuf_poll(0) == kInputAvail;
|
return inbuf_poll(0) == kInputAvail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Check for CTRL-C typed by reading all available characters.
|
||||||
* Check for CTRL-C typed by reading all available characters.
|
// In cooked mode we should get SIGINT, no need to check.
|
||||||
* In cooked mode we should get SIGINT, no need to check.
|
|
||||||
*/
|
|
||||||
void os_breakcheck()
|
void os_breakcheck()
|
||||||
{
|
{
|
||||||
if (curr_tmode == TMODE_RAW && event_poll(0))
|
if (curr_tmode == TMODE_RAW && event_poll(0))
|
||||||
fill_input_buf(FALSE);
|
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)
|
static InbufPollResult inbuf_poll(int32_t ms)
|
||||||
{
|
{
|
||||||
if (input_available())
|
if (input_available())
|
||||||
@@ -192,23 +189,23 @@ static InbufPollResult inbuf_poll(int32_t ms)
|
|||||||
static void stderr_switch()
|
static void stderr_switch()
|
||||||
{
|
{
|
||||||
int mode = cur_tmode;
|
int mode = cur_tmode;
|
||||||
/* We probably set the wrong file descriptor to raw mode. Switch back to
|
// We probably set the wrong file descriptor to raw mode. Switch back to
|
||||||
* cooked mode */
|
// cooked mode
|
||||||
settmode(TMODE_COOK);
|
settmode(TMODE_COOK);
|
||||||
/* Stop the idle handle */
|
// Stop the idle handle
|
||||||
uv_idle_stop(&fread_idle);
|
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;
|
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_init(uv_default_loop(), &read_stream, 0);
|
||||||
uv_pipe_open(&read_stream, read_cmd_fd);
|
uv_pipe_open(&read_stream, read_cmd_fd);
|
||||||
uv_read_start((uv_stream_t *)&read_stream, alloc_cb, read_cb);
|
uv_read_start((uv_stream_t *)&read_stream, alloc_cb, read_cb);
|
||||||
rbuffer.reading = false;
|
rbuffer.reading = false;
|
||||||
/* Set the mode back to what it was */
|
// Set the mode back to what it was
|
||||||
settmode(mode);
|
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)
|
static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf)
|
||||||
{
|
{
|
||||||
if (rbuffer.reading) {
|
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->base = rbuffer.uvbuf.base;
|
||||||
buf->len = rbuffer.uvbuf.len;
|
buf->len = rbuffer.uvbuf.len;
|
||||||
/* Avoid `alloc_cb`, `alloc_cb` sequences on windows */
|
// Avoid `alloc_cb`, `alloc_cb` sequences on windows
|
||||||
rbuffer.reading = true;
|
rbuffer.reading = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Callback invoked by libuv after it copies the data into the buffer provided
|
||||||
* 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
|
||||||
* by `alloc_cb`. This is also called on EOF or when `alloc_cb` returns a
|
// 0-length buffer.
|
||||||
* 0-length buffer.
|
|
||||||
*/
|
|
||||||
static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf)
|
static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf)
|
||||||
{
|
{
|
||||||
if (cnt <= 0) {
|
if (cnt <= 0) {
|
||||||
if (cnt != UV_ENOBUFS) {
|
if (cnt != UV_ENOBUFS) {
|
||||||
/* Read error or EOF, either way vim must exit */
|
// Read error or EOF, either way vim must exit
|
||||||
eof = true;
|
eof = true;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Data was already written, so all we need is to update 'wpos' to reflect
|
// Data was already written, so all we need is to update 'wpos' to reflect
|
||||||
* the space actually used in the buffer. */
|
// the space actually used in the buffer.
|
||||||
rbuffer.wpos += cnt;
|
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)
|
static void fread_idle_cb(uv_idle_t *handle, int status)
|
||||||
{
|
{
|
||||||
uv_fs_t req;
|
uv_fs_t req;
|
||||||
|
|
||||||
/* Synchronous read */
|
// Synchronous read
|
||||||
uv_fs_read(
|
uv_fs_read(
|
||||||
uv_default_loop(),
|
uv_default_loop(),
|
||||||
&req,
|
&req,
|
||||||
@@ -255,16 +250,15 @@ static void fread_idle_cb(uv_idle_t *handle, int status)
|
|||||||
&rbuffer.uvbuf,
|
&rbuffer.uvbuf,
|
||||||
1,
|
1,
|
||||||
rbuffer.fpos,
|
rbuffer.fpos,
|
||||||
NULL
|
NULL);
|
||||||
);
|
|
||||||
|
|
||||||
uv_fs_req_cleanup(&req);
|
uv_fs_req_cleanup(&req);
|
||||||
|
|
||||||
if (req.result <= 0) {
|
if (req.result <= 0) {
|
||||||
if (rbuffer.fpos == 0 && uv_guess_handle(2) == UV_TTY) {
|
if (rbuffer.fpos == 0 && uv_guess_handle(2) == UV_TTY) {
|
||||||
/* Read error. Since stderr is a tty we switch to reading from it. This
|
// 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
|
// is for handling for cases like "foo | xargs vim" because xargs
|
||||||
* redirects stdin from /dev/null. Previously, this was done in ui.c */
|
// redirects stdin from /dev/null. Previously, this was done in ui.c
|
||||||
stderr_switch();
|
stderr_switch();
|
||||||
} else {
|
} else {
|
||||||
eof = true;
|
eof = true;
|
||||||
|
@@ -11,9 +11,8 @@ bool input_ready(void);
|
|||||||
void input_start(void);
|
void input_start(void);
|
||||||
void input_stop(void);
|
void input_stop(void);
|
||||||
uint32_t input_read(char *buf, uint32_t count);
|
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);
|
bool os_char_avail(void);
|
||||||
void os_breakcheck(void);
|
void os_breakcheck(void);
|
||||||
|
|
||||||
#endif
|
#endif // NEOVIM_OS_INPUT_H
|
||||||
|
|
||||||
|
23
src/os/mem.c
23
src/os/mem.c
@@ -1,26 +1,13 @@
|
|||||||
/* vi:set ts=8 sts=4 sw=4:
|
// os.c -- OS-level calls to query hardware, etc.
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
#include "os/os.h"
|
#include "os/os.h"
|
||||||
|
|
||||||
/*
|
// Return total amount of memory available in Kbyte.
|
||||||
* Return total amount of memory available in Kbyte.
|
// Doesn't change when memory has been allocated.
|
||||||
* Doesn't change when memory has been allocated.
|
|
||||||
*/
|
|
||||||
long_u os_total_mem(int special) {
|
long_u os_total_mem(int special) {
|
||||||
/* We need to return memory in *Kbytes* but uv_get_total_memory() returns the
|
// We need to return memory in *Kbytes* but uv_get_total_memory() returns the
|
||||||
* number of bytes of total memory. */
|
// number of bytes of total memory.
|
||||||
return uv_get_total_memory() >> 10;
|
return uv_get_total_memory() >> 10;
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
#include "vim.h"
|
#include "vim.h"
|
||||||
|
|
||||||
long_u os_total_mem(int special);
|
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_dirname(char_u *buf, size_t len);
|
||||||
int os_get_absolute_path(char_u *fname, char_u *buf, int len, int force);
|
int os_get_absolute_path(char_u *fname, char_u *buf, int len, int force);
|
||||||
int os_is_absolute_path(const char_u *fname);
|
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_user_name(char *s, size_t len);
|
||||||
int os_get_uname(uid_t uid, 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);
|
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_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
|
||||||
|
@@ -22,9 +22,9 @@ void os_delay(uint64_t ms, bool ignoreinput)
|
|||||||
int old_tmode;
|
int old_tmode;
|
||||||
|
|
||||||
if (ignoreinput) {
|
if (ignoreinput) {
|
||||||
/* Go to cooked mode without echo, to allow SIGINT interrupting us
|
// 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
|
// here. But we don't want QUIT to kill us (CTRL-\ used in a
|
||||||
* shell may produce SIGQUIT). */
|
// shell may produce SIGQUIT).
|
||||||
in_os_delay = true;
|
in_os_delay = true;
|
||||||
old_tmode = curr_tmode;
|
old_tmode = curr_tmode;
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ void os_delay(uint64_t ms, bool ignoreinput)
|
|||||||
static void delay(uint64_t ms)
|
static void delay(uint64_t ms)
|
||||||
{
|
{
|
||||||
uint64_t hrtime;
|
uint64_t hrtime;
|
||||||
int64_t ns = ms * 1000000; /* convert to nanoseconds */
|
int64_t ns = ms * 1000000; // convert to nanoseconds
|
||||||
|
|
||||||
uv_mutex_lock(&delay_mutex);
|
uv_mutex_lock(&delay_mutex);
|
||||||
|
|
||||||
|
@@ -7,5 +7,4 @@
|
|||||||
void time_init(void);
|
void time_init(void);
|
||||||
void os_delay(uint64_t ms, bool ignoreinput);
|
void os_delay(uint64_t ms, bool ignoreinput);
|
||||||
|
|
||||||
#endif
|
#endif // NEOVIM_OS_TIME_H
|
||||||
|
|
||||||
|
@@ -1,15 +1,4 @@
|
|||||||
/* vi:set ts=2 sts=2 sw=2:
|
// users.c -- operating system user information
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
@@ -20,10 +9,8 @@
|
|||||||
# include <pwd.h>
|
# include <pwd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
// Initialize users garray and fill it with os usernames.
|
||||||
* Initialize users garray and fill it with os usernames.
|
// Return Ok for success, FAIL for failure.
|
||||||
* Return Ok for success, FAIL for failure.
|
|
||||||
*/
|
|
||||||
int os_get_usernames(garray_T *users)
|
int os_get_usernames(garray_T *users)
|
||||||
{
|
{
|
||||||
if (users == NULL) {
|
if (users == NULL) {
|
||||||
@@ -37,7 +24,7 @@ int os_get_usernames(garray_T *users)
|
|||||||
|
|
||||||
setpwent();
|
setpwent();
|
||||||
while ((pw = getpwent()) != NULL) {
|
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 (pw->pw_name != NULL) {
|
||||||
if (ga_grow(users, 1) == FAIL) {
|
if (ga_grow(users, 1) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@@ -55,20 +42,16 @@ int os_get_usernames(garray_T *users)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Insert user name in s[len].
|
||||||
* Insert user name in s[len].
|
// Return OK if a name found.
|
||||||
* Return OK if a name found.
|
|
||||||
*/
|
|
||||||
int os_get_user_name(char *s, size_t len)
|
int os_get_user_name(char *s, size_t len)
|
||||||
{
|
{
|
||||||
return os_get_uname(getuid(), s, len);
|
return os_get_uname(getuid(), s, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Insert user name for "uid" in s[len].
|
||||||
* Insert user name for "uid" in s[len].
|
// Return OK if a name found.
|
||||||
* Return OK if a name found.
|
// If the name is not found, write the uid into s[len] and return FAIL.
|
||||||
* 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)
|
int os_get_uname(uid_t uid, char *s, size_t len)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID)
|
#if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID)
|
||||||
@@ -84,11 +67,9 @@ int os_get_uname(uid_t uid, char *s, size_t len)
|
|||||||
return FAIL; // a number is not a name
|
return FAIL; // a number is not a name
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Returns the user directory for the given username.
|
||||||
* Returns the user directory for the given username.
|
// The caller has to free() the returned string.
|
||||||
* The caller has to free() the returned string.
|
// If the username is not found, NULL is returned.
|
||||||
* If the username is not found, NULL is returned.
|
|
||||||
*/
|
|
||||||
char *os_get_user_directory(const char *name)
|
char *os_get_user_directory(const char *name)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
|
#if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
|
||||||
|
@@ -16,7 +16,7 @@ int os_dirname(char_u *buf, int len);
|
|||||||
int os_isdir(char_u * name);
|
int os_isdir(char_u * name);
|
||||||
int is_executable(char_u *name);
|
int is_executable(char_u *name);
|
||||||
int os_can_exe(char_u *name);
|
int os_can_exe(char_u *name);
|
||||||
long os_getperm(char_u *name);
|
int32_t os_getperm(char_u *name);
|
||||||
int os_setperm(char_u *name, long perm);
|
int os_setperm(char_u *name, long perm);
|
||||||
int os_file_exists(const char_u *name);
|
int os_file_exists(const char_u *name);
|
||||||
]]
|
]]
|
||||||
|
Reference in New Issue
Block a user