On Sep 23 2017, Eli Zaretskii <eliz@gnu.org> wrote:
>> +/* Return the current working directory.=C2=A0 The result should =
be freed
>> +=C2=A0 =C2=A0with 'free'.=C2=A0 Return NULL on errors.=C2=
=A0 */
>> +char *
>> +emacs_get_current_dir_name (void)
>> +{
>> +=C2=A0 char *dir =3D emacs_get_current_dir_name_1 ();
>> +=C2=A0 if (dir =3D=3D NULL)
>> +=C2=A0 =C2=A0 return NULL;
>> +=C2=A0 /* On Linux, getcwd and get_current_dir_name return a stri=
ng
>> +=C2=A0 =C2=A0 =C2=A0starting with "(unreachable)" if th=
e current directory doesn't
>> +=C2=A0 =C2=A0 =C2=A0exist, e.g. because it was unmounted.=C2=A0 T=
reat that as an error.
>> +=C2=A0 =C2=A0 =C2=A0See https://debbu=
gs.gnu.org/cgi/bugreport.cgi?bug=3D27871.=C2=A0 */
>> +=C2=A0 const char *prefix =3D "(unreachable)";
>> +=C2=A0 size_t dir_len =3D strlen (dir);
>> +=C2=A0 size_t prefix_len =3D strlen (prefix);
>> +=C2=A0 if (dir_len >=3D prefix_len && strncmp (dir, pr=
efix, prefix_len) =3D=3D 0)
>> +=C2=A0 =C2=A0 {
>> +=C2=A0 =C2=A0 =C2=A0 errno =3D ENOTCONN;
>> +=C2=A0 =C2=A0 =C2=A0 return NULL;
>
> What if there's a directory called literally "(unreachable)SO=
METHING"?
An absolute file name cannot start with "(unreachable)".
Yes, and getcwd and friends only retur=
n absolute filenames, and we only use $PWD if it's absolute, so anythin=
g except '/' or a drive letter can't be a prefix in the success=
case. I'll add a comment to that effect.=C2=A0