Mercurial > hg > nginx
comparison src/os/win32/ngx_files.c @ 3417:15017418fd84
disable Win32 short file names
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 28 Jan 2010 14:17:51 +0000 |
parents | 6be1f25bae90 |
children | bdcae1a576e3 |
comparison
equal
deleted
inserted
replaced
3416:ee713c767b25 | 3417:15017418fd84 |
---|---|
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 | 9 |
10 | 10 |
11 #define NGX_UTF16_BUFLEN 256 | 11 #define NGX_UTF16_BUFLEN 256 |
12 | 12 |
13 static u_short *ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t len); | 13 static u_short *ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t *len); |
14 | 14 |
15 | 15 |
16 /* FILE_FLAG_BACKUP_SEMANTICS allows to obtain a handle to a directory */ | 16 /* FILE_FLAG_BACKUP_SEMANTICS allows to obtain a handle to a directory */ |
17 | 17 |
18 ngx_fd_t | 18 ngx_fd_t |
19 ngx_open_file(u_char *name, u_long mode, u_long create, u_long access) | 19 ngx_open_file(u_char *name, u_long mode, u_long create, u_long access) |
20 { | 20 { |
21 u_short *u; | 21 size_t len; |
22 u_long n; | |
23 u_short *u, *lu; | |
22 ngx_fd_t fd; | 24 ngx_fd_t fd; |
23 ngx_err_t err; | 25 ngx_err_t err; |
24 u_short utf16[NGX_UTF16_BUFLEN]; | 26 u_short utf16[NGX_UTF16_BUFLEN]; |
25 | 27 |
26 u = ngx_utf8_to_utf16(utf16, name, NGX_UTF16_BUFLEN); | 28 len = NGX_UTF16_BUFLEN; |
29 u = ngx_utf8_to_utf16(utf16, name, &len); | |
27 | 30 |
28 if (u == NULL) { | 31 if (u == NULL) { |
29 return INVALID_HANDLE_VALUE; | 32 return INVALID_HANDLE_VALUE; |
33 } | |
34 | |
35 fd = INVALID_HANDLE_VALUE; | |
36 lu = NULL; | |
37 | |
38 if (create == NGX_FILE_OPEN) { | |
39 | |
40 lu = malloc(len * 2); | |
41 if (lu == NULL) { | |
42 goto failed; | |
43 } | |
44 | |
45 n = GetLongPathNameW(u, lu, len); | |
46 | |
47 if (n == 0) { | |
48 goto failed; | |
49 } | |
50 | |
51 if (n != len - 1 || ngx_memcmp(u, lu, n) != 0) { | |
52 ngx_set_errno(NGX_ENOENT); | |
53 goto failed; | |
54 } | |
30 } | 55 } |
31 | 56 |
32 fd = CreateFileW(u, mode, | 57 fd = CreateFileW(u, mode, |
33 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, | 58 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, |
34 NULL, create, FILE_FLAG_BACKUP_SEMANTICS, NULL); | 59 NULL, create, FILE_FLAG_BACKUP_SEMANTICS, NULL); |
35 | 60 |
61 failed: | |
62 | |
63 err = ngx_errno; | |
64 | |
65 if (lu) { | |
66 ngx_free(lu); | |
67 } | |
68 | |
36 if (u != utf16) { | 69 if (u != utf16) { |
37 err = ngx_errno; | |
38 ngx_free(u); | 70 ngx_free(u); |
39 ngx_set_errno(err); | 71 } |
40 } | 72 |
73 ngx_set_errno(err); | |
41 | 74 |
42 return fd; | 75 return fd; |
43 } | 76 } |
44 | 77 |
45 | 78 |
242 | 275 |
243 | 276 |
244 ngx_int_t | 277 ngx_int_t |
245 ngx_file_info(u_char *file, ngx_file_info_t *sb) | 278 ngx_file_info(u_char *file, ngx_file_info_t *sb) |
246 { | 279 { |
280 size_t len; | |
247 long rc; | 281 long rc; |
248 u_short *u; | 282 u_short *u; |
249 ngx_err_t err; | 283 ngx_err_t err; |
250 WIN32_FILE_ATTRIBUTE_DATA fa; | 284 WIN32_FILE_ATTRIBUTE_DATA fa; |
251 u_short utf16[NGX_UTF16_BUFLEN]; | 285 u_short utf16[NGX_UTF16_BUFLEN]; |
252 | 286 |
253 u = ngx_utf8_to_utf16(utf16, file, NGX_UTF16_BUFLEN); | 287 len = NGX_UTF16_BUFLEN; |
288 | |
289 u = ngx_utf8_to_utf16(utf16, file, &len); | |
254 | 290 |
255 if (u == NULL) { | 291 if (u == NULL) { |
256 return NGX_FILE_ERROR; | 292 return NGX_FILE_ERROR; |
257 } | 293 } |
258 | 294 |
509 return sc * bs; | 545 return sc * bs; |
510 } | 546 } |
511 | 547 |
512 | 548 |
513 static u_short * | 549 static u_short * |
514 ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t len) | 550 ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t *len) |
515 { | 551 { |
516 u_char *p; | 552 u_char *p; |
517 u_short *u, *last; | 553 u_short *u, *last; |
518 uint32_t n; | 554 uint32_t n; |
519 | 555 |
520 p = utf8; | 556 p = utf8; |
521 u = utf16; | 557 u = utf16; |
522 last = utf16 + len; | 558 last = utf16 + *len; |
523 | 559 |
524 while (u < last) { | 560 while (u < last) { |
525 | 561 |
526 if (*p < 0x80) { | 562 if (*p < 0x80) { |
527 *u = (u_short) *p; | 563 *u++ = (u_short) *p; |
528 | 564 |
529 if (*p == 0) { | 565 if (*p == 0) { |
566 *len = u - utf16; | |
530 return utf16; | 567 return utf16; |
531 } | 568 } |
532 | 569 |
533 u++; | |
534 p++; | 570 p++; |
535 | 571 |
536 continue; | 572 continue; |
537 } | 573 } |
538 | 574 |
552 u = malloc(((p - utf8) + ngx_strlen(p) + 1) * sizeof(u_short)); | 588 u = malloc(((p - utf8) + ngx_strlen(p) + 1) * sizeof(u_short)); |
553 if (u == NULL) { | 589 if (u == NULL) { |
554 return NULL; | 590 return NULL; |
555 } | 591 } |
556 | 592 |
557 ngx_memcpy(u, utf16, len * 2); | 593 ngx_memcpy(u, utf16, *len * 2); |
558 | 594 |
559 utf16 = u; | 595 utf16 = u; |
560 u += len; | 596 u += *len; |
561 | 597 |
562 for ( ;; ) { | 598 for ( ;; ) { |
563 | 599 |
564 if (*p < 0x80) { | 600 if (*p < 0x80) { |
565 *u = (u_short) *p; | 601 *u++ = (u_short) *p; |
566 | 602 |
567 if (*p == 0) { | 603 if (*p == 0) { |
604 *len = u - utf16; | |
568 return utf16; | 605 return utf16; |
569 } | 606 } |
570 | 607 |
571 u++; | |
572 p++; | 608 p++; |
573 | 609 |
574 continue; | 610 continue; |
575 } | 611 } |
576 | 612 |