From fe0c3999ca484e991badcde34a5ad962d72440f3 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 27 May 2016 06:20:31 -0400 Subject: do_source: less fuss about fopen_noinh_readbin --- config/config.h.in | 1 - src/nvim/ex_cmds2.c | 22 +++------------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/config/config.h.in b/config/config.h.in index c2f52d8c7e..867278de0d 100644 --- a/config/config.h.in +++ b/config/config.h.in @@ -49,7 +49,6 @@ #cmakedefine UNIX #cmakedefine USE_FNAME_CASE -#define FEAT_CSCOPE #cmakedefine FEAT_TUI #ifndef UNIT_TESTING diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 5fe6209a0a..5fc64596a9 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2482,12 +2482,8 @@ int source_level(void *cookie) } -#if (defined(WIN32) && defined(FEAT_CSCOPE)) || defined(HAVE_FD_CLOEXEC) -# define USE_FOPEN_NOINH -/* - * Special function to open a file without handle inheritance. - * When possible the handle is closed on exec(). - */ +/// Special function to open a file without handle inheritance. +/// If possible the handle is closed on exec(). static FILE *fopen_noinh_readbin(char *filename) { int fd_tmp = os_open(filename, O_RDONLY, 0); @@ -2506,7 +2502,6 @@ static FILE *fopen_noinh_readbin(char *filename) return fdopen(fd_tmp, READBIN); } -#endif /* @@ -2560,11 +2555,7 @@ do_source ( /* Apply SourcePre autocommands, they may get the file. */ apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf); -#ifdef USE_FOPEN_NOINH cookie.fp = fopen_noinh_readbin((char *)fname_exp); -#else - cookie.fp = mch_fopen((char *)fname_exp, READBIN); -#endif if (cookie.fp == NULL && check_other) { /* * Try again, replacing file name ".vimrc" by "_vimrc" or vice versa, @@ -2573,15 +2564,8 @@ do_source ( p = path_tail(fname_exp); if ((*p == '.' || *p == '_') && (STRICMP(p + 1, "nvimrc") == 0 || STRICMP(p + 1, "exrc") == 0)) { - if (*p == '_') - *p = '.'; - else - *p = '_'; -#ifdef USE_FOPEN_NOINH + *p = (*p == '_') ? '.' : '_'; cookie.fp = fopen_noinh_readbin((char *)fname_exp); -#else - cookie.fp = mch_fopen((char *)fname_exp, READBIN); -#endif } } -- cgit From 8c127c77a6f3c9d3c82f5cff23650efcfb8ca26e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 28 May 2016 12:53:31 -0400 Subject: fopen_noinh_readbin: restore WIN32 decision --- src/nvim/ex_cmds2.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 5fc64596a9..d167c28182 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2481,24 +2481,28 @@ int source_level(void *cookie) return ((struct source_cookie *)cookie)->level; } - /// Special function to open a file without handle inheritance. /// If possible the handle is closed on exec(). static FILE *fopen_noinh_readbin(char *filename) { +#ifdef WIN32 + int fd_tmp = os_open(filename, O_RDONLY | O_BINARY | O_NOINHERIT, 0); +#else int fd_tmp = os_open(filename, O_RDONLY, 0); +#endif - if (fd_tmp < 0) + if (fd_tmp < 0) { return NULL; + } -# ifdef HAVE_FD_CLOEXEC +#ifdef HAVE_FD_CLOEXEC { int fdflags = fcntl(fd_tmp, F_GETFD); if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0) { (void)fcntl(fd_tmp, F_SETFD, fdflags | FD_CLOEXEC); } } -# endif +#endif return fdopen(fd_tmp, READBIN); } -- cgit