comparison src/os/win32/ngx_files.c @ 8141:2acb00b9b5ff

Win32: non-ASCII names in ngx_fs_bsize(), ngx_fs_available(). This fixes potentially incorrect cache size calculations and non-working "min_free" when using cache in directories with non-ASCII names.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 23 Feb 2023 20:50:03 +0300
parents c33eb93f9c7a
children
comparison
equal deleted inserted replaced
8140:c33eb93f9c7a 8141:2acb00b9b5ff
965 965
966 966
967 size_t 967 size_t
968 ngx_fs_bsize(u_char *name) 968 ngx_fs_bsize(u_char *name)
969 { 969 {
970 u_long sc, bs, nfree, ncl; 970 u_long sc, bs, nfree, ncl;
971 971 size_t len;
972 if (GetDiskFreeSpace((const char *) name, &sc, &bs, &nfree, &ncl) == 0) { 972 u_short *u;
973 u_short utf16[NGX_UTF16_BUFLEN];
974
975 len = NGX_UTF16_BUFLEN;
976 u = ngx_utf8_to_utf16(utf16, name, &len, 0);
977
978 if (u == NULL) {
973 return 512; 979 return 512;
980 }
981
982 if (GetDiskFreeSpaceW(u, &sc, &bs, &nfree, &ncl) == 0) {
983
984 if (u != utf16) {
985 ngx_free(u);
986 }
987
988 return 512;
989 }
990
991 if (u != utf16) {
992 ngx_free(u);
974 } 993 }
975 994
976 return sc * bs; 995 return sc * bs;
977 } 996 }
978 997
979 998
980 off_t 999 off_t
981 ngx_fs_available(u_char *name) 1000 ngx_fs_available(u_char *name)
982 { 1001 {
983 ULARGE_INTEGER navail; 1002 size_t len;
984 1003 u_short *u;
985 if (GetDiskFreeSpaceEx((const char *) name, &navail, NULL, NULL) == 0) { 1004 ULARGE_INTEGER navail;
1005 u_short utf16[NGX_UTF16_BUFLEN];
1006
1007 len = NGX_UTF16_BUFLEN;
1008 u = ngx_utf8_to_utf16(utf16, name, &len, 0);
1009
1010 if (u == NULL) {
986 return NGX_MAX_OFF_T_VALUE; 1011 return NGX_MAX_OFF_T_VALUE;
1012 }
1013
1014 if (GetDiskFreeSpaceExW(u, &navail, NULL, NULL) == 0) {
1015
1016 if (u != utf16) {
1017 ngx_free(u);
1018 }
1019
1020 return NGX_MAX_OFF_T_VALUE;
1021 }
1022
1023 if (u != utf16) {
1024 ngx_free(u);
987 } 1025 }
988 1026
989 return (off_t) navail.QuadPart; 1027 return (off_t) navail.QuadPart;
990 } 1028 }
991 1029