ruby-changes:43197
From: nobu <ko1@a...>
Date: Sat, 4 Jun 2016 10:38:46 +0900 (JST)
Subject: [ruby-changes:43197] nobu:r55270 (trunk): win32.c: use PATH_MAX
nobu 2016-06-04 10:38:41 +0900 (Sat, 04 Jun 2016) New Revision: 55270 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55270 Log: win32.c: use PATH_MAX * win32/win32.c: unify MAX_PATH, _MAX_PATH, and MAXPATHLEN to PATH_MAX, except for MAX_PATH in get_special_folder for an API limit. Modified files: trunk/ChangeLog trunk/win32/win32.c Index: ChangeLog =================================================================== --- ChangeLog (revision 55269) +++ ChangeLog (revision 55270) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jun 4 10:38:39 2016 Nobuyoshi Nakada <nobu@r...> + + * win32/win32.c: unify MAX_PATH, _MAX_PATH, and MAXPATHLEN to + PATH_MAX, except for MAX_PATH in get_special_folder for an API + limit. + Fri Jun 3 21:27:22 2016 Nobuyoshi Nakada <nobu@r...> * ruby.c (process_options): rb_str_conv_enc() never set encoding Index: win32/win32.c =================================================================== --- win32/win32.c (revision 55269) +++ win32/win32.c (revision 55270) @@ -83,6 +83,16 @@ static char *w32_getenv(const char *name https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L83 #define dln_find_file_r(fname, path, buf, size) rb_w32_udln_find_file_r(fname, path, buf, size, cp) #undef CharNext /* no default cp version */ +#ifndef PATH_MAX +# if defined MAX_PATH +# define PATH_MAX MAX_PATH +# elif defined HAVE_SYS_PARAM_H +# include <sys/param.h> +# define PATH_MAX MAXPATHLEN +# endif +#endif +#define ENV_MAX 512 + #undef stat #undef fclose #undef close @@ -433,7 +443,7 @@ get_special_folder(int n, WCHAR *buf, si https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L443 func = (get_path_func) get_proc_address("shell32", "SHGetPathFromIDListEx", NULL); } - if (!func && len < 260) return FALSE; + if (!func && len < MAX_PATH) return FALSE; if (SHGetSpecialFolderLocation(NULL, n, &pidl) == 0) { if (func) { @@ -488,7 +498,7 @@ get_proc_address(const char *module, con https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L498 VALUE rb_w32_special_folder(int type) { - WCHAR path[_MAX_PATH]; + WCHAR path[PATH_MAX]; if (!get_special_folder(type, path, numberof(path))) return Qnil; regulate_path(path); @@ -517,7 +527,7 @@ static void https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L527 init_env(void) { static const WCHAR TMPDIR[] = L"TMPDIR"; - struct {WCHAR name[6], eq, val[_MAX_PATH];} wk; + struct {WCHAR name[6], eq, val[ENV_MAX];} wk; DWORD len; BOOL f; #define env wk.val @@ -1062,12 +1072,6 @@ join_argv(char *cmd, char *const *argv, https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1072 return len; } -#ifdef HAVE_SYS_PARAM_H -# include <sys/param.h> -#else -# define MAXPATHLEN 512 -#endif - /* License: Ruby's */ #define STRNDUPV(ptr, v, src, len) \ (((char *)memcpy(((ptr) = ALLOCV((v), (len) + 1)), (src), (len)))[len] = 0) @@ -1213,7 +1217,7 @@ UINT rb_w32_filecp(void); https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1217 static rb_pid_t w32_spawn(int mode, const char *cmd, const char *prog, UINT cp) { - char fbuf[MAXPATHLEN]; + char fbuf[PATH_MAX]; char *p = NULL; const char *shell = NULL; WCHAR *wcmd = NULL, *wshell = NULL; @@ -1356,7 +1360,7 @@ w32_aspawn_flags(int mode, const char *p https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1360 size_t len; BOOL ntcmd = FALSE, tmpnt; const char *shell; - char *cmd, fbuf[MAXPATHLEN]; + char *cmd, fbuf[PATH_MAX]; WCHAR *wcmd = NULL, *wprog = NULL; int e = 0; rb_pid_t ret = -1; @@ -1487,11 +1491,11 @@ insert(const char *path, VALUE vinfo, vo https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1491 static NtCmdLineElement ** cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail, UINT cp, rb_encoding *enc) { - char buffer[MAXPATHLEN], *buf = buffer; + char buffer[PATH_MAX], *buf = buffer; NtCmdLineElement **last = tail; int status; - if (patt->len >= MAXPATHLEN) + if (patt->len >= PATH_MAX) if (!(buf = malloc(patt->len + 1))) return 0; strlcpy(buf, patt->str, patt->len + 1); @@ -1855,7 +1859,7 @@ static HANDLE https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1859 open_dir_handle(const WCHAR *filename, WIN32_FIND_DATAW *fd) { HANDLE fh; - WCHAR fullname[_MAX_PATH + rb_strlen_lit("\\*")]; + WCHAR fullname[PATH_MAX + rb_strlen_lit("\\*")]; WCHAR *p; int len = 0; @@ -1865,12 +1869,12 @@ open_dir_handle(const WCHAR *filename, W https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1869 fh = open_special(filename, 0, 0); if (fh != INVALID_HANDLE_VALUE) { - len = get_final_path(fh, fullname, _MAX_PATH, 0); + len = get_final_path(fh, fullname, PATH_MAX, 0); CloseHandle(fh); } if (!len) { len = lstrlenW(filename); - if (len >= _MAX_PATH) { + if (len >= PATH_MAX) { errno = ENAMETOOLONG; return INVALID_HANDLE_VALUE; } @@ -5360,7 +5364,7 @@ check_valid_dir(const WCHAR *path) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5364 { WIN32_FIND_DATAW fd; HANDLE fh; - WCHAR full[MAX_PATH]; + WCHAR full[PATH_MAX]; WCHAR *dmy; WCHAR *p, *q; @@ -5441,7 +5445,7 @@ winnt_stat(const WCHAR *path, struct sta https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5445 memset(st, 0, sizeof(*st)); f = open_special(path, 0, 0); if (f != INVALID_HANDLE_VALUE) { - WCHAR finalname[MAX_PATH]; + WCHAR finalname[PATH_MAX]; const DWORD attr = stati64_handle(f, st); const DWORD len = get_final_path(f, finalname, numberof(finalname), 0); CloseHandle(f); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/