diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-05-24 19:18:11 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-05-24 19:18:11 +0000 |
commit | ff7ed8f586589d620a806c3758fac4a47a8e7e15 (patch) | |
tree | 729bbcb92231538fa61dab6c3d890b025484b7f5 /src/nvim/os | |
parent | 376914f419eb08fdf4c1a63a77e1f035898a0f10 (diff) | |
parent | 28c04948a1c887a1cc0cb64de79fa32631700466 (diff) | |
download | rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.gz rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.bz2 rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.zip |
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'src/nvim/os')
-rw-r--r-- | src/nvim/os/env.c | 22 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 20 | ||||
-rw-r--r-- | src/nvim/os/input.c | 14 | ||||
-rw-r--r-- | src/nvim/os/nvim.manifest | 5 | ||||
-rw-r--r-- | src/nvim/os/shell.c | 7 | ||||
-rw-r--r-- | src/nvim/os/stdpaths.c | 49 | ||||
-rw-r--r-- | src/nvim/os/users.c | 2 |
7 files changed, 81 insertions, 38 deletions
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 5b1cb01976..5a79004c41 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -49,6 +49,7 @@ #endif #ifdef INCLUDE_GENERATED_DECLARATIONS +# include "auto/pathdef.h" # include "os/env.c.generated.h" #endif @@ -473,17 +474,9 @@ void init_homedir(void) var = os_homedir(); } - if (var != NULL) { - // Change to the directory and get the actual path. This resolves - // links. Don't do it when we can't return. - if (os_dirname(os_buf, MAXPATHL) == OK && os_chdir(os_buf) == 0) { - if (!os_chdir(var) && os_dirname(IObuff, IOSIZE) == OK) { - var = IObuff; - } - if (os_chdir(os_buf) != 0) { - emsg(_(e_prev_dir)); - } - } + // Get the actual path. This resolves links. + if (var != NULL && os_realpath(var, IObuff, IOSIZE) != NULL) { + var = IObuff; } // Fall back to current working directory if home is not found @@ -586,9 +579,6 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es bool copy_char; bool mustfree; // var was allocated, need to free it later bool at_start = true; // at start of a name -#if defined(BACKSLASH_IN_FILENAME) - char *const save_dst = dst; -#endif int prefix_len = (prefix == NULL) ? 0 : (int)strlen(prefix); @@ -729,7 +719,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es // with it, skip a character if (after_pathsep(dst, dst + c) #if defined(BACKSLASH_IN_FILENAME) - && (dst == save_dst || dst[-1] != ':') + && dst[c - 1] != ':' #endif && vim_ispathsep(*tail)) { tail++; @@ -1198,7 +1188,7 @@ bool os_setenv_append_path(const char *fname) const char *tail = path_tail_with_sep((char *)fname); size_t dirlen = (size_t)(tail - fname); assert(tail >= fname && dirlen + 1 < sizeof(os_buf)); - xstrlcpy(os_buf, fname, dirlen + 1); + xmemcpyz(os_buf, fname, dirlen); const char *path = os_getenv("PATH"); const size_t pathlen = path ? strlen(path) : 0; const size_t newlen = pathlen + dirlen + 2; diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index ade745df2c..19bdf30311 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -374,8 +374,8 @@ static bool is_executable_in_path(const char *name, char **abspath) char *e = xstrchrnul(p, ENV_SEPCHAR); // Combine the $PATH segment with `name`. - xstrlcpy(buf, p, (size_t)(e - p) + 1); - append_path(buf, name, buf_len); + xmemcpyz(buf, p, (size_t)(e - p)); + (void)append_path(buf, name, buf_len); #ifdef MSWIN if (is_executable_ext(buf, abspath)) { @@ -789,7 +789,7 @@ void os_copy_xattr(const char *from_file, const char *to_file) // get the length of the extended attributes ssize_t size = listxattr((char *)from_file, NULL, 0); // not supported or no attributes to copy - if (errno == ENOTSUP || size <= 0) { + if (size <= 0) { return; } char *xattr_buf = xmalloc((size_t)size); @@ -1320,22 +1320,22 @@ bool os_fileid_equal_fileinfo(const FileID *file_id, const FileInfo *file_info) /// Return the canonicalized absolute pathname. /// /// @param[in] name Filename to be canonicalized. -/// @param[out] buf Buffer to store the canonicalized values. A minimum length -// of MAXPATHL+1 is required. If it is NULL, memory is -// allocated. In that case, the caller should deallocate this -// buffer. +/// @param[out] buf Buffer to store the canonicalized values. +/// If it is NULL, memory is allocated. In that case, the caller +/// should deallocate this buffer. +/// @param[in] len The length of the buffer. /// /// @return pointer to the buf on success, or NULL. -char *os_realpath(const char *name, char *buf) +char *os_realpath(const char *name, char *buf, size_t len) FUNC_ATTR_NONNULL_ARG(1) { uv_fs_t request; int result = uv_fs_realpath(NULL, &request, name, NULL); if (result == kLibuvSuccess) { if (buf == NULL) { - buf = xmallocz(MAXPATHL); + buf = xmalloc(len); } - xstrlcpy(buf, request.ptr, MAXPATHL + 1); + xstrlcpy(buf, request.ptr, len); } uv_fs_req_cleanup(&request); return result == kLibuvSuccess ? buf : NULL; diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index fab360c9af..60b5b48745 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -247,6 +247,13 @@ bool os_isatty(int fd) return uv_guess_handle(fd) == UV_TTY; } +void input_enqueue_raw(String keys) +{ + if (keys.size > 0) { + rbuffer_write(input_buffer, keys.data, keys.size); + } +} + size_t input_enqueue(String keys) { const char *ptr = keys.data; @@ -255,9 +262,9 @@ size_t input_enqueue(String keys) while (rbuffer_space(input_buffer) >= 19 && ptr < end) { // A "<x>" form occupies at least 1 characters, and produces up // to 19 characters (1 + 5 * 3 for the char and 3 for a modifier). - // In the case of K_SPECIAL(0x80), 3 bytes are escaped and needed, + // In the case of K_SPECIAL (0x80), 3 bytes are escaped and needed, // but since the keys are UTF-8, so the first byte cannot be - // K_SPECIAL(0x80). + // K_SPECIAL (0x80). uint8_t buf[19] = { 0 }; // Do not simplify the keys here. Simplification will be done later. unsigned new_size @@ -351,8 +358,7 @@ static uint8_t check_multiclick(int code, int grid, int row, int col) return modifiers; } -// Mouse event handling code(Extract row/col if available and detect multiple -// clicks) +/// Mouse event handling code (extract row/col if available and detect multiple clicks) static unsigned handle_mouse_event(const char **ptr, uint8_t *buf, unsigned bufsize) { int mouse_code = 0; diff --git a/src/nvim/os/nvim.manifest b/src/nvim/os/nvim.manifest index 571b7f4580..f6bd20f66b 100644 --- a/src/nvim/os/nvim.manifest +++ b/src/nvim/os/nvim.manifest @@ -18,8 +18,9 @@ </application> </compatibility> <asmv3:application> - <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings"> - <activeCodePage>UTF-8</activeCodePage> + <asmv3:windowsSettings> + <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage> + <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware> </asmv3:windowsSettings> </asmv3:application> </assembly> diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 46ba13c4cd..2a10510b0f 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -1117,8 +1117,8 @@ static void out_data_ring(char *output, size_t size) /// Continue to append data to last screen line. /// /// @param output Data to append to screen lines. -/// @param remaining Size of data. -/// @param new_line If true, next data output will be on a new line. +/// @param count Size of data. +/// @param eof If true, there will be no more data output. static void out_data_append_to_screen(char *output, size_t *count, bool eof) FUNC_ATTR_NONNULL_ALL { @@ -1168,8 +1168,7 @@ static void out_data_cb(Stream *stream, RBuffer *buf, size_t count, void *data, rbuffer_consumed(buf, cnt); } - // Move remaining data to start of buffer, so the buffer can never - // wrap around. + // Move remaining data to start of buffer, so the buffer can never wrap around. rbuffer_reset(buf); } diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index ede17bc7c8..e5bdd56fe6 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -2,13 +2,16 @@ #include <stdbool.h> #include <string.h> +#include "klib/kvec.h" #include "nvim/ascii_defs.h" #include "nvim/fileio.h" #include "nvim/globals.h" #include "nvim/memory.h" #include "nvim/os/os.h" +#include "nvim/os/os_defs.h" #include "nvim/os/stdpaths_defs.h" #include "nvim/path.h" +#include "nvim/strings.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/stdpaths.c.generated.h" @@ -93,6 +96,46 @@ bool appname_is_valid(void) return true; } +/// Remove duplicate directories in the given XDG directory. +/// @param[in] List of directories possibly with duplicates +/// @param[out] List of directories without duplicates +static char *xdg_remove_duplicate(char *ret, const char *sep) +{ + kvec_t(char *) data = KV_INITIAL_VALUE; + char *saveptr; + + char *token = os_strtok(ret, sep, &saveptr); + while (token != NULL) { + // Check if the directory is not already in the list + bool is_duplicate = false; + for (size_t i = 0; i < data.size; i++) { + if (path_fnamecmp(kv_A(data, i), token) == 0) { + is_duplicate = true; + break; + } + } + // If it's not a duplicate, add it to the list + if (!is_duplicate) { + kv_push(data, token); + } + token = os_strtok(NULL, sep, &saveptr); + } + + StringBuilder result = KV_INITIAL_VALUE; + + for (size_t i = 0; i < data.size; i++) { + if (i == 0) { + kv_printf(result, "%s", kv_A(data, i)); + } else { + kv_printf(result, "%s%s", sep, kv_A(data, i)); + } + } + + kv_destroy(data); + xfree(ret); + return result.items; +} + /// Return XDG variable value /// /// @param[in] idx XDG variable to use. @@ -131,6 +174,10 @@ char *stdpaths_get_xdg_var(const XDGVarType idx) ret = xmemdupz(ret, len >= 2 ? len - 1 : 0); // Trim trailing slash. } + if ((idx == kXDGDataDirs || idx == kXDGConfigDirs) && ret != NULL) { + ret = xdg_remove_duplicate(ret, ENV_SEPSTR); + } + return ret; } @@ -151,7 +198,7 @@ char *get_xdg_home(const XDGVarType idx) assert(appname_len < (IOSIZE - sizeof("-data"))); if (dir) { - xstrlcpy(IObuff, appname, appname_len + 1); + xmemcpyz(IObuff, appname, appname_len); #if defined(MSWIN) if (idx == kXDGDataHome || idx == kXDGStateHome) { xstrlcat(IObuff, "-data", IOSIZE); diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index 8886d6068d..d5a8355470 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -203,7 +203,7 @@ static void init_users(void) os_get_usernames(&ga_users); } -/// Given to ExpandGeneric() to obtain an user names. +/// Given to ExpandGeneric() to obtain user names. char *get_users(expand_T *xp, int idx) { init_users(); |