diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2012-06-05 02:09:04 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2012-06-05 02:09:04 +0400 |
commit | 415ee7d6e47dcb3e0906a7bebc6d52ab8ed899da (patch) | |
tree | f7773ad82023c8616b339d84faa4bb7643af0311 /sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent_sun.c | |
parent | 3cc0cd4c5b3bed6f7d9aff26322d505785e11aa9 (diff) | |
download | glibc-415ee7d6e47dcb3e0906a7bebc6d52ab8ed899da.tar.gz |
Merged changes from kopensolaris-gnu project
http://git.csclub.uwaterloo.ca/?p=kopensolaris-gnu/glibc.git
Commits from 9157319 to bad8ac8.
This is only partial patch, some changes to not apply
and will be resovled and committed next.
Diffstat (limited to 'sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent_sun.c')
-rw-r--r-- | sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent_sun.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent_sun.c b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent_sun.c new file mode 100644 index 0000000000..820b115286 --- /dev/null +++ b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent_sun.c @@ -0,0 +1,119 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <mntentP.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> +#include <sys/ioctl.h> + +/* Docs: http://docs.sun.com/app/docs/doc/816-5168/resetmnttab-3c */ + +#define _MNT_CMP(x, y, f) \ + (!y->f || (y->f && strcmp (x->f, y->f) == 0)) + + +int getmntent (FILE *fp, struct mnttab *mt) +{ + struct extmnttab emt; + int res = ioctl (fileno (fp), MNTIOC_GETMNTENT, &emt); + if (res != 0) + return -1; + + mt->mnt_special = emt.mnt_special; + mt->mnt_mountp = emt.mnt_mountp; + mt->mnt_fstype = emt.mnt_fstype; + mt->mnt_mntopts = emt.mnt_mntopts; + mt->mnt_time = emt.mnt_time; + + return 0; +} + +int getmntany (FILE *fp, struct mnttab *mt, struct mnttab *mtpref) +{ + int res; + while ((res = getmntent (fp, mt)) == 0) + { + if (_MNT_CMP (mt, mtpref, mnt_special) && + _MNT_CMP (mt, mtpref, mnt_mountp) && + _MNT_CMP (mt, mtpref, mnt_fstype) && + _MNT_CMP (mt, mtpref, mnt_mntopts) && + _MNT_CMP (mt, mtpref, mnt_time)) + return 0; + } + + return res; +} + + +int getextmntent(FILE *fp, struct extmnttab *emt, int len) +{ + int res = ioctl (fileno (fp), MNTIOC_GETMNTENT, emt); + if (res != 0) + return -1; + return 0; +} + + +char *mntopt (char **opts) +{ + char *optsp = *opts; + + /* Strip leading spaces. */ + while (*optsp == ' ') + optsp++; + + /* Find comma. */ + char *ret = optsp; + while (*optsp != ',' && *optsp != '\0') + optsp++; + + /* Replace comma with null terminator. */ + if (*optsp == ',') + optsp++; + *opts = optsp; + + return ret; +} + + +char * hasmntopt (struct mnttab *mt, char *opt) +{ + /* We make a copy of mnt_mntopts since we modify it. */ + char buf[MNT_LINE_MAX + 1]; + strncpy (buf, mt->mnt_mntopts, sizeof (buf))[MNT_LINE_MAX] = '\0'; + + char *opts = buf; + char *optp; + size_t len = strlen (opt); + while (*(optp = mntopt (&opts))) + { + /* Check if opt matched, taking into account delimiters (e.g. '='). */ + if (strncmp (optp, opt, len) == 0 && !isalnum (optp[len])) + return mt->mnt_mntopts + (optp - buf); + } + + return NULL; +} + + +void resetmnttab (FILE *fp) +{ + rewind (fp); +} |