[PATCH] Add getmntent_r

Corinna Vinschen corinna-cygwin@cygwin.com
Tue Jun 5 12:52:00 GMT 2012


On Jun  5 14:42, Corinna Vinschen wrote:
> Hi Yaakov,
> 
> thanks for the patch, but this won't fly.
> 
> On Jun  5 00:08, Yaakov (Cygwin/X) wrote:
> > This patch set implements getmntent_r, a GNU extension:
> > 
> > http://man7.org/linux/man-pages/man3/getmntent.3.html
> > 
> > libvirt needs this[1], as I just (re)discovered.  Patches for
> > winsup/cygwin and winsup/doc attached.
> 
> > +extern "C" struct mntent *
> > +getmntent_r (FILE *, struct mntent *mntbuf, char *buf, int buflen)
> > +{
> > +  struct mntent *mnt = mount_table->getmntent (_my_tls.locals.iteration++);
> > +  char *tmpbuf;
> > +  int len = 0, maxlen;
> > +
> > +  if (!mnt)
> > +    {
> > +      mntbuf = NULL;
> 
> This doesn't make sense since mntbuf is a local varibale.  Changing
                                                     ^^
                                                  variable

> its value won't be propagated by the calling function anyway.
                                ^^
                                to

> [...]
> > +  memcpy (mntbuf, mnt, sizeof (struct mntent));
> 
> This doesn't do what you want.  mntbuf is just a copy of mnt, so the
> mntbuf members won't point to buf, but they will point to the internal
> storage.  While you have made a copy of the internal strings, they won't
> be used.  Also, assuming you first store the strings in tmpbuf and then
> memcpy them over to buf, 

... you have to make sure the mntbuf pointers point to buf, not to tmpbuf.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat



More information about the Cygwin-patches mailing list