From 8b91ba929b5d178ed36423c6fac27debfa3bdf38 Mon Sep 17 00:00:00 2001 From: Pavel Platto Date: Sun, 15 Jun 2014 22:18:43 +0300 Subject: Temporary os_mkdtemp implementation. Use it instead of mkdtemp. --- src/nvim/os/fs.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index dce95eb3c9..46aea2bf36 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -3,6 +3,13 @@ #include +// TODO(hinidu): remove after implementing `os_mkdtemp` on top of libuv +#ifdef WIN32 +# include +#else +# include +#endif + #include "nvim/os/os.h" #include "nvim/ascii.h" #include "nvim/memory.h" @@ -285,6 +292,21 @@ int os_mkdir(const char *path, int32_t mode) return result; } +/// Create a unique temporary directory. +/// TODO(hinidu): Implement on top of libuv. ref #850 +/// +/// @param[in,out] template Template of the path to the directory with XXXXXX +/// which would be replaced by random chars. +/// @return Pointer to changed `template` for success, `NULL` for failure. +char *os_mkdtemp(char *template) +{ +#ifdef WIN32 + return _mktemp(template) && os_mkdir(template, 0700) == 0 ? template : NULL; +#else + return mkdtemp(template); +#endif +} + /// Remove a directory. /// /// @return `0` for success, non-zero for failure. -- cgit From edd7a8c5ddd99bd0c02b4218d43bccb562809d55 Mon Sep 17 00:00:00 2001 From: Pavel Platto Date: Thu, 19 Jun 2014 00:58:04 +0300 Subject: Remove #ifdefs TEMPDIRNAMES and add TEMPDIRNAMES for Windows Vim does not define TEMPDIRNAMES for all systems, but it is defined for all systems supported by Neovim. Temporary directory names for Windows was obtained from GetTempPath() function documentation at MSDN. Additionally small renamings were performed. --- src/nvim/os/os.h | 7 +++++++ src/nvim/os/unix_defs.h | 7 +++++++ src/nvim/os/win_defs.h | 9 +++++++++ 3 files changed, 23 insertions(+) create mode 100644 src/nvim/os/unix_defs.h create mode 100644 src/nvim/os/win_defs.h (limited to 'src/nvim/os') diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h index b6148e72bf..b46989d9b4 100644 --- a/src/nvim/os/os.h +++ b/src/nvim/os/os.h @@ -7,10 +7,17 @@ #include "nvim/os/fs_defs.h" #include "nvim/vim.h" +#ifdef WIN32 +# include "nvim/os/win_defs.h" +#else +# include "nvim/os/unix_defs.h" +#endif + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/fs.h.generated.h" # include "os/mem.h.generated.h" # include "os/env.h.generated.h" # include "os/users.h.generated.h" #endif + #endif // NVIM_OS_OS_H diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h new file mode 100644 index 0000000000..197a87bcc5 --- /dev/null +++ b/src/nvim/os/unix_defs.h @@ -0,0 +1,7 @@ +#ifndef NEOVIM_OS_UNIX_DEFS_H +#define NEOVIM_OS_UNIX_DEFS_H + +#define TEMP_DIR_NAMES {"$TMPDIR", "/tmp", ".", "$HOME"} +#define TEMP_FILE_PATH_MAXLEN 256 + +#endif // NEOVIM_OS_UNIX_DEFS_H diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h new file mode 100644 index 0000000000..49fcb64777 --- /dev/null +++ b/src/nvim/os/win_defs.h @@ -0,0 +1,9 @@ +#ifndef NEOVIM_OS_WIN_DEFS_H +#define NEOVIM_OS_WIN_DEFS_H + +#include + +#define TEMP_DIR_NAMES {"$TMP", "$TEMP", "$USERPROFILE", ""} +#define TEMP_FILE_PATH_MAXLEN _MAX_PATH + +#endif // NEOVIM_OS_WIN_DEFS_H -- cgit From 29e0cd1571b773feb7fd61118930cdac7d83e38c Mon Sep 17 00:00:00 2001 From: Pavel Platto Date: Thu, 19 Jun 2014 23:46:51 +0300 Subject: Refactor vim_tempname - temp_count is uint32_t now instead of long because it supposed to be at most 999999999 (comment on line 5227) temporary files. The most probably it was a long for compatibility with systems where int is 16-bit. - Use "nvim" as prefix for temp folder name instead of "v" - Remove unused parameter from vim_tempname --- src/nvim/os/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/server.c b/src/nvim/os/server.c index 23f9393122..2494dfeb9f 100644 --- a/src/nvim/os/server.c +++ b/src/nvim/os/server.c @@ -52,7 +52,7 @@ void server_init(void) servers = pmap_new(cstr_t)(); if (!os_getenv("NEOVIM_LISTEN_ADDRESS")) { - char *listen_address = (char *)vim_tempname('s'); + char *listen_address = (char *)vim_tempname(); os_setenv("NEOVIM_LISTEN_ADDRESS", listen_address, 1); free(listen_address); } -- cgit From 286ce271e730a2e6883c244912b36bca007f6ddc Mon Sep 17 00:00:00 2001 From: Pavel Platto Date: Sun, 22 Jun 2014 13:03:08 +0300 Subject: Extract `tempfile` module from fileio Though this module is relatively small it has very clear boundaries. The last argument for extracting `tempfile` was the errors which I got when I was writing unittests for it: `cimport './src/nvim/fileio.h'` does not work for some reason. --- src/nvim/os/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/server.c b/src/nvim/os/server.c index 2494dfeb9f..2e8934ecfb 100644 --- a/src/nvim/os/server.c +++ b/src/nvim/os/server.c @@ -11,7 +11,7 @@ #include "nvim/vim.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/fileio.h" +#include "nvim/tempfile.h" #include "nvim/map.h" #define MAX_CONNECTIONS 32 -- cgit From 14239ae33128ae961a4ce9e68436ad3f0f557b90 Mon Sep 17 00:00:00 2001 From: Pavel Platto Date: Sat, 28 Jun 2014 21:32:04 +0300 Subject: Create os/os_defs.h for os specific definitions --- src/nvim/os/os.h | 6 ------ src/nvim/os/os_defs.h | 10 ++++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 src/nvim/os/os_defs.h (limited to 'src/nvim/os') diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h index b46989d9b4..69bd1ff4fd 100644 --- a/src/nvim/os/os.h +++ b/src/nvim/os/os.h @@ -7,12 +7,6 @@ #include "nvim/os/fs_defs.h" #include "nvim/vim.h" -#ifdef WIN32 -# include "nvim/os/win_defs.h" -#else -# include "nvim/os/unix_defs.h" -#endif - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/fs.h.generated.h" # include "os/mem.h.generated.h" diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h new file mode 100644 index 0000000000..aa6c5bccc3 --- /dev/null +++ b/src/nvim/os/os_defs.h @@ -0,0 +1,10 @@ +#ifndef NVIM_OS_OS_DEFS_H +#define NVIM_OS_OS_DEFS_H + +#ifdef WIN32 +# include "nvim/os/win_defs.h" +#else +# include "nvim/os/unix_defs.h" +#endif + +#endif // NVIM_OS_DEFS_H -- cgit