16
16
#include "missing/file.h"
17
17
#endif
18
18
#ifdef __CYGWIN__
19
+ #define OpenFile WINAPI_OpenFile
19
20
#include <windows.h>
20
21
#include <sys/cygwin.h>
22
+ #undef OpenFile
21
23
#endif
22
24
23
- #define OpenFile rb_io_t
24
25
#include "ruby.h"
25
26
#include "rubyio.h"
26
27
#include "rubysig.h"
@@ -2329,18 +2330,6 @@ rb_file_s_umask(argc, argv)
2329
2330
# endif
2330
2331
#endif
2331
2332
2332
- #if defined _WIN32 || defined __CYGWIN__
2333
- #define USE_NTFS 1
2334
- #else
2335
- #define USE_NTFS 0
2336
- #endif
2337
-
2338
- #if USE_NTFS
2339
- #define istrailinggabage (x ) ((x) == '.' || (x) == ' ')
2340
- #else
2341
- #define istrailinggabage (x ) 0
2342
- #endif
2343
-
2344
2333
#ifdef DOSISH_DRIVE_LETTER
2345
2334
static inline int
2346
2335
has_drive_letter (buf )
@@ -2452,9 +2441,8 @@ rb_path_last_separator(path)
2452
2441
return last ;
2453
2442
}
2454
2443
2455
- #define chompdirsep rb_path_end
2456
2444
char *
2457
- rb_path_end (path )
2445
+ chompdirsep (path )
2458
2446
const char * path ;
2459
2447
{
2460
2448
while (* path ) {
@@ -2469,35 +2457,20 @@ rb_path_end(path)
2469
2457
}
2470
2458
return (char * )path ;
2471
2459
}
2472
-
2473
- #if USE_NTFS
2474
- static char *
2475
- ntfs_tail ( const char * path )
2460
+
2461
+ char *
2462
+ rb_path_end ( path )
2463
+ const char * path ;
2476
2464
{
2477
- while (* path && * path != ':' ) {
2478
- if (istrailinggabage (* path )) {
2479
- const char * last = path ++ ;
2480
- while (istrailinggabage (* path )) path ++ ;
2481
- if (!* path || * path == ':' ) return (char * )last ;
2482
- }
2483
- else if (isdirsep (* path )) {
2484
- const char * last = path ++ ;
2485
- while (isdirsep (* path )) path ++ ;
2486
- if (!* path ) return (char * )last ;
2487
- if (* path == ':' ) path ++ ;
2488
- }
2489
- else {
2490
- path = CharNext (path );
2491
- }
2492
- }
2493
- return (char * )path ;
2465
+ if (isdirsep (* path )) path ++ ;
2466
+ return chompdirsep (path );
2494
2467
}
2495
- #endif
2496
2468
2497
2469
#if USE_NTFS
2498
2470
static char *
2499
2471
ntfs_tail (const char * path )
2500
2472
{
2473
+ while (* path == '.' ) path ++ ;
2501
2474
while (* path && * path != ':' ) {
2502
2475
if (istrailinggabage (* path )) {
2503
2476
const char * last = path ++ ;
@@ -2527,10 +2500,6 @@ ntfs_tail(const char *path)
2527
2500
p = buf + bdiff;\
2528
2501
pend = buf + buflen;\
2529
2502
}\
2530
- rb_str_resize(result, buflen);\
2531
- buf = RSTRING(result)->ptr;\
2532
- p = buf + bdiff;\
2533
- pend = buf + buflen;\
2534
2503
} while (0)
2535
2504
2536
2505
#define BUFINIT () (\
@@ -2769,53 +2738,54 @@ file_expand_path(fname, dname, result)
276
B83A
9
2738
2770
2739
#if USE_NTFS
2771
2740
* p = '\0' ;
2772
- if (! strpbrk ( b = buf , "*?" )) {
2741
+ if (( s = strrdirsep ( b = buf )) != 0 && ! strpbrk ( s , "*?" )) {
2773
2742
size_t len ;
2774
2743
WIN32_FIND_DATA wfd ;
2775
2744
#ifdef __CYGWIN__
2776
- int lnk_added = 0 ;
2745
+ int lnk_added = 0 , is_symlink = 0 ;
2777
2746
struct stat st ;
2778
- char w32buf [MAXPATHLEN ], sep = 0 ;
2779
- p = 0 ;
2747
+ char w32buf [MAXPATHLEN ];
2748
+ p = ( char * ) s ;
2780
2749
if (lstat (buf , & st ) == 0 && S_ISLNK (st .st_mode )) {
2781
- p = strrdirsep (buf );
2782
- if (!p ) p = skipprefix (buf );
2783
- if (p ) {
2784
- sep = * p ;
2785
- * p = '\0' ;
2786
- }
2750
+ is_symlink = 1 ;
2751
+ * p = '\0' ;
2787
2752
}
2788
- if (cygwin_conv_to_win32_path (buf , w32buf ) == 0 ) {
2753
+ if (cygwin_conv_to_win32_path (( * buf ? buf : "/" ) , w32buf ) == 0 ) {
2789
2754
b = w32buf ;
2790
2755
}
2791
- if (p ) * p = sep ;
2792
- else p = buf ;
2793
- if (b == w32buf ) {
2756
+ if (is_symlink && b == w32buf ) {
2757
+ * p = '\\' ;
2794
2758
strlcat (w32buf , p , sizeof (w32buf ));
2795
2759
len = strlen (p );
2796
2760
if (len > 4 && strcasecmp (p + len - 4 , ".lnk" ) != 0 ) {
2797
2761
lnk_added = 1 ;
2798
2762
strlcat (w32buf , ".lnk" , sizeof (w32buf ));
2799
2763
}
2800
2764
}
2765
+ * p = '/' ;
2801
2766
#endif
2802
2767
HANDLE h = FindFirstFile (b , & wfd );
2803
2768
if (h != INVALID_HANDLE_VALUE ) {
2804
2769
FindClose (h );
2805
- p = strrdirsep (buf );
2806
2770
len = strlen (wfd .cFileName );
2807
2771
#ifdef __CYGWIN__
2808
2772
if (lnk_added && len > 4 &&
2809
2773
strcasecmp (wfd .cFileName + len - 4 , ".lnk" ) == 0 ) {
2810
- len -= 4 ;
2774
+ wfd . cFileName [ len -= 4 ] = '\0' ;
2811
2775
}
2776
+ #else
2777
+ p = (char * )s ;
2812
2778
#endif
2813
- if (!p ) p = buf ;
2814
- buflen = ++ p - buf + len ;
2815
- rb_str_resize (result , buflen );
2779
+ ++ p ;
2780
+ BUFCHECK (bdiff + len >= buflen );
2816
2781
memcpy (p , wfd .cFileName , len + 1 );
2817
2782
p += len ;
2818
2783
}
2784
+ #ifdef __CYGWIN__
2785
+ else {
2786
+ p += strlen (p );
2787
+ }
2788
+ #endif
2819
2789
}
2820
2790
#endif
2821
2791
@@ -3051,7 +3021,7 @@ rb_file_s_extname(klass, fname)
3051
3021
if (!p )
3052
3022
p = name ;
3053
3023
else
3054
- p ++ ;
3024
+ name = ++ p ;
3055
3025
3056
3026
e = 0 ;
3057
3027
while (* p ) {
@@ -3081,7 +3051,7 @@ rb_file_s_extname(klass, fname)
3081
3051
break ;
3082
3052
p = CharNext (p );
3083
3053
}
3084
- if (!e || e + 1 == p ) /* no dot, or the only dot is first or end? */
3054
+ if (!e || e == name || e + 1 == p ) /* no dot, or the only dot is first or end? */
3085
3055
return rb_str_new (0 , 0 );
3086
3056
extname = rb_str_new (e , p - e ); /* keep the dot, too! */
3087
3057
OBJ_INFECT (extname , fname );
0 commit comments