[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Meta
From: |
Matthew White |
Subject: |
Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml |
Date: |
Wed, 14 Sep 2016 12:12:56 +0200 |
On Sun, 11 Sep 2016 23:39:09 +0200
Giuseppe Scrivano <address@hidden> wrote:
> Hi Matthew,
>
> Matthew White <address@hidden> writes:
>
> > +void
> > +replace_metalink_basename (char **name, char *ref)
> > +{
> > + size_t dir_len = 0;
> > + char *p, *dir, *file, *new;
> > +
> > + if (!name)
> > + return;
> > +
> > + /* New basename from file name reference. */
> > + file = ref;
> > + if (file)
> > + {
> > + p = strrchr (file, '/');
> > + if (p)
> > + file = p + 1;
> > + }
> > +
> > + /* Old directory. */
> > + dir = NULL;
> > + if (*name)
> > + {
> > + p = strrchr (*name, '/');
> > + if (p)
> > + dir_len = (p - *name) + 1;
> > + }
> > + dir = xstrndup (*name, dir_len);
>
> I'll review this patch more in details, but one small thing here, could
> we modify name in place and avoid a memory allocation for dir?
>
> name[dir_len] = '\0';
Function amended to modify *name in place.
Followed Tim's suggestions for Patch 09/25 about different environments
compatibility, the function now uses last_component() to detect the basename:
http://lists.gnu.org/archive/html/bug-wget/2016-09/msg00083.html
NOTES: if *name is NULL and ref is like 'dir/C:D:file', the result will be
'C:D:file'; is it advisable to remove the drive letters 'C:D:' and return only
'file'?
/*
Replace/remove the basename of a file name.
The file name is permanently modified.
Always set NAME to a string, even an empty one.
Use REF's basename as replacement. If REF is NULL or if it doesn't
provide a valid basename candidate, then remove NAME's basename.
*/
void
replace_metalink_basename (char **name, char *ref)
{
char *new, *basename;
if (!name)
return;
/* Strip old basename. */
if (*name)
{
basename = last_component (*name);
if (basename == *name)
xfree (*name);
else
*basename = '\0';
}
/* New basename from file name reference. */
if (ref)
ref = last_component (ref);
/* Replace the old basename. */
new = aprintf ("%s%s", *name ? *name : "", ref ? ref : "");
xfree (*name);
*name = new;
}
>
> Giuseppe
Regards,
Matthew
--
Matthew White <address@hidden>
pgpWUFwV9hLuw.pgp
Description: PGP signature
- [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml, Matthew White, 2016/09/10
- Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml, Giuseppe Scrivano, 2016/09/11
- Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml,
Matthew White <=
- Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml, Giuseppe Scrivano, 2016/09/14
- Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml, Matthew White, 2016/09/14
- Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml, Giuseppe Scrivano, 2016/09/15
- Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml, Matthew White, 2016/09/15
- Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml, Tim Ruehsen, 2016/09/15
- Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml, Matthew White, 2016/09/15
- Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml, Tim Ruehsen, 2016/09/16
- Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml, Eli Zaretskii, 2016/09/16
- Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml, Tim Ruehsen, 2016/09/16
- Re: [Bug-wget] [PATCH 20/25] New option --metalink-index to process Metalink application/metalink4+xml, Eli Zaretskii, 2016/09/16