[Libguestfs] [PATCH 6/6] New API: btrfs_subvolume_show

Hu Tao hutao at cn.fujitsu.com
Wed Nov 26 03:16:03 UTC 2014


On Fri, Nov 21, 2014 at 05:17:13PM +0100, Pino Toscano wrote:
 
 <...>

> > +          while (*p && c_isspace (*p)) p++;
> > +          pend = strchrnul (p, '\n');
> > +          if (*pend == '\n') {
> > +            *pend = '\0';
> > +            pend++;
> > +          }
> 
> I see this code repeated already; I think it would be better to create
> a small helper function like:
>   char *analyze_line (char *p, char **field, char **value)

perhaps an extra delimiter parameter?

> which would
> - destructively update p (setting null bytes, just like it is done now)
> - return in field the start of the field text
> - return in value, if present, the start of the value (after the colon)
> - return the pointer to the first character of the new line (or null,
>   if none following)
> this way it is IMHO easier to iterate over the lines, and also to detect
> whether a line contains a field+value or just text.


Regards,
Hu




More information about the Libguestfs mailing list