Magellan Linux

Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/getmntent.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1122 - (show annotations) (download)
Wed Aug 18 21:11:40 2010 UTC (13 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1208 byte(s)
-updated to klibc-1.5.19
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <mntent.h>
5
6 #define BUFLEN 1024
7
8 struct mntent *getmntent_r(FILE *fp, struct mntent *mntbuf, char *buf,
9 int buflen)
10 {
11 char *line = NULL, *saveptr = NULL;
12 const char *sep = " \t\n";
13
14 if (!fp || !mntbuf || !buf)
15 return NULL;
16
17 while ((line = fgets(buf, buflen, fp)) != NULL) {
18 if (buf[0] == '#' || buf[0] == '\n')
19 continue;
20 break;
21 }
22
23 if (!line)
24 return NULL;
25
26 mntbuf->mnt_fsname = strtok_r(buf, sep, &saveptr);
27 if (!mntbuf->mnt_fsname)
28 return NULL;
29
30 mntbuf->mnt_dir = strtok_r(NULL, sep, &saveptr);
31 if (!mntbuf->mnt_fsname)
32 return NULL;
33
34 mntbuf->mnt_type = strtok_r(NULL, sep, &saveptr);
35 if (!mntbuf->mnt_type)
36 return NULL;
37
38 mntbuf->mnt_opts = strtok_r(NULL, sep, &saveptr);
39 if (!mntbuf->mnt_opts)
40 mntbuf->mnt_opts = "";
41
42 line = strtok_r(NULL, sep, &saveptr);
43 mntbuf->mnt_freq = !line ? 0 : atoi(line);
44
45 line = strtok_r(NULL, sep, &saveptr);
46 mntbuf->mnt_passno = !line ? 0 : atoi(line);
47
48 return mntbuf;
49 }
50
51 struct mntent *getmntent(FILE *fp)
52 {
53 static char *buf = NULL;
54 static struct mntent mntbuf;
55
56 buf = malloc(BUFLEN);
57 if (!buf)
58 perror("malloc");
59
60 return getmntent_r(fp, &mntbuf, buf, BUFLEN);
61 }