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/event/loop.h"
|
||||
|
||||
/*
|
||||
* definition of global variables
|
||||
*/
|
||||
|
||||
#define IOSIZE (1024+1) // file I/O and sprintf buffer size
|
||||
|
||||
#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
|
||||
// takes 6 bytes for one cell)
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* TODO(metrix78): Move this to os_defs.h
|
||||
*/
|
||||
// Maximum length of a file path. Make it a bit long, to stay
|
||||
// on the safe side. But not too long to put on the stack.
|
||||
#ifndef MAXPATHL
|
||||
# ifdef MAXPATHLEN
|
||||
# define MAXPATHL MAXPATHLEN
|
||||
@ -108,12 +101,9 @@ typedef enum {
|
||||
* They may have different values when the screen wasn't (re)allocated yet
|
||||
* after setting Rows or Columns (e.g., when starting up).
|
||||
*/
|
||||
|
||||
#define DFLT_COLS 80 /* default value for 'columns' */
|
||||
#define DFLT_ROWS 24 /* default value for 'lines' */
|
||||
|
||||
#define DFLT_COLS 80 // default value for 'columns'
|
||||
#define DFLT_ROWS 24 // default value for 'lines'
|
||||
EXTERN long Rows INIT(= DFLT_ROWS); // nr of rows 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);
|
||||
/* Selected "quit" at the dialog. */
|
||||
|
||||
EXTERN char_u IObuff[IOSIZE]; /* sprintf's are done in this buffer */
|
||||
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 IObuff[IOSIZE]; ///< Buffer for sprintf, I/O, etc.
|
||||
EXTERN char_u NameBuff[MAXPATHL]; ///< Buffer for expanding file names
|
||||
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. */
|
||||
EXTERN int RedrawingDisabled INIT(= 0);
|
||||
|
@ -164,11 +164,11 @@ static char_u *homedir = NULL;
|
||||
|
||||
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);
|
||||
homedir = NULL;
|
||||
|
||||
char_u *var = (char_u *)os_getenv("HOME");
|
||||
const char *var = os_getenv("HOME");
|
||||
|
||||
#ifdef WIN32
|
||||
// Typically, $HOME is not defined on Windows, unless the user has
|
||||
@ -182,10 +182,10 @@ void init_homedir(void)
|
||||
homepath = "\\";
|
||||
}
|
||||
if (homedrive != NULL && strlen(homedrive) + strlen(homepath) < MAXPATHL) {
|
||||
snprintf((char *)NameBuff, MAXPATHL, "%s%s", homedrive, homepath);
|
||||
if (NameBuff[0] != NUL) {
|
||||
var = NameBuff;
|
||||
vim_setenv("HOME", (char *)NameBuff);
|
||||
snprintf(os_buf, MAXPATHL, "%s%s", homedrive, homepath);
|
||||
if (os_buf[0] != NUL) {
|
||||
var = os_buf;
|
||||
vim_setenv("HOME", os_buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -195,17 +195,16 @@ void init_homedir(void)
|
||||
#ifdef UNIX
|
||||
// Change to the directory and get the actual path. This resolves
|
||||
// links. Don't do it when we can't return.
|
||||
if (os_dirname(NameBuff, MAXPATHL) == OK
|
||||
&& os_chdir((char *)NameBuff) == 0) {
|
||||
if (!os_chdir((char *)var) && os_dirname(IObuff, IOSIZE) == OK) {
|
||||
var = IObuff;
|
||||
if (os_dirname((char_u *)os_buf, MAXPATHL) == OK && os_chdir(os_buf) == 0) {
|
||||
if (!os_chdir(var) && os_dirname(IObuff, IOSIZE) == OK) {
|
||||
var = (char *)IObuff;
|
||||
}
|
||||
if (os_chdir((char *)NameBuff) != 0) {
|
||||
if (os_chdir(os_buf) != 0) {
|
||||
EMSG(_(e_prev_dir));
|
||||
}
|
||||
}
|
||||
#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);
|
||||
size_t dirlen = (size_t)(tail - fname);
|
||||
assert(tail >= fname && dirlen + 1 < sizeof(NameBuff));
|
||||
xstrlcpy((char *)NameBuff, fname, dirlen + 1);
|
||||
assert(tail >= fname && dirlen + 1 < sizeof(os_buf));
|
||||
xstrlcpy(os_buf, fname, dirlen + 1);
|
||||
const char *path = os_getenv("PATH");
|
||||
const size_t pathlen = path ? strlen(path) : 0;
|
||||
const size_t newlen = pathlen + dirlen + 2;
|
||||
@ -884,7 +883,7 @@ bool os_setenv_append_path(const char *fname)
|
||||
xstrlcpy(temp, path, newlen);
|
||||
xstrlcat(temp, ENV_SEPSTR, newlen);
|
||||
}
|
||||
xstrlcat(temp, (char *)NameBuff, newlen);
|
||||
xstrlcat(temp, os_buf, newlen);
|
||||
os_setenv("PATH", temp, 1);
|
||||
xfree(temp);
|
||||
return true;
|
||||
|
@ -275,8 +275,8 @@ static bool is_executable(const char *name)
|
||||
static bool is_executable_ext(char *name, const char *pathext)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
xstrlcpy((char *)NameBuff, name, sizeof(NameBuff));
|
||||
char *buf_end = xstrchrnul((char *)NameBuff, '\0');
|
||||
xstrlcpy(os_buf, name, sizeof(os_buf));
|
||||
char *buf_end = xstrchrnul(os_buf, '\0');
|
||||
for (const char *ext = pathext; *ext; ext++) {
|
||||
// Skip the extension if there is no suffix after a '.'.
|
||||
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);
|
||||
STRLCPY(buf_end, ext, ext_end - ext + 1);
|
||||
|
||||
if (is_executable((char *)NameBuff)) {
|
||||
if (is_executable(os_buf)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user