[前][次][番号順一覧][スレッド一覧]

ruby-changes:44923

From: nobu <ko1@a...>
Date: Tue, 6 Dec 2016 16:21:59 +0900 (JST)
Subject: [ruby-changes:44923] nobu:r56996 (trunk): file.c: isADS

nobu	2016-12-06 16:21:55 +0900 (Tue, 06 Dec 2016)

  New Revision: 56996

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56996

  Log:
    file.c: isADS
    
    * file.c (isADS): add macro to tell if Alternate Data Stream
      separator, to distinguish from drive letter.

  Modified files:
    trunk/file.c
Index: file.c
===================================================================
--- file.c	(revision 56995)
+++ file.c	(revision 56996)
@@ -2922,12 +2922,24 @@ static const char file_alt_separator[] = https://github.com/ruby/ruby/blob/trunk/file.c#L2922
 #define USE_NTFS 0
 #endif
 #endif
+#ifndef USE_NTFS_ADS
+# if USE_NTFS
+#   define USE_NTFS_ADS 1
+# else
+#   define USE_NTFS_ADS 0
+# endif
+#endif
 
 #if USE_NTFS
 #define istrailinggarbage(x) ((x) == '.' || (x) == ' ')
 #else
 #define istrailinggarbage(x) 0
 #endif
+#if USE_NTFS_ADS
+# define isADS(x) ((x) == ':')
+#else
+# define isADS(x) 0
+#endif
 
 #define Next(p, e, enc) ((p) + rb_enc_mbclen((p), (e), (enc)))
 #define Inc(p, e, enc) ((p) = Next((p), (e), (enc)))
@@ -3098,17 +3110,17 @@ static char * https://github.com/ruby/ruby/blob/trunk/file.c#L3110
 ntfs_tail(const char *path, const char *end, rb_encoding *enc)
 {
     while (path < end && *path == '.') path++;
-    while (path < end && *path != ':') {
+    while (path < end && !isADS(*path)) {
 	if (istrailinggarbage(*path)) {
 	    const char *last = path++;
 	    while (path < end && istrailinggarbage(*path)) path++;
-	    if (path >= end || *path == ':') return (char *)last;
+	    if (path >= end || isADS(*path)) return (char *)last;
 	}
 	else if (isdirsep(*path)) {
 	    const char *last = path++;
 	    while (path < end && isdirsep(*path)) path++;
 	    if (path >= end) return (char *)last;
-	    if (*path == ':') path++;
+	    if (isADS(*path)) path++;
 	}
 	else {
 	    Inc(path, end, enc);
@@ -3472,7 +3484,7 @@ rb_file_expand_path_internal(VALUE fname https://github.com/ruby/ruby/blob/trunk/file.c#L3484
 	      case ' ': {
 		const char *e = s;
 		while (s < fend && istrailinggarbage(*s)) s++;
-		if (!*s) {
+		if (s >= fend) {
 		    s = e;
 		    goto endpath;
 		}
@@ -3511,19 +3523,23 @@ rb_file_expand_path_internal(VALUE fname https://github.com/ruby/ruby/blob/trunk/file.c#L3523
 
     if (s > b) {
 #if USE_NTFS
+# if USE_NTFS_ADS
 	static const char prime[] = ":$DATA";
 	enum {prime_len = sizeof(prime) -1};
+# endif
       endpath:
+# if USE_NTFS_ADS
 	if (s > b + prime_len && strncasecmp(s - prime_len, prime, prime_len) == 0) {
 	    /* alias of stream */
 	    /* get rid of a bug of x64 VC++ */
-	    if (*(s - (prime_len+1)) == ':') {
+	    if (isADS(*(s - (prime_len+1)))) {
 		s -= prime_len + 1; /* prime */
 	    }
 	    else if (memchr(b, ':', s - prime_len - b)) {
 		s -= prime_len;	/* alternative */
 	    }
 	}
+# endif
 #endif
 	BUFCOPY(b, s-b);
 	rb_str_set_len(result, p-buf);
@@ -4233,7 +4249,7 @@ ruby_enc_find_extname(const char *name, https://github.com/ruby/ruby/blob/trunk/file.c#L4249
 		if (*p == '.') dot = p;
 		p++;
 	    }
-	    if (!*p || *p == ':') {
+	    if (!*p || isADS(*p)) {
 		p = last;
 		break;
 	    }
@@ -4244,7 +4260,7 @@ ruby_enc_find_extname(const char *name, https://github.com/ruby/ruby/blob/trunk/file.c#L4260
 #endif
 	}
 #if USE_NTFS
-	else if (*p == ':') {
+	else if (isADS(*p)) {
 	    break;
 	}
 #endif

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]