From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Foreign file names on MS-Windows
Date: Sat, 22 Mar 2008 13:32:22 -0400 [thread overview]
Message-ID: <jwvhceybrna.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <u7ifuhqh8.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 22 Mar 2008 14:50:59 +0200")
> --- src/w32.c 24 Feb 2008 10:09:03 -0000 1.130
> +++ src/w32.c 22 Mar 2008 11:51:07 -0000
> @@ -1889,6 +1889,8 @@ closedir (DIR *dirp)
> struct direct *
> readdir (DIR *dirp)
> {
> + int downcase = !NILP (Vw32_downcase_file_names);
> +
> if (wnet_enum_handle != INVALID_HANDLE_VALUE)
> {
> if (!read_unc_volume (wnet_enum_handle,
> @@ -1923,14 +1925,23 @@ readdir (DIR *dirp)
> value returned by stat(). */
> dir_static.d_ino = 1;
> + strcpy (dir_static.d_name, dir_find_data.cFileName);
> +
> + /* If the file name in cFileName[] includes `?' characters, it means
> + the original file name used characters that cannot be represented
> + by the current ANSI codepage. To avoid total lossage, retrieve
> + the short 8+3 alias of the long file name. */
> + if (_mbspbrk (dir_static.d_name, "?"))
> + {
> + strcpy (dir_static.d_name, dir_find_data.cAlternateFileName);
> + downcase = 1; /* 8+3 aliases are returned in all caps */
> + }
> + dir_static.d_namlen = strlen (dir_static.d_name);
> dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3 +
> dir_static.d_namlen - dir_static.d_namlen % 4;
> -
> - dir_static.d_namlen = strlen (dir_find_data.cFileName);
> - strcpy (dir_static.d_name, dir_find_data.cFileName);
> if (dir_is_fat)
> _strlwr (dir_static.d_name);
> - else if (!NILP (Vw32_downcase_file_names))
> + else if (downcase)
> {
> register char *p;
> for (p = dir_static.d_name; *p; p++)
Why not just as in the patch below?
I.e. why fiddle with Vw32_downcase_file_names?
And more importantly why modify the code to change dir_static.d_namlen
before the computation of dir_static.d_reclen (which uses
dir_static.d_namlen)?
The patch below would seem pretty safe to me, whereas yours isn't quite
as obvious. Yet, it looks like there was a good reason to do it the way
you did.
Stefan
--- w32.c.~1.130.~ 2008-02-24 08:11:40.000000000 -0500
+++ w32.c 2008-03-22 13:31:01.000000000 -0400
@@ -1926,8 +1926,16 @@
dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3 +
dir_static.d_namlen - dir_static.d_namlen % 4;
- dir_static.d_namlen = strlen (dir_find_data.cFileName);
+ /* If the file name in cFileName[] includes `?' characters, it means
+ the original file name used characters that cannot be represented
+ by the current ANSI codepage. To avoid total lossage, retrieve
+ the short 8+3 alias of the long file name. */
+ if (_mbspbrk (dir_find_data.cFileName, "?"))
+ strcpy (dir_static.d_name, dir_find_data.cAlternateFileName);
+ else
strcpy (dir_static.d_name, dir_find_data.cFileName);
+ dir_static.d_namlen = strlen (dir_static.d_name);
+
if (dir_is_fat)
_strlwr (dir_static.d_name);
else if (!NILP (Vw32_downcase_file_names))
next prev parent reply other threads:[~2008-03-22 17:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-22 12:50 Foreign file names on MS-Windows Eli Zaretskii
2008-03-22 13:21 ` Lennart Borgman (gmail)
2008-03-22 13:32 ` Eli Zaretskii
2008-03-22 14:34 ` Eli Zaretskii
2008-03-22 15:38 ` Jason Rumney
2008-03-22 17:26 ` Eli Zaretskii
2008-03-22 17:32 ` Stefan Monnier [this message]
2008-03-22 18:15 ` Eli Zaretskii
2008-03-23 0:56 ` Stefan Monnier
2008-03-23 4:22 ` Eli Zaretskii
2008-03-24 1:15 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvhceybrna.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.