1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

file.c: isADS

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-12-06 07:21:55 +00:00
parent a8fff36406
commit 1f97dd562c

30
file.c
View file

@ -2922,12 +2922,24 @@ static const char file_alt_separator[] = {FILE_ALT_SEPARATOR, '\0'};
#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 *
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, VALUE dname, int abs_mode, int long_na
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, VALUE dname, int abs_mode, int long_na
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, long *len, rb_encoding *enc)
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, long *len, rb_encoding *enc)
#endif
}
#if USE_NTFS
else if (*p == ':') {
else if (isADS(*p)) {
break;
}
#endif