From e47d5648355dba670df3abdf467c06b4f209a300 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Fri, 11 Jul 2003 00:54:46 +0000 Subject: [PATCH] * path.cc (get_device_number): Remove special com? consideration. (special_chars): Make static. (special_introducers): New. (special_char): Allow specified valid_chars args. (fnunmunge): Handle aux-like filenames correctly. (special_name): Add con, conin$, conout$. (mount_item::fnmunge): Use __small_sprintf return value to calculate increments. --- winsup/cygwin/ChangeLog | 11 +++++ winsup/cygwin/path.cc | 103 ++++++++++++++++++++-------------------- 2 files changed, 63 insertions(+), 51 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 45419e21d..a5399b125 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +2003-07-10 Christopher Faylor + + * path.cc (get_device_number): Remove special com? consideration. + (special_chars): Make static. + (special_introducers): New. + (special_char): Allow specified valid_chars args. + (fnunmunge): Handle aux-like filenames correctly. + (special_name): Add con, conin$, conout$. + (mount_item::fnmunge): Use __small_sprintf return value to calculate + increments. + 2003-07-09 Christopher Faylor * include/cygwin/version.h: Bump DLL minor number to 1. diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index b7d16fddd..ff474fdf5 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -1099,15 +1099,6 @@ get_device_number (const char *unix_path, const char *w32_path, int &unit) if (devn == FH_BAD) devn = get_raw_device_number (unix_path + 5, NULL, unit); } - else - { - char *p = strrchr (unix_path, '/'); - if (p) - unix_path = p + 1; - if (udeveqn ("com", 3) - && (unit = digits (unix_path + 3)) >= 0 && unit < 100) - devn = FH_SERIAL; - } return devn; } @@ -1390,7 +1381,7 @@ set_flags (unsigned *flags, unsigned val) } } -char special_chars[] = +static char special_chars[] = "\001" "\002" "\003" "\004" "\005" "\006" "\007" "\010" "\011" "\012" "\013" "\014" "\015" "\016" "\017" "\020" "\021" "\022" "\023" "\024" "\025" "\026" "\027" "\030" @@ -1400,28 +1391,66 @@ char special_chars[] = "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"; +static char special_introducers[] = + "anpcl"; -static inline char -special_char (const char *s) +static char +special_char (const char *s, const char *valid_chars = special_chars) { - char *p = strechr (special_chars, *s); - if (*p == '%' && strlen (p) >= 3) - { - char hex[] = {s[1], s[2], '\0'}; - unsigned char c = strtoul (hex, &p, 16); - p = strechr (special_chars, c); - } + if (*s != '%' || strlen (s) < 3) + return 0; + + char *p; + char hex[] = {s[1], s[2], '\0'}; + unsigned char c = strtoul (hex, &p, 16); + p = strechr (valid_chars, c); return *p; } +/* Determines if name is "special". Assumes that name is empty or "absolute" */ +static int +special_name (const char *s, int inc = 1) +{ + if (!*s) + return false; + + s += inc; + if (strpbrk (s, special_chars)) + return !strncasematch (s, "%2f", 3); + + if (strcasematch (s, "nul") + || strcasematch (s, "aux") + || strcasematch (s, "prn") + || strcasematch (s, "con") + || strcasematch (s, "conin$") + || strcasematch (s, "conout$")) + return -1; + if (!strncasematch (s, "com", 3) + && !strncasematch (s, "lpt", 3)) + return false; + char *p; + (void) strtoul (s + 3, &p, 10); + return -(*p == '\0'); +} + bool fnunmunge (char *dst, const char *src) { bool converted = false; char c; + if ((c = special_char (src, special_introducers))) + { + __small_sprintf (dst, "%c%s", c, src + 3); + if (special_name (dst, 0)) + { + *dst++ = c; + src += 3; + } + } + while (*src) - if (*src != '%' || !(c = special_char (src))) + if (!(c = special_char (src))) *dst++ = *src++; else { @@ -1434,28 +1463,6 @@ fnunmunge (char *dst, const char *src) return converted; } -/* Determines if name is "special". Assumes that name is empty or "absolute" */ -static int -special_name (const char *s) -{ - if (!*s) - return false; - - if (strpbrk (++s, special_chars)) - return !strncasematch (s, "%2f", 3); - - if (strcasematch (s, "nul") - || strcasematch (s, "aux") - || strcasematch (s, "prn")) - return -1; - if (!strncasematch (s, "com", 3) - && !strncasematch (s, "lpt", 3)) - return false; - char *p; - (void) strtol (s, &p, 10); - return -(*p == '\0'); -} - void mount_item::fnmunge (char *dst, const char *src) { @@ -1467,19 +1474,13 @@ mount_item::fnmunge (char *dst, const char *src) char *d = dst; *d++ = *src++; if (name_type < 0) - { - __small_sprintf (d, "%%%02x", (unsigned char) *src++); - d += 3; - } + d += __small_sprintf (d, "%%%02x", (unsigned char) *src++); while (*src) - if (!special_char (src)) + if (!strchr (special_chars, *src) || (*src == '%' && !special_char (src))) *d++ = *src++; else - { - __small_sprintf (d, "%%%02x", (unsigned char) *src++); - d += 3; - } + d += __small_sprintf (d, "%%%02x", (unsigned char) *src++); *d = *src; }