aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
diff options
context:
space:
mode:
authorNicolas Hillegeer <nicolas@hillegeer.com>2014-07-14 21:17:39 +0200
committerNicolas Hillegeer <nicolas@hillegeer.com>2014-07-14 21:17:39 +0200
commit2b62dcddf801e096bde7d4608e090018b5227e98 (patch)
tree728251b27edf7110565bc0c4c8cc5864f5b31bfe /src/nvim/os
parent47084ea7657121837536d409b9137fd38426aeef (diff)
parent14239ae33128ae961a4ce9e68436ad3f0f557b90 (diff)
downloadrneovim-2b62dcddf801e096bde7d4608e090018b5227e98.tar.gz
rneovim-2b62dcddf801e096bde7d4608e090018b5227e98.tar.bz2
rneovim-2b62dcddf801e096bde7d4608e090018b5227e98.zip
Merge #850 'impl mkdtemp for windows, refactor vim_tempname'
Diffstat (limited to 'src/nvim/os')
-rw-r--r--src/nvim/os/fs.c22
-rw-r--r--src/nvim/os/os.h1
-rw-r--r--src/nvim/os/os_defs.h10
-rw-r--r--src/nvim/os/server.c4
-rw-r--r--src/nvim/os/unix_defs.h7
-rw-r--r--src/nvim/os/win_defs.h9
6 files changed, 51 insertions, 2 deletions
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 <assert.h>
+// TODO(hinidu): remove after implementing `os_mkdtemp` on top of libuv
+#ifdef WIN32
+# include <io.h>
+#else
+# include <stdlib.h>
+#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.
diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h
index b6148e72bf..69bd1ff4fd 100644
--- a/src/nvim/os/os.h
+++ b/src/nvim/os/os.h
@@ -13,4 +13,5 @@
# include "os/env.h.generated.h"
# include "os/users.h.generated.h"
#endif
+
#endif // NVIM_OS_OS_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
diff --git a/src/nvim/os/server.c b/src/nvim/os/server.c
index 23f9393122..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
@@ -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);
}
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 <windows.h>
+
+#define TEMP_DIR_NAMES {"$TMP", "$TEMP", "$USERPROFILE", ""}
+#define TEMP_FILE_PATH_MAXLEN _MAX_PATH
+
+#endif // NEOVIM_OS_WIN_DEFS_H