Klaus Demo nginx / 10fa102
disable Win32 short file names Igor Sysoev 10 years ago
1 changed file(s) with 51 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
99
1010 #define NGX_UTF16_BUFLEN 256
1111
12 static u_short *ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t len);
12 static u_short *ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t *len);
1313
1414
1515 /* FILE_FLAG_BACKUP_SEMANTICS allows to obtain a handle to a directory */
1717 ngx_fd_t
1818 ngx_open_file(u_char *name, u_long mode, u_long create, u_long access)
1919 {
20 u_short *u;
20 size_t len;
21 u_long n;
22 u_short *u, *lu;
2123 ngx_fd_t fd;
2224 ngx_err_t err;
2325 u_short utf16[NGX_UTF16_BUFLEN];
2426
25 u = ngx_utf8_to_utf16(utf16, name, NGX_UTF16_BUFLEN);
27 len = NGX_UTF16_BUFLEN;
28 u = ngx_utf8_to_utf16(utf16, name, &len);
2629
2730 if (u == NULL) {
2831 return INVALID_HANDLE_VALUE;
32 }
33
34 fd = INVALID_HANDLE_VALUE;
35 lu = NULL;
36
37 if (create == NGX_FILE_OPEN) {
38
39 lu = malloc(len * 2);
40 if (lu == NULL) {
41 goto failed;
42 }
43
44 n = GetLongPathNameW(u, lu, len);
45
46 if (n == 0) {
47 goto failed;
48 }
49
50 if (n != len - 1 || ngx_memcmp(u, lu, n) != 0) {
51 ngx_set_errno(NGX_ENOENT);
52 goto failed;
53 }
2954 }
3055
3156 fd = CreateFileW(u, mode,
3257 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3358 NULL, create, FILE_FLAG_BACKUP_SEMANTICS, NULL);
3459
60 failed:
61
62 err = ngx_errno;
63
64 if (lu) {
65 ngx_free(lu);
66 }
67
3568 if (u != utf16) {
36 err = ngx_errno;
3769 ngx_free(u);
38 ngx_set_errno(err);
39 }
70 }
71
72 ngx_set_errno(err);
4073
4174 return fd;
4275 }
243276 ngx_int_t
244277 ngx_file_info(u_char *file, ngx_file_info_t *sb)
245278 {
279 size_t len;
246280 long rc;
247281 u_short *u;
248282 ngx_err_t err;
249283 WIN32_FILE_ATTRIBUTE_DATA fa;
250284 u_short utf16[NGX_UTF16_BUFLEN];
251285
252 u = ngx_utf8_to_utf16(utf16, file, NGX_UTF16_BUFLEN);
286 len = NGX_UTF16_BUFLEN;
287
288 u = ngx_utf8_to_utf16(utf16, file, &len);
253289
254290 if (u == NULL) {
255291 return NGX_FILE_ERROR;
510546
511547
512548 static u_short *
513 ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t len)
549 ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t *len)
514550 {
515551 u_char *p;
516552 u_short *u, *last;
518554
519555 p = utf8;
520556 u = utf16;
521 last = utf16 + len;
557 last = utf16 + *len;
522558
523559 while (u < last) {
524560
525561 if (*p < 0x80) {
526 *u = (u_short) *p;
562 *u++ = (u_short) *p;
527563
528564 if (*p == 0) {
565 *len = u - utf16;
529566 return utf16;
530567 }
531568
532 u++;
533569 p++;
534570
535571 continue;
553589 return NULL;
554590 }
555591
556 ngx_memcpy(u, utf16, len * 2);
592 ngx_memcpy(u, utf16, *len * 2);
557593
558594 utf16 = u;
559 u += len;
595 u += *len;
560596
561597 for ( ;; ) {
562598
563599 if (*p < 0x80) {
564 *u = (u_short) *p;
600 *u++ = (u_short) *p;
565601
566602 if (*p == 0) {
603 *len = u - utf16;
567604 return utf16;
568605 }
569606
570 u++;
571607 p++;
572608
573609 continue;