mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
os/*: Use os_buf instead of NameBuff, IObuff.
This commit is contained in:
parent
0c7751f6ab
commit
aa56b24ee6
@ -13,10 +13,6 @@
|
|||||||
#include "nvim/types.h"
|
#include "nvim/types.h"
|
||||||
#include "nvim/event/loop.h"
|
#include "nvim/event/loop.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* definition of global variables
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define IOSIZE (1024+1) // file I/O and sprintf buffer size
|
#define IOSIZE (1024+1) // file I/O and sprintf buffer size
|
||||||
|
|
||||||
#define MAX_MCO 6 // maximum value for 'maxcombine'
|
#define MAX_MCO 6 // maximum value for 'maxcombine'
|
||||||
@ -25,11 +21,8 @@
|
|||||||
# define MSG_BUF_CLEN (MSG_BUF_LEN / 6) // cell length (worst case: utf-8
|
# define MSG_BUF_CLEN (MSG_BUF_LEN / 6) // cell length (worst case: utf-8
|
||||||
// takes 6 bytes for one cell)
|
// takes 6 bytes for one cell)
|
||||||
|
|
||||||
/*
|
// Maximum length of a file path. Make it a bit long, to stay
|
||||||
* Maximum length of a path (for non-unix systems) Make it a bit long, to stay
|
// on the safe side. But not too long to put on the stack.
|
||||||
* on the safe side. But not too long to put on the stack.
|
|
||||||
* TODO(metrix78): Move this to os_defs.h
|
|
||||||
*/
|
|
||||||
#ifndef MAXPATHL
|
#ifndef MAXPATHL
|
||||||
# ifdef MAXPATHLEN
|
# ifdef MAXPATHLEN
|
||||||
# define MAXPATHL MAXPATHLEN
|
# define MAXPATHL MAXPATHLEN
|
||||||
@ -108,12 +101,9 @@ typedef enum {
|
|||||||
* They may have different values when the screen wasn't (re)allocated yet
|
* They may have different values when the screen wasn't (re)allocated yet
|
||||||
* after setting Rows or Columns (e.g., when starting up).
|
* after setting Rows or Columns (e.g., when starting up).
|
||||||
*/
|
*/
|
||||||
|
#define DFLT_COLS 80 // default value for 'columns'
|
||||||
#define DFLT_COLS 80 /* default value for 'columns' */
|
#define DFLT_ROWS 24 // default value for 'lines'
|
||||||
#define DFLT_ROWS 24 /* default value for 'lines' */
|
|
||||||
|
|
||||||
EXTERN long Rows INIT(= DFLT_ROWS); // nr of rows in the screen
|
EXTERN long Rows INIT(= DFLT_ROWS); // nr of rows in the screen
|
||||||
|
|
||||||
EXTERN long Columns INIT(= DFLT_COLS); // nr of columns in the screen
|
EXTERN long Columns INIT(= DFLT_COLS); // nr of columns in the screen
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -889,9 +879,11 @@ EXTERN int swap_exists_action INIT(= SEA_NONE);
|
|||||||
EXTERN int swap_exists_did_quit INIT(= FALSE);
|
EXTERN int swap_exists_did_quit INIT(= FALSE);
|
||||||
/* Selected "quit" at the dialog. */
|
/* Selected "quit" at the dialog. */
|
||||||
|
|
||||||
EXTERN char_u IObuff[IOSIZE]; /* sprintf's are done in this buffer */
|
EXTERN char_u IObuff[IOSIZE]; ///< Buffer for sprintf, I/O, etc.
|
||||||
EXTERN char_u NameBuff[MAXPATHL]; /* buffer for expanding file names */
|
EXTERN char_u NameBuff[MAXPATHL]; ///< Buffer for expanding file names
|
||||||
EXTERN char_u msg_buf[MSG_BUF_LEN]; /* small buffer for messages */
|
EXTERN char_u msg_buf[MSG_BUF_LEN]; ///< Small buffer for messages
|
||||||
|
EXTERN char os_buf[MAX(MAXPATHL, IOSIZE)]; ///< Buffer for the os/ layer
|
||||||
|
|
||||||
|
|
||||||
/* When non-zero, postpone redrawing. */
|
/* When non-zero, postpone redrawing. */
|
||||||
EXTERN int RedrawingDisabled INIT(= 0);
|
EXTERN int RedrawingDisabled INIT(= 0);
|
||||||
|
@ -164,11 +164,11 @@ static char_u *homedir = NULL;
|
|||||||
|
|
||||||
void init_homedir(void)
|
void init_homedir(void)
|
||||||
{
|
{
|
||||||
// In case we are called a second time (when 'encoding' changes).
|
// In case we are called a second time.
|
||||||
xfree(homedir);
|
xfree(homedir);
|
||||||
homedir = NULL;
|
homedir = NULL;
|
||||||
|
|
||||||
char_u *var = (char_u *)os_getenv("HOME");
|
const char *var = os_getenv("HOME");
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// Typically, $HOME is not defined on Windows, unless the user has
|
// Typically, $HOME is not defined on Windows, unless the user has
|
||||||
@ -182,10 +182,10 @@ void init_homedir(void)
|
|||||||
homepath = "\\";
|
homepath = "\\";
|
||||||
}
|
}
|
||||||
if (homedrive != NULL && strlen(homedrive) + strlen(homepath) < MAXPATHL) {
|
if (homedrive != NULL && strlen(homedrive) + strlen(homepath) < MAXPATHL) {
|
||||||
snprintf((char *)NameBuff, MAXPATHL, "%s%s", homedrive, homepath);
|
snprintf(os_buf, MAXPATHL, "%s%s", homedrive, homepath);
|
||||||
if (NameBuff[0] != NUL) {
|
if (os_buf[0] != NUL) {
|
||||||
var = NameBuff;
|
var = os_buf;
|
||||||
vim_setenv("HOME", (char *)NameBuff);
|
vim_setenv("HOME", os_buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,17 +195,16 @@ void init_homedir(void)
|
|||||||
#ifdef UNIX
|
#ifdef UNIX
|
||||||
// Change to the directory and get the actual path. This resolves
|
// Change to the directory and get the actual path. This resolves
|
||||||
// links. Don't do it when we can't return.
|
// links. Don't do it when we can't return.
|
||||||
if (os_dirname(NameBuff, MAXPATHL) == OK
|
if (os_dirname((char_u *)os_buf, MAXPATHL) == OK && os_chdir(os_buf) == 0) {
|
||||||
&& os_chdir((char *)NameBuff) == 0) {
|
if (!os_chdir(var) && os_dirname(IObuff, IOSIZE) == OK) {
|
||||||
if (!os_chdir((char *)var) && os_dirname(IObuff, IOSIZE) == OK) {
|
var = (char *)IObuff;
|
||||||
var = IObuff;
|
|
||||||
}
|
}
|
||||||
if (os_chdir((char *)NameBuff) != 0) {
|
if (os_chdir(os_buf) != 0) {
|
||||||
EMSG(_(e_prev_dir));
|
EMSG(_(e_prev_dir));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
homedir = vim_strsave(var);
|
homedir = vim_strsave((char_u *)var);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -871,8 +870,8 @@ bool os_setenv_append_path(const char *fname)
|
|||||||
}
|
}
|
||||||
const char *tail = (char *)path_tail_with_sep((char_u *)fname);
|
const char *tail = (char *)path_tail_with_sep((char_u *)fname);
|
||||||
size_t dirlen = (size_t)(tail - fname);
|
size_t dirlen = (size_t)(tail - fname);
|
||||||
assert(tail >= fname && dirlen + 1 < sizeof(NameBuff));
|
assert(tail >= fname && dirlen + 1 < sizeof(os_buf));
|
||||||
xstrlcpy((char *)NameBuff, fname, dirlen + 1);
|
xstrlcpy(os_buf, fname, dirlen + 1);
|
||||||
const char *path = os_getenv("PATH");
|
const char *path = os_getenv("PATH");
|
||||||
const size_t pathlen = path ? strlen(path) : 0;
|
const size_t pathlen = path ? strlen(path) : 0;
|
||||||
const size_t newlen = pathlen + dirlen + 2;
|
const size_t newlen = pathlen + dirlen + 2;
|
||||||
@ -884,7 +883,7 @@ bool os_setenv_append_path(const char *fname)
|
|||||||
xstrlcpy(temp, path, newlen);
|
xstrlcpy(temp, path, newlen);
|
||||||
xstrlcat(temp, ENV_SEPSTR, newlen);
|
xstrlcat(temp, ENV_SEPSTR, newlen);
|
||||||
}
|
}
|
||||||
xstrlcat(temp, (char *)NameBuff, newlen);
|
xstrlcat(temp, os_buf, newlen);
|
||||||
os_setenv("PATH", temp, 1);
|
os_setenv("PATH", temp, 1);
|
||||||
xfree(temp);
|
xfree(temp);
|
||||||
return true;
|
return true;
|
||||||
|
@ -275,8 +275,8 @@ static bool is_executable(const char *name)
|
|||||||
static bool is_executable_ext(char *name, const char *pathext)
|
static bool is_executable_ext(char *name, const char *pathext)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
xstrlcpy((char *)NameBuff, name, sizeof(NameBuff));
|
xstrlcpy(os_buf, name, sizeof(os_buf));
|
||||||
char *buf_end = xstrchrnul((char *)NameBuff, '\0');
|
char *buf_end = xstrchrnul(os_buf, '\0');
|
||||||
for (const char *ext = pathext; *ext; ext++) {
|
for (const char *ext = pathext; *ext; ext++) {
|
||||||
// Skip the extension if there is no suffix after a '.'.
|
// Skip the extension if there is no suffix after a '.'.
|
||||||
if (ext[0] == '.' && (ext[1] == '\0' || ext[1] == ENV_SEPCHAR)) {
|
if (ext[0] == '.' && (ext[1] == '\0' || ext[1] == ENV_SEPCHAR)) {
|
||||||
@ -287,7 +287,7 @@ static bool is_executable_ext(char *name, const char *pathext)
|
|||||||
const char *ext_end = xstrchrnul(ext, ENV_SEPCHAR);
|
const char *ext_end = xstrchrnul(ext, ENV_SEPCHAR);
|
||||||
STRLCPY(buf_end, ext, ext_end - ext + 1);
|
STRLCPY(buf_end, ext, ext_end - ext + 1);
|
||||||
|
|
||||||
if (is_executable((char *)NameBuff)) {
|
if (is_executable(os_buf)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user