OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [linux/] [uClibc/] [libc/] [misc/] [mntent/] [mntent.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
#include <mntent.h>
5
 
6
#ifdef __UCLIBC_HAS_THREADS__
7
#include <pthread.h>
8
static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
9
# define LOCK   __pthread_mutex_lock(&mylock)
10
# define UNLOCK __pthread_mutex_unlock(&mylock);
11
#else
12
# define LOCK
13
# define UNLOCK
14
#endif
15
 
16
/* Reentrant version of getmntent.  */
17
struct mntent *getmntent_r (FILE *filep,
18
        struct mntent *mnt, char *buff, int bufsize)
19
{
20
        char *cp, *ptrptr;
21
        const char *sep = " \t\n";
22
 
23
        if (!filep || !mnt || !buff)
24
            return NULL;
25
 
26
        /* Loop on the file, skipping comment lines. - FvK 03/07/93 */
27
        while ((cp = fgets(buff, bufsize, filep)) != NULL) {
28
                if (buff[0] == '#' || buff[0] == '\n')
29
                        continue;
30
                break;
31
        }
32
 
33
        /* At the EOF, the buffer should be unchanged. We should
34
         * check the return value from fgets ().
35
         */
36
        if (cp == NULL)
37
                return NULL;
38
 
39
        ptrptr = 0;
40
        mnt->mnt_fsname = strtok_r(buff, sep, &ptrptr);
41
        if (mnt->mnt_fsname == NULL)
42
                return NULL;
43
 
44
        mnt->mnt_dir = strtok_r(NULL, sep, &ptrptr);
45
        if (mnt->mnt_dir == NULL)
46
                return NULL;
47
 
48
        mnt->mnt_type = strtok_r(NULL, sep, &ptrptr);
49
        if (mnt->mnt_type == NULL)
50
                return NULL;
51
 
52
        mnt->mnt_opts = strtok_r(NULL, sep, &ptrptr);
53
        if (mnt->mnt_opts == NULL)
54
                mnt->mnt_opts = "";
55
 
56
        cp = strtok_r(NULL, sep, &ptrptr);
57
        mnt->mnt_freq = (cp != NULL) ? atoi(cp) : 0;
58
 
59
        cp = strtok_r(NULL, sep, &ptrptr);
60
        mnt->mnt_passno = (cp != NULL) ? atoi(cp) : 0;
61
 
62
        return mnt;
63
}
64
 
65
struct mntent *getmntent(FILE * filep)
66
{
67
    struct mntent *tmp;
68
    static char buff[BUFSIZ];
69
    static struct mntent mnt;
70
    LOCK;
71
    tmp = getmntent_r(filep, &mnt, buff, sizeof buff);
72
    UNLOCK;
73
    return(tmp);
74
}
75
 
76
int addmntent(FILE * filep, const struct mntent *mnt)
77
{
78
        if (fseek(filep, 0, SEEK_END) < 0)
79
                return 1;
80
 
81
        if (fprintf (filep, "%s %s %s %s %d %d\n", mnt->mnt_fsname, mnt->mnt_dir,
82
                 mnt->mnt_type, mnt->mnt_opts, mnt->mnt_freq, mnt->mnt_passno) < 1)
83
                return 1;
84
 
85
        return 0;
86
}
87
 
88
char *hasmntopt(const struct mntent *mnt, const char *opt)
89
{
90
        return strstr(mnt->mnt_opts, opt);
91
}
92
 
93
FILE *setmntent(const char *name, const char *mode)
94
{
95
        return fopen(name, mode);
96
}
97
 
98
int endmntent(FILE * filep)
99
{
100
        if (filep != NULL)
101
                fclose(filep);
102
        return 1;
103
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.