On Mon, 12 Sep 2016 20:18:30 +0300
Eli Zaretskii <[email protected]> wrote:

> > From: Tim Ruehsen <[email protected]>
> > Date: Mon, 12 Sep 2016 13:00:32 +0200
> > 
> > > +  char *basename = name;
> > > +
> > > +  while ((name = strstr (basename, "/")))
> > > +    basename = name + 1;
> > 
> > Could you use strrchr() ? something like
> > 
> > char *basename = strrchr (name, '/');
> > 
> > if (basename)
> >   basename += 1;
> > else
> >   basename = name;
> 
> I think we want to use ISSEP, no?  Otherwise Windows file names with
> backslashes will misfire.
> 

Thanks Eli. A possible implementation if ISSEP is shown below.

#if defined(WINDOWS) || defined(MSDOS)
# define ISSEP(c) ((c) == '/' || (c) == '\\')
#else
# define ISSEP(c) ((c) == '/')
#endif

char *
get_metalink_basename (char *name)
{
  char *basename;

  if (!name)
    return NULL;

  basename = name + strlen (name);

  while (basename > name && !ISSEP (*basename))
    --basename;

  if (ISSEP (*basename))
    ++basename;

  return metalink_check_safe_path (basename) ? basename : NULL;
}

Regards,
Matthew

-- 
Matthew White <[email protected]>

Attachment: pgpk3G7_fjcQY.pgp
Description: PGP signature

Reply via email to