comparison src/os_win32.c @ 15603:639b8318472c v8.1.0809

patch 8.1.0809: too many #ifdefs commit https://github.com/vim/vim/commit/a12a161b8ce09d024ed71c2134149fa323f8ee8e Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 24 16:39:02 2019 +0100 patch 8.1.0809: too many #ifdefs Problem: Too many #ifdefs. Solution: Graduate FEAT_MBYTE, part 3.
author Bram Moolenaar <Bram@vim.org>
date Thu, 24 Jan 2019 16:45:06 +0100
parents df198b298bff
children bfbdef46aa7d
comparison
equal deleted inserted replaced
15602:2ef2028868e2 15603:639b8318472c
450 450
451 while (*p != NUL) 451 while (*p != NUL)
452 { 452 {
453 if (*p == '^' && vim_strchr(escaped, p[1]) != NULL) 453 if (*p == '^' && vim_strchr(escaped, p[1]) != NULL)
454 mch_memmove(p, p + 1, l--); 454 mch_memmove(p, p + 1, l--);
455 #ifdef FEAT_MBYTE
456 n = (*mb_ptr2len)(p); 455 n = (*mb_ptr2len)(p);
457 #else
458 n = 1;
459 #endif
460 p += n; 456 p += n;
461 l -= n; 457 l -= n;
462 } 458 }
463 } 459 }
464 460
1888 if (g_nMouseClick == -1) 1884 if (g_nMouseClick == -1)
1889 #endif 1885 #endif
1890 { 1886 {
1891 int n = 1; 1887 int n = 1;
1892 1888
1893 #ifdef FEAT_MBYTE
1894 if (ch2 == NUL) 1889 if (ch2 == NUL)
1895 { 1890 {
1896 int i; 1891 int i;
1897 char_u *p; 1892 char_u *p;
1898 WCHAR ch[2]; 1893 WCHAR ch[2];
1910 typeahead[typeaheadlen + i] = p[i]; 1905 typeahead[typeaheadlen + i] = p[i];
1911 vim_free(p); 1906 vim_free(p);
1912 } 1907 }
1913 } 1908 }
1914 else 1909 else
1915 #endif
1916 typeahead[typeaheadlen] = c; 1910 typeahead[typeaheadlen] = c;
1917 if (ch2 != NUL) 1911 if (ch2 != NUL)
1918 { 1912 {
1919 if (c == K_NUL) 1913 if (c == K_NUL)
1920 { 1914 {
1948 * using a double-byte encoding (would become a lead 1942 * using a double-byte encoding (would become a lead
1949 * byte). */ 1943 * byte). */
1950 if ((modifiers & MOD_MASK_ALT) 1944 if ((modifiers & MOD_MASK_ALT)
1951 && n == 1 1945 && n == 1
1952 && (typeahead[typeaheadlen] & 0x80) == 0 1946 && (typeahead[typeaheadlen] & 0x80) == 0
1953 #ifdef FEAT_MBYTE
1954 && !enc_dbcs 1947 && !enc_dbcs
1955 #endif
1956 ) 1948 )
1957 { 1949 {
1958 #ifdef FEAT_MBYTE
1959 n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80, 1950 n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80,
1960 typeahead + typeaheadlen); 1951 typeahead + typeaheadlen);
1961 #else
1962 typeahead[typeaheadlen] |= 0x80;
1963 #endif
1964 modifiers &= ~MOD_MASK_ALT; 1952 modifiers &= ~MOD_MASK_ALT;
1965 } 1953 }
1966 1954
1967 if (modifiers != 0) 1955 if (modifiers != 0)
1968 { 1956 {
2042 return TRUE; 2030 return TRUE;
2043 } 2031 }
2044 return FALSE; 2032 return FALSE;
2045 } 2033 }
2046 2034
2047 #ifdef FEAT_MBYTE
2048 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 2035 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
2049 { 2036 {
2050 WCHAR *p = enc_to_utf16((char_u *)name, NULL); 2037 WCHAR *p = enc_to_utf16((char_u *)name, NULL);
2051 WCHAR fnamew[_MAX_PATH]; 2038 WCHAR fnamew[_MAX_PATH];
2052 WCHAR *dumw; 2039 WCHAR *dumw;
2071 if (path != NULL) 2058 if (path != NULL)
2072 *path = utf16_to_enc(fnamew, NULL); 2059 *path = utf16_to_enc(fnamew, NULL);
2073 return TRUE; 2060 return TRUE;
2074 } 2061 }
2075 } 2062 }
2076 #endif
2077 2063
2078 curpath = getenv("PATH"); 2064 curpath = getenv("PATH");
2079 newpath = (char*)alloc((unsigned)(STRLEN(curpath) + 3)); 2065 newpath = (char*)alloc((unsigned)(STRLEN(curpath) + 3));
2080 if (newpath == NULL) 2066 if (newpath == NULL)
2081 return FALSE; 2067 return FALSE;
2766 return FAIL; 2752 return FAIL;
2767 #endif 2753 #endif
2768 } 2754 }
2769 2755
2770 2756
2771 #ifdef FEAT_MBYTE
2772 /* 2757 /*
2773 * fname_casew(): Wide version of fname_case(). Set the case of the file name, 2758 * fname_casew(): Wide version of fname_case(). Set the case of the file name,
2774 * if it already exists. When "len" is > 0, also expand short to long 2759 * if it already exists. When "len" is > 0, also expand short to long
2775 * filenames. 2760 * filenames.
2776 * Return FAIL if wide functions are not available, OK otherwise. 2761 * Return FAIL if wide functions are not available, OK otherwise.
2876 } 2861 }
2877 2862
2878 wcscpy(name, szTrueName); 2863 wcscpy(name, szTrueName);
2879 return OK; 2864 return OK;
2880 } 2865 }
2881 #endif
2882 2866
2883 /* 2867 /*
2884 * fname_case(): Set the case of the file name, if it already exists. 2868 * fname_case(): Set the case of the file name, if it already exists.
2885 * When "len" is > 0, also expand short to long filenames. 2869 * When "len" is > 0, also expand short to long filenames.
2886 * NOTE: much of this is identical to fname_casew(), keep in sync! 2870 * NOTE: much of this is identical to fname_casew(), keep in sync!
2904 if (flen == 0) 2888 if (flen == 0)
2905 return; 2889 return;
2906 2890
2907 slash_adjust(name); 2891 slash_adjust(name);
2908 2892
2909 #ifdef FEAT_MBYTE
2910 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 2893 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
2911 { 2894 {
2912 WCHAR *p = enc_to_utf16(name, NULL); 2895 WCHAR *p = enc_to_utf16(name, NULL);
2913 2896
2914 if (p != NULL) 2897 if (p != NULL)
2931 } 2914 }
2932 } 2915 }
2933 } 2916 }
2934 return; 2917 return;
2935 } 2918 }
2936 #endif
2937 2919
2938 /* If 'enc' is utf-8, flen can be larger than _MAX_PATH. 2920 /* If 'enc' is utf-8, flen can be larger than _MAX_PATH.
2939 * So we should check this after calling wide function. */ 2921 * So we should check this after calling wide function. */
2940 if (flen > _MAX_PATH) 2922 if (flen > _MAX_PATH)
2941 return; 2923 return;
2960 2942
2961 ptruePrev = ptrue; 2943 ptruePrev = ptrue;
2962 porigPrev = porig; 2944 porigPrev = porig;
2963 while (*porig != NUL && *porig != psepc) 2945 while (*porig != NUL && *porig != psepc)
2964 { 2946 {
2965 #ifdef FEAT_MBYTE
2966 int l; 2947 int l;
2967 2948
2968 if (enc_dbcs) 2949 if (enc_dbcs)
2969 { 2950 {
2970 l = (*mb_ptr2len)((char_u *)porig); 2951 l = (*mb_ptr2len)((char_u *)porig);
2971 while (--l >= 0) 2952 while (--l >= 0)
2972 *ptrue++ = *porig++; 2953 *ptrue++ = *porig++;
2973 } 2954 }
2974 else 2955 else
2975 #endif
2976 *ptrue++ = *porig++; 2956 *ptrue++ = *porig++;
2977 } 2957 }
2978 *ptrue = NUL; 2958 *ptrue = NUL;
2979 2959
2980 /* To avoid a slow failure append "\*" when searching a directory, 2960 /* To avoid a slow failure append "\*" when searching a directory,
3042 int len) 3022 int len)
3043 { 3023 {
3044 char szUserName[256 + 1]; /* UNLEN is 256 */ 3024 char szUserName[256 + 1]; /* UNLEN is 256 */
3045 DWORD cch = sizeof szUserName; 3025 DWORD cch = sizeof szUserName;
3046 3026
3047 #ifdef FEAT_MBYTE
3048 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 3027 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3049 { 3028 {
3050 WCHAR wszUserName[256 + 1]; /* UNLEN is 256 */ 3029 WCHAR wszUserName[256 + 1]; /* UNLEN is 256 */
3051 DWORD wcch = sizeof(wszUserName) / sizeof(WCHAR); 3030 DWORD wcch = sizeof(wszUserName) / sizeof(WCHAR);
3052 3031
3060 vim_free(p); 3039 vim_free(p);
3061 return OK; 3040 return OK;
3062 } 3041 }
3063 } 3042 }
3064 } 3043 }
3065 #endif
3066 if (GetUserName(szUserName, &cch)) 3044 if (GetUserName(szUserName, &cch))
3067 { 3045 {
3068 vim_strncpy(s, (char_u *)szUserName, len - 1); 3046 vim_strncpy(s, (char_u *)szUserName, len - 1);
3069 return OK; 3047 return OK;
3070 } 3048 }
3081 char_u *s, 3059 char_u *s,
3082 int len) 3060 int len)
3083 { 3061 {
3084 DWORD cch = len; 3062 DWORD cch = len;
3085 3063
3086 #ifdef FEAT_MBYTE
3087 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 3064 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3088 { 3065 {
3089 WCHAR wszHostName[256 + 1]; 3066 WCHAR wszHostName[256 + 1];
3090 DWORD wcch = sizeof(wszHostName) / sizeof(WCHAR); 3067 DWORD wcch = sizeof(wszHostName) / sizeof(WCHAR);
3091 3068
3099 vim_free(p); 3076 vim_free(p);
3100 return; 3077 return;
3101 } 3078 }
3102 } 3079 }
3103 } 3080 }
3104 #endif
3105 if (!GetComputerName((LPSTR)s, &cch)) 3081 if (!GetComputerName((LPSTR)s, &cch))
3106 vim_strncpy(s, (char_u *)"PC (Win32 Vim)", len - 1); 3082 vim_strncpy(s, (char_u *)"PC (Win32 Vim)", len - 1);
3107 } 3083 }
3108 3084
3109 3085
3133 * Originally this was: 3109 * Originally this was:
3134 * return (getcwd(buf, len) != NULL ? OK : FAIL); 3110 * return (getcwd(buf, len) != NULL ? OK : FAIL);
3135 * But the Win32s known bug list says that getcwd() doesn't work 3111 * But the Win32s known bug list says that getcwd() doesn't work
3136 * so use the Win32 system call instead. <Negri> 3112 * so use the Win32 system call instead. <Negri>
3137 */ 3113 */
3138 #ifdef FEAT_MBYTE
3139 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 3114 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3140 { 3115 {
3141 WCHAR wbuf[_MAX_PATH + 1]; 3116 WCHAR wbuf[_MAX_PATH + 1];
3142 3117
3143 if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0) 3118 if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0)
3165 return OK; 3140 return OK;
3166 } 3141 }
3167 } 3142 }
3168 return FAIL; 3143 return FAIL;
3169 } 3144 }
3170 #endif
3171 if (GetCurrentDirectory(len, (LPSTR)buf) == 0) 3145 if (GetCurrentDirectory(len, (LPSTR)buf) == 0)
3172 return FAIL; 3146 return FAIL;
3173 lfnlen = GetLongPathNameA((LPCSTR)buf, (LPSTR)abuf, _MAX_PATH); 3147 lfnlen = GetLongPathNameA((LPCSTR)buf, (LPSTR)abuf, _MAX_PATH);
3174 if (lfnlen == 0 || lfnlen >= (DWORD)len) 3148 if (lfnlen == 0 || lfnlen >= (DWORD)len)
3175 // Failed to get long path name or it's too long: fall back to the 3149 // Failed to get long path name or it's too long: fall back to the
3203 int 3177 int
3204 mch_setperm(char_u *name, long perm) 3178 mch_setperm(char_u *name, long perm)
3205 { 3179 {
3206 long n = -1; 3180 long n = -1;
3207 3181
3208 #ifdef FEAT_MBYTE
3209 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 3182 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3210 { 3183 {
3211 WCHAR *p = enc_to_utf16(name, NULL); 3184 WCHAR *p = enc_to_utf16(name, NULL);
3212 3185
3213 if (p != NULL) 3186 if (p != NULL)
3217 if (n == -1) 3190 if (n == -1)
3218 return FAIL; 3191 return FAIL;
3219 } 3192 }
3220 } 3193 }
3221 if (n == -1) 3194 if (n == -1)
3222 #endif
3223 n = _chmod((const char *)name, perm); 3195 n = _chmod((const char *)name, perm);
3224 if (n == -1) 3196 if (n == -1)
3225 return FAIL; 3197 return FAIL;
3226 3198
3227 win32_set_archive(name); 3199 win32_set_archive(name);
3288 * Return 0 on success, -1 on error. 3260 * Return 0 on success, -1 on error.
3289 */ 3261 */
3290 int 3262 int
3291 mch_mkdir(char_u *name) 3263 mch_mkdir(char_u *name)
3292 { 3264 {
3293 #ifdef FEAT_MBYTE
3294 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 3265 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3295 { 3266 {
3296 WCHAR *p; 3267 WCHAR *p;
3297 int retval; 3268 int retval;
3298 3269
3301 return -1; 3272 return -1;
3302 retval = _wmkdir(p); 3273 retval = _wmkdir(p);
3303 vim_free(p); 3274 vim_free(p);
3304 return retval; 3275 return retval;
3305 } 3276 }
3306 #endif
3307 return _mkdir((const char *)name); 3277 return _mkdir((const char *)name);
3308 } 3278 }
3309 3279
3310 /* 3280 /*
3311 * Delete directory "name". 3281 * Delete directory "name".
3312 * Return 0 on success, -1 on error. 3282 * Return 0 on success, -1 on error.
3313 */ 3283 */
3314 int 3284 int
3315 mch_rmdir(char_u *name) 3285 mch_rmdir(char_u *name)
3316 { 3286 {
3317 #ifdef FEAT_MBYTE
3318 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 3287 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3319 { 3288 {
3320 WCHAR *p; 3289 WCHAR *p;
3321 int retval; 3290 int retval;
3322 3291
3325 return -1; 3294 return -1;
3326 retval = _wrmdir(p); 3295 retval = _wrmdir(p);
3327 vim_free(p); 3296 vim_free(p);
3328 return retval; 3297 return retval;
3329 } 3298 }
3330 #endif
3331 return _rmdir((const char *)name); 3299 return _rmdir((const char *)name);
3332 } 3300 }
3333 3301
3334 /* 3302 /*
3335 * Return TRUE if file "fname" has more than one link. 3303 * Return TRUE if file "fname" has more than one link.
3351 { 3319 {
3352 HANDLE hFind; 3320 HANDLE hFind;
3353 int res = FALSE; 3321 int res = FALSE;
3354 WIN32_FIND_DATAA findDataA; 3322 WIN32_FIND_DATAA findDataA;
3355 DWORD fileFlags = 0, reparseTag = 0; 3323 DWORD fileFlags = 0, reparseTag = 0;
3356 #ifdef FEAT_MBYTE
3357 WCHAR *wn = NULL; 3324 WCHAR *wn = NULL;
3358 WIN32_FIND_DATAW findDataW; 3325 WIN32_FIND_DATAW findDataW;
3359 3326
3360 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 3327 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3361 wn = enc_to_utf16(name, NULL); 3328 wn = enc_to_utf16(name, NULL);
3368 fileFlags = findDataW.dwFileAttributes; 3335 fileFlags = findDataW.dwFileAttributes;
3369 reparseTag = findDataW.dwReserved0; 3336 reparseTag = findDataW.dwReserved0;
3370 } 3337 }
3371 } 3338 }
3372 else 3339 else
3373 #endif
3374 { 3340 {
3375 hFind = FindFirstFile((LPCSTR)name, &findDataA); 3341 hFind = FindFirstFile((LPCSTR)name, &findDataA);
3376 if (hFind != INVALID_HANDLE_VALUE) 3342 if (hFind != INVALID_HANDLE_VALUE)
3377 { 3343 {
3378 fileFlags = findDataA.dwFileAttributes; 3344 fileFlags = findDataA.dwFileAttributes;
3413 int 3379 int
3414 win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info) 3380 win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info)
3415 { 3381 {
3416 HANDLE hFile; 3382 HANDLE hFile;
3417 int res = FILEINFO_READ_FAIL; 3383 int res = FILEINFO_READ_FAIL;
3418 #ifdef FEAT_MBYTE
3419 WCHAR *wn = NULL; 3384 WCHAR *wn = NULL;
3420 3385
3421 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 3386 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3422 { 3387 {
3423 wn = enc_to_utf16(fname, NULL); 3388 wn = enc_to_utf16(fname, NULL);
3434 FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */ 3399 FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */
3435 NULL); /* handle to template file */ 3400 NULL); /* handle to template file */
3436 vim_free(wn); 3401 vim_free(wn);
3437 } 3402 }
3438 else 3403 else
3439 #endif
3440 hFile = CreateFile((LPCSTR)fname, /* file name */ 3404 hFile = CreateFile((LPCSTR)fname, /* file name */
3441 GENERIC_READ, /* access mode */ 3405 GENERIC_READ, /* access mode */
3442 FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ 3406 FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */
3443 NULL, /* security descriptor */ 3407 NULL, /* security descriptor */
3444 OPEN_EXISTING, /* creation disposition */ 3408 OPEN_EXISTING, /* creation disposition */
3464 */ 3428 */
3465 static int 3429 static int
3466 win32_getattrs(char_u *name) 3430 win32_getattrs(char_u *name)
3467 { 3431 {
3468 int attr; 3432 int attr;
3469 #ifdef FEAT_MBYTE
3470 WCHAR *p = NULL; 3433 WCHAR *p = NULL;
3471 3434
3472 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 3435 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3473 p = enc_to_utf16(name, NULL); 3436 p = enc_to_utf16(name, NULL);
3474 3437
3476 { 3439 {
3477 attr = GetFileAttributesW(p); 3440 attr = GetFileAttributesW(p);
3478 vim_free(p); 3441 vim_free(p);
3479 } 3442 }
3480 else 3443 else
3481 #endif
3482 attr = GetFileAttributes((char *)name); 3444 attr = GetFileAttributes((char *)name);
3483 3445
3484 return attr; 3446 return attr;
3485 } 3447 }
3486 3448
3491 */ 3453 */
3492 static int 3454 static int
3493 win32_setattrs(char_u *name, int attrs) 3455 win32_setattrs(char_u *name, int attrs)
3494 { 3456 {
3495 int res; 3457 int res;
3496 #ifdef FEAT_MBYTE
3497 WCHAR *p = NULL; 3458 WCHAR *p = NULL;
3498 3459
3499 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 3460 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3500 p = enc_to_utf16(name, NULL); 3461 p = enc_to_utf16(name, NULL);
3501 3462
3503 { 3464 {
3504 res = SetFileAttributesW(p, attrs); 3465 res = SetFileAttributesW(p, attrs);
3505 vim_free(p); 3466 vim_free(p);
3506 } 3467 }
3507 else 3468 else
3508 #endif
3509 res = SetFileAttributes((char *)name, attrs); 3469 res = SetFileAttributes((char *)name, attrs);
3510 3470
3511 return res ? 0 : -1; 3471 return res ? 0 : -1;
3512 } 3472 }
3513 3473
3619 int 3579 int
3620 mch_nodetype(char_u *name) 3580 mch_nodetype(char_u *name)
3621 { 3581 {
3622 HANDLE hFile; 3582 HANDLE hFile;
3623 int type; 3583 int type;
3624 #ifdef FEAT_MBYTE
3625 WCHAR *wn = NULL; 3584 WCHAR *wn = NULL;
3626 #endif
3627 3585
3628 /* We can't open a file with a name "\\.\con" or "\\.\prn" and trying to 3586 /* We can't open a file with a name "\\.\con" or "\\.\prn" and trying to
3629 * read from it later will cause Vim to hang. Thus return NODE_WRITABLE 3587 * read from it later will cause Vim to hang. Thus return NODE_WRITABLE
3630 * here. */ 3588 * here. */
3631 if (STRNCMP(name, "\\\\.\\", 4) == 0) 3589 if (STRNCMP(name, "\\\\.\\", 4) == 0)
3632 return NODE_WRITABLE; 3590 return NODE_WRITABLE;
3633 3591
3634 #ifdef FEAT_MBYTE
3635 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 3592 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3636 wn = enc_to_utf16(name, NULL); 3593 wn = enc_to_utf16(name, NULL);
3637 3594
3638 if (wn != NULL) 3595 if (wn != NULL)
3639 { 3596 {
3645 0, /* file attributes */ 3602 0, /* file attributes */
3646 NULL); /* handle to template file */ 3603 NULL); /* handle to template file */
3647 vim_free(wn); 3604 vim_free(wn);
3648 } 3605 }
3649 else 3606 else
3650 #endif
3651 hFile = CreateFile((LPCSTR)name, /* file name */ 3607 hFile = CreateFile((LPCSTR)name, /* file name */
3652 GENERIC_WRITE, /* access mode */ 3608 GENERIC_WRITE, /* access mode */
3653 0, /* share mode */ 3609 0, /* share mode */
3654 NULL, /* security descriptor */ 3610 NULL, /* security descriptor */
3655 OPEN_EXISTING, /* creation disposition */ 3611 OPEN_EXISTING, /* creation disposition */
3693 DWORD err; 3649 DWORD err;
3694 3650
3695 p = (struct my_acl *)alloc_clear((unsigned)sizeof(struct my_acl)); 3651 p = (struct my_acl *)alloc_clear((unsigned)sizeof(struct my_acl));
3696 if (p != NULL) 3652 if (p != NULL)
3697 { 3653 {
3698 # ifdef FEAT_MBYTE
3699 WCHAR *wn = NULL; 3654 WCHAR *wn = NULL;
3700 3655
3701 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 3656 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3702 wn = enc_to_utf16(fname, NULL); 3657 wn = enc_to_utf16(fname, NULL);
3703 if (wn != NULL) 3658 if (wn != NULL)
3735 p = NULL; 3690 p = NULL;
3736 } 3691 }
3737 vim_free(wn); 3692 vim_free(wn);
3738 } 3693 }
3739 else 3694 else
3740 # endif
3741 { 3695 {
3742 /* Try to retrieve the entire security descriptor. */ 3696 /* Try to retrieve the entire security descriptor. */
3743 err = GetNamedSecurityInfo( 3697 err = GetNamedSecurityInfo(
3744 (LPSTR)fname, // Abstract filename 3698 (LPSTR)fname, // Abstract filename
3745 SE_FILE_OBJECT, // File Object 3699 SE_FILE_OBJECT, // File Object
3813 struct my_acl *p = (struct my_acl *)acl; 3767 struct my_acl *p = (struct my_acl *)acl;
3814 SECURITY_INFORMATION sec_info = 0; 3768 SECURITY_INFORMATION sec_info = 0;
3815 3769
3816 if (p != NULL) 3770 if (p != NULL)
3817 { 3771 {
3818 # ifdef FEAT_MBYTE
3819 WCHAR *wn = NULL; 3772 WCHAR *wn = NULL;
3820 # endif
3821 3773
3822 /* Set security flags */ 3774 /* Set security flags */
3823 if (p->pSidOwner) 3775 if (p->pSidOwner)
3824 sec_info |= OWNER_SECURITY_INFORMATION; 3776 sec_info |= OWNER_SECURITY_INFORMATION;
3825 if (p->pSidGroup) 3777 if (p->pSidGroup)
3834 sec_info |= PROTECTED_DACL_SECURITY_INFORMATION; 3786 sec_info |= PROTECTED_DACL_SECURITY_INFORMATION;
3835 } 3787 }
3836 if (p->pSacl) 3788 if (p->pSacl)
3837 sec_info |= SACL_SECURITY_INFORMATION; 3789 sec_info |= SACL_SECURITY_INFORMATION;
3838 3790
3839 # ifdef FEAT_MBYTE
3840 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 3791 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3841 wn = enc_to_utf16(fname, NULL); 3792 wn = enc_to_utf16(fname, NULL);
3842 if (wn != NULL) 3793 if (wn != NULL)
3843 { 3794 {
3844 (void)SetNamedSecurityInfoW( 3795 (void)SetNamedSecurityInfoW(
3851 p->pSacl // For auditing purposes. 3802 p->pSacl // For auditing purposes.
3852 ); 3803 );
3853 vim_free(wn); 3804 vim_free(wn);
3854 } 3805 }
3855 else 3806 else
3856 # endif
3857 { 3807 {
3858 (void)SetNamedSecurityInfo( 3808 (void)SetNamedSecurityInfo(
3859 (LPSTR)fname, // Abstract filename 3809 (LPSTR)fname, // Abstract filename
3860 SE_FILE_OBJECT, // File Object 3810 SE_FILE_OBJECT, // File Object
3861 sec_info, 3811 sec_info,
4209 STARTUPINFO *si, 4159 STARTUPINFO *si,
4210 PROCESS_INFORMATION *pi, 4160 PROCESS_INFORMATION *pi,
4211 LPVOID *env, 4161 LPVOID *env,
4212 char *cwd) 4162 char *cwd)
4213 { 4163 {
4214 #ifdef FEAT_MBYTE
4215 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 4164 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
4216 { 4165 {
4217 BOOL ret; 4166 BOOL ret;
4218 WCHAR *wcmd, *wcwd = NULL; 4167 WCHAR *wcmd, *wcwd = NULL;
4219 4168
4245 if (wcwd != NULL) 4194 if (wcwd != NULL)
4246 vim_free(wcwd); 4195 vim_free(wcwd);
4247 return ret; 4196 return ret;
4248 } 4197 }
4249 fallback: 4198 fallback:
4250 #endif
4251 return CreateProcess( 4199 return CreateProcess(
4252 NULL, /* Executable name */ 4200 NULL, /* Executable name */
4253 cmd, /* Command to execute */ 4201 cmd, /* Command to execute */
4254 NULL, /* Process security attributes */ 4202 NULL, /* Process security attributes */
4255 NULL, /* Thread security attributes */ 4203 NULL, /* Thread security attributes */
4265 static HINSTANCE 4213 static HINSTANCE
4266 vim_shell_execute( 4214 vim_shell_execute(
4267 char *cmd, 4215 char *cmd,
4268 INT n_show_cmd) 4216 INT n_show_cmd)
4269 { 4217 {
4270 #ifdef FEAT_MBYTE
4271 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 4218 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
4272 { 4219 {
4273 WCHAR *wcmd = enc_to_utf16((char_u *)cmd, NULL); 4220 WCHAR *wcmd = enc_to_utf16((char_u *)cmd, NULL);
4274 if (wcmd != NULL) 4221 if (wcmd != NULL)
4275 { 4222 {
4277 ret = ShellExecuteW(NULL, NULL, wcmd, NULL, NULL, n_show_cmd); 4224 ret = ShellExecuteW(NULL, NULL, wcmd, NULL, NULL, n_show_cmd);
4278 vim_free(wcmd); 4225 vim_free(wcmd);
4279 return ret; 4226 return ret;
4280 } 4227 }
4281 } 4228 }
4282 #endif
4283 return ShellExecute(NULL, NULL, cmd, NULL, NULL, n_show_cmd); 4229 return ShellExecute(NULL, NULL, cmd, NULL, NULL, n_show_cmd);
4284 } 4230 }
4285 4231
4286 4232
4287 #if defined(FEAT_GUI_W32) || defined(PROTO) 4233 #if defined(FEAT_GUI_W32) || defined(PROTO)
4464 repeatCount = 0; 4410 repeatCount = 0;
4465 /* We got real data in the pipe, read it */ 4411 /* We got real data in the pipe, read it */
4466 while (ret != 0 && availableBytes > 0) 4412 while (ret != 0 && availableBytes > 0)
4467 { 4413 {
4468 repeatCount++; 4414 repeatCount++;
4469 toRead = 4415 toRead = (DWORD)(BUFLEN - *buffer_off);
4470 # ifdef FEAT_MBYTE
4471 (DWORD)(BUFLEN - *buffer_off);
4472 # else
4473 (DWORD)BUFLEN;
4474 # endif
4475 toRead = availableBytes < toRead ? availableBytes : toRead; 4416 toRead = availableBytes < toRead ? availableBytes : toRead;
4476 ReadFile(g_hChildStd_OUT_Rd, buffer 4417 ReadFile(g_hChildStd_OUT_Rd, buffer + *buffer_off, toRead , &len, NULL);
4477 # ifdef FEAT_MBYTE
4478 + *buffer_off, toRead
4479 # else
4480 , toRead
4481 # endif
4482 , &len, NULL);
4483 4418
4484 /* If we haven't read anything, there is a problem */ 4419 /* If we haven't read anything, there is a problem */
4485 if (len == 0) 4420 if (len == 0)
4486 break; 4421 break;
4487 4422
4499 ga_append(ga, NL); 4434 ga_append(ga, NL);
4500 else 4435 else
4501 ga_append(ga, buffer[i]); 4436 ga_append(ga, buffer[i]);
4502 } 4437 }
4503 } 4438 }
4504 # ifdef FEAT_MBYTE
4505 else if (has_mbyte) 4439 else if (has_mbyte)
4506 { 4440 {
4507 int l; 4441 int l;
4508 int c; 4442 int c;
4509 char_u *p; 4443 char_u *p;
4543 mch_memmove(buffer, p, *buffer_off); 4477 mch_memmove(buffer, p, *buffer_off);
4544 return; 4478 return;
4545 } 4479 }
4546 *buffer_off = 0; 4480 *buffer_off = 0;
4547 } 4481 }
4548 # endif /* FEAT_MBYTE */
4549 else 4482 else
4550 { 4483 {
4551 buffer[len] = NUL; 4484 buffer[len] = NUL;
4552 msg_puts((char *)buffer); 4485 msg_puts((char *)buffer);
4553 } 4486 }
4738 len -= 2; 4671 len -= 2;
4739 } 4672 }
4740 } 4673 }
4741 else if (ta_buf[i] == '\r') 4674 else if (ta_buf[i] == '\r')
4742 ta_buf[i] = '\n'; 4675 ta_buf[i] = '\n';
4743 # ifdef FEAT_MBYTE
4744 if (has_mbyte) 4676 if (has_mbyte)
4745 i += (*mb_ptr2len_len)(ta_buf + i, 4677 i += (*mb_ptr2len_len)(ta_buf + i,
4746 ta_len + len - i) - 1; 4678 ta_len + len - i) - 1;
4747 # endif
4748 } 4679 }
4749 4680
4750 /* 4681 /*
4751 * For pipes: echo the typed characters. For a pty this 4682 * For pipes: echo the typed characters. For a pty this
4752 * does not seem to work. 4683 * does not seem to work.
4753 */ 4684 */
4754 for (i = ta_len; i < ta_len + len; ++i) 4685 for (i = ta_len; i < ta_len + len; ++i)
4755 { 4686 {
4756 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') 4687 if (ta_buf[i] == '\n' || ta_buf[i] == '\b')
4757 msg_putchar(ta_buf[i]); 4688 msg_putchar(ta_buf[i]);
4758 # ifdef FEAT_MBYTE
4759 else if (has_mbyte) 4689 else if (has_mbyte)
4760 { 4690 {
4761 int l = (*mb_ptr2len)(ta_buf + i); 4691 int l = (*mb_ptr2len)(ta_buf + i);
4762 4692
4763 msg_outtrans_len(ta_buf + i, l); 4693 msg_outtrans_len(ta_buf + i, l);
4764 i += l - 1; 4694 i += l - 1;
4765 } 4695 }
4766 # endif
4767 else 4696 else
4768 msg_outtrans_len(ta_buf + i, 1); 4697 msg_outtrans_len(ta_buf + i, 1);
4769 } 4698 }
4770 windgoto(msg_row, msg_col); 4699 windgoto(msg_row, msg_col);
4771 out_flush(); 4700 out_flush();
4855 else 4784 else
4856 return mch_system_classic(cmd, options); 4785 return mch_system_classic(cmd, options);
4857 } 4786 }
4858 #else 4787 #else
4859 4788
4860 # ifdef FEAT_MBYTE
4861 static int 4789 static int
4862 mch_system(char *cmd, int options) 4790 mch_system(char *cmd, int options)
4863 { 4791 {
4864 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 4792 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
4865 { 4793 {
4871 return ret; 4799 return ret;
4872 } 4800 }
4873 } 4801 }
4874 return system(cmd); 4802 return system(cmd);
4875 } 4803 }
4876 # else
4877 # define mch_system(c, o) system(c)
4878 # endif
4879 4804
4880 #endif 4805 #endif
4881 4806
4882 #if defined(FEAT_GUI) && defined(FEAT_TERMINAL) 4807 #if defined(FEAT_GUI) && defined(FEAT_TERMINAL)
4883 /* 4808 /*
4970 { 4895 {
4971 int x = 0; 4896 int x = 0;
4972 int tmode = cur_tmode; 4897 int tmode = cur_tmode;
4973 #ifdef FEAT_TITLE 4898 #ifdef FEAT_TITLE
4974 char szShellTitle[512]; 4899 char szShellTitle[512];
4975 # ifdef FEAT_MBYTE
4976 int did_set_title = FALSE; 4900 int did_set_title = FALSE;
4977 4901
4978 /* Change the title to reflect that we are in a subshell. */ 4902 /* Change the title to reflect that we are in a subshell. */
4979 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 4903 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
4980 { 4904 {
5001 } 4925 }
5002 } 4926 }
5003 } 4927 }
5004 } 4928 }
5005 if (!did_set_title) 4929 if (!did_set_title)
5006 # endif
5007 /* Change the title to reflect that we are in a subshell. */ 4930 /* Change the title to reflect that we are in a subshell. */
5008 if (GetConsoleTitle(szShellTitle, sizeof(szShellTitle) - 4) > 0) 4931 if (GetConsoleTitle(szShellTitle, sizeof(szShellTitle) - 4) > 0)
5009 { 4932 {
5010 if (cmd == NULL) 4933 if (cmd == NULL)
5011 strcat(szShellTitle, " :sh"); 4934 strcat(szShellTitle, " :sh");
5215 { 5138 {
5216 char *msg = _("VIMRUN.EXE not found in your $PATH.\n" 5139 char *msg = _("VIMRUN.EXE not found in your $PATH.\n"
5217 "External commands will not pause after completion.\n" 5140 "External commands will not pause after completion.\n"
5218 "See :help win32-vimrun for more information."); 5141 "See :help win32-vimrun for more information.");
5219 char *title = _("Vim Warning"); 5142 char *title = _("Vim Warning");
5220 # ifdef FEAT_MBYTE
5221 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 5143 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
5222 { 5144 {
5223 WCHAR *wmsg = enc_to_utf16((char_u *)msg, NULL); 5145 WCHAR *wmsg = enc_to_utf16((char_u *)msg, NULL);
5224 WCHAR *wtitle = enc_to_utf16((char_u *)title, NULL); 5146 WCHAR *wtitle = enc_to_utf16((char_u *)title, NULL);
5225 5147
5227 MessageBoxW(NULL, wmsg, wtitle, MB_ICONWARNING); 5149 MessageBoxW(NULL, wmsg, wtitle, MB_ICONWARNING);
5228 vim_free(wmsg); 5150 vim_free(wmsg);
5229 vim_free(wtitle); 5151 vim_free(wtitle);
5230 } 5152 }
5231 else 5153 else
5232 # endif
5233 MessageBox(NULL, msg, title, MB_ICONWARNING); 5154 MessageBox(NULL, msg, title, MB_ICONWARNING);
5234 need_vimrun_warning = FALSE; 5155 need_vimrun_warning = FALSE;
5235 } 5156 }
5236 if (!s_dont_use_vimrun && p_stmp) 5157 if (!s_dont_use_vimrun && p_stmp)
5237 /* Use vimrun to execute the command. It opens a console 5158 /* Use vimrun to execute the command. It opens a console
5292 LPSECURITY_ATTRIBUTES lpSecurityAttributes, 5213 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
5293 DWORD dwCreationDisposition, 5214 DWORD dwCreationDisposition,
5294 DWORD dwFlagsAndAttributes) 5215 DWORD dwFlagsAndAttributes)
5295 { 5216 {
5296 HANDLE h; 5217 HANDLE h;
5297 # ifdef FEAT_MBYTE
5298 WCHAR *wn = NULL; 5218 WCHAR *wn = NULL;
5219
5299 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 5220 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
5300 { 5221 {
5301 wn = enc_to_utf16(fname, NULL); 5222 wn = enc_to_utf16(fname, NULL);
5302 if (wn != NULL) 5223 if (wn != NULL)
5303 { 5224 {
5306 dwFlagsAndAttributes, NULL); 5227 dwFlagsAndAttributes, NULL);
5307 vim_free(wn); 5228 vim_free(wn);
5308 } 5229 }
5309 } 5230 }
5310 if (wn == NULL) 5231 if (wn == NULL)
5311 # endif
5312 h = CreateFile((LPCSTR)fname, dwDesiredAccess, dwShareMode, 5232 h = CreateFile((LPCSTR)fname, dwDesiredAccess, dwShareMode,
5313 lpSecurityAttributes, dwCreationDisposition, 5233 lpSecurityAttributes, dwCreationDisposition,
5314 dwFlagsAndAttributes, NULL); 5234 dwFlagsAndAttributes, NULL);
5315 return h; 5235 return h;
5316 } 5236 }
6337 DWORD cbToWrite) 6257 DWORD cbToWrite)
6338 { 6258 {
6339 COORD coord = g_coord; 6259 COORD coord = g_coord;
6340 DWORD written; 6260 DWORD written;
6341 6261
6342 #ifdef FEAT_MBYTE
6343 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 6262 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
6344 { 6263 {
6345 static WCHAR *unicodebuf = NULL; 6264 static WCHAR *unicodebuf = NULL;
6346 static int unibuflen = 0; 6265 static int unibuflen = 0;
6347 int length; 6266 int length;
6390 written = p - pchBuf; 6309 written = p - pchBuf;
6391 g_coord.X += (SHORT)mb_string2cells(pchBuf, written); 6310 g_coord.X += (SHORT)mb_string2cells(pchBuf, written);
6392 } 6311 }
6393 } 6312 }
6394 else 6313 else
6395 #endif
6396 { 6314 {
6397 if (!USE_VTP) 6315 if (!USE_VTP)
6398 { 6316 {
6399 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cbToWrite, 6317 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cbToWrite,
6400 coord, &written); 6318 coord, &written);
6761 * Return 0 for success, -1 for failure. 6679 * Return 0 for success, -1 for failure.
6762 */ 6680 */
6763 int 6681 int
6764 mch_remove(char_u *name) 6682 mch_remove(char_u *name)
6765 { 6683 {
6766 #ifdef FEAT_MBYTE
6767 WCHAR *wn = NULL; 6684 WCHAR *wn = NULL;
6768 int n; 6685 int n;
6769 #endif
6770 6686
6771 /* 6687 /*
6772 * On Windows, deleting a directory's symbolic link is done by 6688 * On Windows, deleting a directory's symbolic link is done by
6773 * RemoveDirectory(): mch_rmdir. It seems unnatural, but it is fact. 6689 * RemoveDirectory(): mch_rmdir. It seems unnatural, but it is fact.
6774 */ 6690 */
6775 if (mch_isdir(name) && mch_is_symbolic_link(name)) 6691 if (mch_isdir(name) && mch_is_symbolic_link(name))
6776 return mch_rmdir(name); 6692 return mch_rmdir(name);
6777 6693
6778 win32_setattrs(name, FILE_ATTRIBUTE_NORMAL); 6694 win32_setattrs(name, FILE_ATTRIBUTE_NORMAL);
6779 6695
6780 #ifdef FEAT_MBYTE
6781 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 6696 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
6782 { 6697 {
6783 wn = enc_to_utf16(name, NULL); 6698 wn = enc_to_utf16(name, NULL);
6784 if (wn != NULL) 6699 if (wn != NULL)
6785 { 6700 {
6786 n = DeleteFileW(wn) ? 0 : -1; 6701 n = DeleteFileW(wn) ? 0 : -1;
6787 vim_free(wn); 6702 vim_free(wn);
6788 return n; 6703 return n;
6789 } 6704 }
6790 } 6705 }
6791 #endif
6792 return DeleteFile((LPCSTR)name) ? 0 : -1; 6706 return DeleteFile((LPCSTR)name) ? 0 : -1;
6793 } 6707 }
6794 6708
6795 6709
6796 /* 6710 /*
6837 } 6751 }
6838 /* Use physical RAM less reserve for OS + data. */ 6752 /* Use physical RAM less reserve for OS + data. */
6839 return (long_u)((ms.ullTotalPhys - WINNT_RESERVE_BYTES) / 1024); 6753 return (long_u)((ms.ullTotalPhys - WINNT_RESERVE_BYTES) / 1024);
6840 } 6754 }
6841 6755
6842 #ifdef FEAT_MBYTE
6843 /* 6756 /*
6844 * Same code as below, but with wide functions and no comments. 6757 * Same code as below, but with wide functions and no comments.
6845 * Return 0 for success, non-zero for failure. 6758 * Return 0 for success, non-zero for failure.
6846 */ 6759 */
6847 int 6760 int
6891 if (!DeleteFileW(wold)) 6804 if (!DeleteFileW(wold))
6892 return -8; 6805 return -8;
6893 6806
6894 return 0; 6807 return 0;
6895 } 6808 }
6896 #endif
6897 6809
6898 6810
6899 /* 6811 /*
6900 * mch_rename() works around a bug in rename (aka MoveFile) in 6812 * mch_rename() works around a bug in rename (aka MoveFile) in
6901 * Windows 95: rename("foo.bar", "foo.bar~") will generate a 6813 * Windows 95: rename("foo.bar", "foo.bar~") will generate a
6922 { 6834 {
6923 char szTempFile[_MAX_PATH+1]; 6835 char szTempFile[_MAX_PATH+1];
6924 char szNewPath[_MAX_PATH+1]; 6836 char szNewPath[_MAX_PATH+1];
6925 char *pszFilePart; 6837 char *pszFilePart;
6926 HANDLE hf; 6838 HANDLE hf;
6927 #ifdef FEAT_MBYTE
6928 WCHAR *wold = NULL; 6839 WCHAR *wold = NULL;
6929 WCHAR *wnew = NULL; 6840 WCHAR *wnew = NULL;
6930 int retval = -1; 6841 int retval = -1;
6931 6842
6932 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 6843 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
6937 retval = mch_wrename(wold, wnew); 6848 retval = mch_wrename(wold, wnew);
6938 vim_free(wold); 6849 vim_free(wold);
6939 vim_free(wnew); 6850 vim_free(wnew);
6940 return retval; 6851 return retval;
6941 } 6852 }
6942 #endif
6943 6853
6944 /* 6854 /*
6945 * No need to play tricks unless the file name contains a "~" as the 6855 * No need to play tricks unless the file name contains a "~" as the
6946 * seventh character. 6856 * seventh character.
6947 */ 6857 */
7022 int 6932 int
7023 mch_access(char *n, int p) 6933 mch_access(char *n, int p)
7024 { 6934 {
7025 HANDLE hFile; 6935 HANDLE hFile;
7026 int retval = -1; /* default: fail */ 6936 int retval = -1; /* default: fail */
7027 #ifdef FEAT_MBYTE
7028 WCHAR *wn = NULL; 6937 WCHAR *wn = NULL;
7029 6938
7030 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 6939 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
7031 wn = enc_to_utf16((char_u *)n, NULL); 6940 wn = enc_to_utf16((char_u *)n, NULL);
7032 #endif
7033 6941
7034 if (mch_isdir((char_u *)n)) 6942 if (mch_isdir((char_u *)n))
7035 { 6943 {
7036 char TempName[_MAX_PATH + 16] = ""; 6944 char TempName[_MAX_PATH + 16] = "";
7037 #ifdef FEAT_MBYTE
7038 WCHAR TempNameW[_MAX_PATH + 16] = L""; 6945 WCHAR TempNameW[_MAX_PATH + 16] = L"";
7039 #endif
7040 6946
7041 if (p & R_OK) 6947 if (p & R_OK)
7042 { 6948 {
7043 /* Read check is performed by seeing if we can do a find file on 6949 /* Read check is performed by seeing if we can do a find file on
7044 * the directory for any file. */ 6950 * the directory for any file. */
7045 #ifdef FEAT_MBYTE
7046 if (wn != NULL) 6951 if (wn != NULL)
7047 { 6952 {
7048 int i; 6953 int i;
7049 WIN32_FIND_DATAW d; 6954 WIN32_FIND_DATAW d;
7050 6955
7060 goto getout; 6965 goto getout;
7061 else 6966 else
7062 (void)FindClose(hFile); 6967 (void)FindClose(hFile);
7063 } 6968 }
7064 else 6969 else
7065 #endif
7066 { 6970 {
7067 char *pch; 6971 char *pch;
7068 WIN32_FIND_DATA d; 6972 WIN32_FIND_DATA d;
7069 6973
7070 vim_strncpy((char_u *)TempName, (char_u *)n, _MAX_PATH); 6974 vim_strncpy((char_u *)TempName, (char_u *)n, _MAX_PATH);
7085 { 6989 {
7086 /* Trying to create a temporary file in the directory should catch 6990 /* Trying to create a temporary file in the directory should catch
7087 * directories on read-only network shares. However, in 6991 * directories on read-only network shares. However, in
7088 * directories whose ACL allows writes but denies deletes will end 6992 * directories whose ACL allows writes but denies deletes will end
7089 * up keeping the temporary file :-(. */ 6993 * up keeping the temporary file :-(. */
7090 #ifdef FEAT_MBYTE
7091 if (wn != NULL) 6994 if (wn != NULL)
7092 { 6995 {
7093 if (!GetTempFileNameW(wn, L"VIM", 0, TempNameW)) 6996 if (!GetTempFileNameW(wn, L"VIM", 0, TempNameW))
7094 goto getout; 6997 goto getout;
7095 else 6998 else
7096 DeleteFileW(TempNameW); 6999 DeleteFileW(TempNameW);
7097 } 7000 }
7098 else 7001 else
7099 #endif
7100 { 7002 {
7101 if (!GetTempFileName(n, "VIM", 0, TempName)) 7003 if (!GetTempFileName(n, "VIM", 0, TempName))
7102 goto getout; 7004 goto getout;
7103 mch_remove((char_u *)TempName); 7005 mch_remove((char_u *)TempName);
7104 } 7006 }
7112 /* Trying to open the file for the required access does ACL, read-only 7014 /* Trying to open the file for the required access does ACL, read-only
7113 * network share, and file attribute checks. */ 7015 * network share, and file attribute checks. */
7114 DWORD access_mode = ((p & W_OK) ? GENERIC_WRITE : 0) 7016 DWORD access_mode = ((p & W_OK) ? GENERIC_WRITE : 0)
7115 | ((p & R_OK) ? GENERIC_READ : 0); 7017 | ((p & R_OK) ? GENERIC_READ : 0);
7116 7018
7117 #ifdef FEAT_MBYTE
7118 if (wn != NULL) 7019 if (wn != NULL)
7119 hFile = CreateFileW(wn, access_mode, share_mode, 7020 hFile = CreateFileW(wn, access_mode, share_mode,
7120 NULL, OPEN_EXISTING, 0, NULL); 7021 NULL, OPEN_EXISTING, 0, NULL);
7121 else 7022 else
7122 #endif
7123 hFile = CreateFile(n, access_mode, share_mode, 7023 hFile = CreateFile(n, access_mode, share_mode,
7124 NULL, OPEN_EXISTING, 0, NULL); 7024 NULL, OPEN_EXISTING, 0, NULL);
7125 if (hFile == INVALID_HANDLE_VALUE) 7025 if (hFile == INVALID_HANDLE_VALUE)
7126 goto getout; 7026 goto getout;
7127 CloseHandle(hFile); 7027 CloseHandle(hFile);
7128 } 7028 }
7129 7029
7130 retval = 0; /* success */ 7030 retval = 0; /* success */
7131 getout: 7031 getout:
7132 #ifdef FEAT_MBYTE
7133 vim_free(wn); 7032 vim_free(wn);
7134 #endif
7135 return retval; 7033 return retval;
7136 } 7034 }
7137 7035
7138 #if defined(FEAT_MBYTE) || defined(PROTO)
7139 /* 7036 /*
7140 * Version of open() that may use UTF-16 file name. 7037 * Version of open() that may use UTF-16 file name.
7141 */ 7038 */
7142 int 7039 int
7143 mch_open(const char *name, int flags, int mode) 7040 mch_open(const char *name, int flags, int mode)
7144 { 7041 {
7145 /* _wopen() does not work with Borland C 5.5: creates a read-only file. */ 7042 /* _wopen() does not work with Borland C 5.5: creates a read-only file. */
7146 # ifndef __BORLANDC__ 7043 #ifndef __BORLANDC__
7147 WCHAR *wn; 7044 WCHAR *wn;
7148 int f; 7045 int f;
7149 7046
7150 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 7047 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
7151 { 7048 {
7155 f = _wopen(wn, flags, mode); 7052 f = _wopen(wn, flags, mode);
7156 vim_free(wn); 7053 vim_free(wn);
7157 return f; 7054 return f;
7158 } 7055 }
7159 } 7056 }
7160 # endif 7057 #endif
7161 7058
7162 /* open() can open a file which name is longer than _MAX_PATH bytes 7059 /* open() can open a file which name is longer than _MAX_PATH bytes
7163 * and shorter than _MAX_PATH characters successfully, but sometimes it 7060 * and shorter than _MAX_PATH characters successfully, but sometimes it
7164 * causes unexpected error in another part. We make it an error explicitly 7061 * causes unexpected error in another part. We make it an error explicitly
7165 * here. */ 7062 * here. */
7178 WCHAR *wn, *wm; 7075 WCHAR *wn, *wm;
7179 FILE *f = NULL; 7076 FILE *f = NULL;
7180 7077
7181 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 7078 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
7182 { 7079 {
7183 # if defined(DEBUG) && _MSC_VER >= 1400 7080 #if defined(DEBUG) && _MSC_VER >= 1400
7184 /* Work around an annoying assertion in the Microsoft debug CRT 7081 /* Work around an annoying assertion in the Microsoft debug CRT
7185 * when mode's text/binary setting doesn't match _get_fmode(). */ 7082 * when mode's text/binary setting doesn't match _get_fmode(). */
7186 char newMode = mode[strlen(mode) - 1]; 7083 char newMode = mode[strlen(mode) - 1];
7187 int oldMode = 0; 7084 int oldMode = 0;
7188 7085
7189 _get_fmode(&oldMode); 7086 _get_fmode(&oldMode);
7190 if (newMode == 't') 7087 if (newMode == 't')
7191 _set_fmode(_O_TEXT); 7088 _set_fmode(_O_TEXT);
7192 else if (newMode == 'b') 7089 else if (newMode == 'b')
7193 _set_fmode(_O_BINARY); 7090 _set_fmode(_O_BINARY);
7194 # endif 7091 #endif
7195 wn = enc_to_utf16((char_u *)name, NULL); 7092 wn = enc_to_utf16((char_u *)name, NULL);
7196 wm = enc_to_utf16((char_u *)mode, NULL); 7093 wm = enc_to_utf16((char_u *)mode, NULL);
7197 if (wn != NULL && wm != NULL) 7094 if (wn != NULL && wm != NULL)
7198 f = _wfopen(wn, wm); 7095 f = _wfopen(wn, wm);
7199 vim_free(wn); 7096 vim_free(wn);
7200 vim_free(wm); 7097 vim_free(wm);
7201 7098
7202 # if defined(DEBUG) && _MSC_VER >= 1400 7099 #if defined(DEBUG) && _MSC_VER >= 1400
7203 _set_fmode(oldMode); 7100 _set_fmode(oldMode);
7204 # endif 7101 #endif
7205 return f; 7102 return f;
7206 } 7103 }
7207 7104
7208 /* fopen() can open a file which name is longer than _MAX_PATH bytes 7105 /* fopen() can open a file which name is longer than _MAX_PATH bytes
7209 * and shorter than _MAX_PATH characters successfully, but sometimes it 7106 * and shorter than _MAX_PATH characters successfully, but sometimes it
7212 if (strlen(name) >= _MAX_PATH) 7109 if (strlen(name) >= _MAX_PATH)
7213 return NULL; 7110 return NULL;
7214 7111
7215 return fopen(name, mode); 7112 return fopen(name, mode);
7216 } 7113 }
7217 #endif 7114
7218
7219 #ifdef FEAT_MBYTE
7220 /* 7115 /*
7221 * SUB STREAM (aka info stream) handling: 7116 * SUB STREAM (aka info stream) handling:
7222 * 7117 *
7223 * NTFS can have sub streams for each file. Normal contents of file is 7118 * NTFS can have sub streams for each file. Normal contents of file is
7224 * stored in the main stream, and extra contents (author information and 7119 * stored in the main stream, and extra contents (author information and
7358 } 7253 }
7359 } 7254 }
7360 vim_free(fromw); 7255 vim_free(fromw);
7361 vim_free(tow); 7256 vim_free(tow);
7362 } 7257 }
7363 #endif
7364 7258
7365 /* 7259 /*
7366 * Copy file attributes from file "from" to file "to". 7260 * Copy file attributes from file "from" to file "to".
7367 * For Windows NT and later we copy info streams. 7261 * For Windows NT and later we copy info streams.
7368 * Always returns zero, errors are ignored. 7262 * Always returns zero, errors are ignored.
7369 */ 7263 */
7370 int 7264 int
7371 mch_copy_file_attribute(char_u *from, char_u *to) 7265 mch_copy_file_attribute(char_u *from, char_u *to)
7372 { 7266 {
7373 #ifdef FEAT_MBYTE
7374 /* File streams only work on Windows NT and later. */ 7267 /* File streams only work on Windows NT and later. */
7375 PlatformId(); 7268 PlatformId();
7376 copy_infostreams(from, to); 7269 copy_infostreams(from, to);
7377 #endif
7378 return 0; 7270 return 0;
7379 } 7271 }
7380 7272
7381 #if defined(MYRESETSTKOFLW) || defined(PROTO) 7273 #if defined(MYRESETSTKOFLW) || defined(PROTO)
7382 /* 7274 /*
7462 return 1; 7354 return 1;
7463 } 7355 }
7464 #endif 7356 #endif
7465 7357
7466 7358
7467 #if defined(FEAT_MBYTE) || defined(PROTO)
7468 /* 7359 /*
7469 * The command line arguments in UCS2 7360 * The command line arguments in UCS2
7470 */ 7361 */
7471 static int nArgsW = 0; 7362 static int nArgsW = 0;
7472 static LPWSTR *ArglistW = NULL; 7363 static LPWSTR *ArglistW = NULL;
7689 (void)vim_chdirfile(alist_name(&GARGLIST[0]), "drop"); 7580 (void)vim_chdirfile(alist_name(&GARGLIST[0]), "drop");
7690 } 7581 }
7691 7582
7692 set_alist_count(); 7583 set_alist_count();
7693 } 7584 }
7694 #endif
7695 7585
7696 int 7586 int
7697 mch_setenv(char *var, char *value, int x) 7587 mch_setenv(char *var, char *value, int x)
7698 { 7588 {
7699 char_u *envbuf; 7589 char_u *envbuf;
7702 if (envbuf == NULL) 7592 if (envbuf == NULL)
7703 return -1; 7593 return -1;
7704 7594
7705 sprintf((char *)envbuf, "%s=%s", var, value); 7595 sprintf((char *)envbuf, "%s=%s", var, value);
7706 7596
7707 #ifdef FEAT_MBYTE
7708 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) 7597 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
7709 { 7598 {
7710 WCHAR *p = enc_to_utf16(envbuf, NULL); 7599 WCHAR *p = enc_to_utf16(envbuf, NULL);
7711 7600
7712 vim_free(envbuf); 7601 vim_free(envbuf);
7713 if (p == NULL) 7602 if (p == NULL)
7714 return -1; 7603 return -1;
7715 _wputenv(p); 7604 _wputenv(p);
7716 # ifdef libintl_wputenv 7605 #ifdef libintl_wputenv
7717 libintl_wputenv(p); 7606 libintl_wputenv(p);
7718 # endif 7607 #endif
7719 /* Unlike Un*x systems, we can free the string for _wputenv(). */ 7608 /* Unlike Un*x systems, we can free the string for _wputenv(). */
7720 vim_free(p); 7609 vim_free(p);
7721 } 7610 }
7722 else 7611 else
7723 #endif
7724 { 7612 {
7725 _putenv((char *)envbuf); 7613 _putenv((char *)envbuf);
7726 #ifdef libintl_putenv 7614 #ifdef libintl_putenv
7727 libintl_putenv((char *)envbuf); 7615 libintl_putenv((char *)envbuf);
7728 #endif 7616 #endif