diff options
| author | Pavel Platto <hinidu@gmail.com> | 2014-08-05 16:54:32 +0300 |
|---|---|---|
| committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-08-09 11:28:43 -0300 |
| commit | 5e42b406a57fd6f4f6dc982745f854eb8e0cd92f (patch) | |
| tree | 90036928a4094cb1b3b06051348a2375b51b795f /src/nvim/os | |
| parent | 19f44fda8bc74abdcd13deca47be99b151f69239 (diff) | |
| download | rneovim-5e42b406a57fd6f4f6dc982745f854eb8e0cd92f.tar.gz rneovim-5e42b406a57fd6f4f6dc982745f854eb8e0cd92f.tar.bz2 rneovim-5e42b406a57fd6f4f6dc982745f854eb8e0cd92f.zip | |
Implement `os_mkdtemp` on top of `uv_fs_mkdtemp`
Diffstat (limited to 'src/nvim/os')
| -rw-r--r-- | src/nvim/os/fs.c | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 46aea2bf36..4820a4d165 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -3,13 +3,6 @@ #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" @@ -293,18 +286,21 @@ int os_mkdir(const char *path, int32_t mode) } /// 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) +/// @param[in] template Template of the path to the directory with XXXXXX +/// which would be replaced by random chars. +/// @param[out] path Path to created directory for success, undefined for +/// failure. +/// @return `0` for success, non-zero for failure. +int os_mkdtemp(const char *template, char *path) { -#ifdef WIN32 - return _mktemp(template) && os_mkdir(template, 0700) == 0 ? template : NULL; -#else - return mkdtemp(template); -#endif + uv_fs_t request; + int result = uv_fs_mkdtemp(uv_default_loop(), &request, template, NULL); + if (result == kLibuvSuccess) { + strcpy(path, request.path); + } + uv_fs_req_cleanup(&request); + return result; } /// Remove a directory. |