On 2012-06-05 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.

And here is the code I used to test on Cygwin and Linux.


Yaakov

#ifdef CCOD
#pragma CCOD:script no
#endif

#include <mntent.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#ifdef __CYGWIN__
#include <dlfcn.h>
#include <cygwin/version.h>
#endif

int
main(void)
{
#if defined(__CYGWIN__) && CYGWIN_VERSION_API_MINOR < 262
  void *libc = dlopen ("cygwin1.dll", 0);
  struct mntent *(*getmntent_r) (FILE *, struct mntent *, char *, int)
    = dlsym (libc, "getmntent_r");
#endif

  FILE *mtab = setmntent (_PATH_MOUNTED, "r");
  int buflen = 256;
  char *buf = (char *) malloc (buflen);
  struct mntent mntent, *mntret;
  int i, len;

  while (((mntret = getmntent_r (mtab, &mntent, buf, buflen)) != NULL))
    {
      len = 0;
      for (i = 0; i < 6; i++)
        len += printf ("%s ", buf + len);
      printf ("\n");
      /* check that these are identical with the above */
      printf ("%s %s %s %s %d %d\n", mntent.mnt_fsname, mntent.mnt_dir,
                                     mntent.mnt_type, mntent.mnt_opts,
                                     mntent.mnt_freq, mntent.mnt_passno);
      printf ("%s %s %s %s %d %d\n", mntret->mnt_fsname, mntret->mnt_dir,
                                     mntret->mnt_type, mntret->mnt_opts,
                                     mntret->mnt_freq, mntret->mnt_passno);
    }
  return 0;
}

Reply via email to