| OLD | NEW |
| 1 #include <stdio.h> | 1 #include <stdio.h> |
| 2 #include <string.h> | 2 #include <string.h> |
| 3 #include <mntent.h> | 3 #include <mntent.h> |
| 4 #include <errno.h> | 4 #include <errno.h> |
| 5 | 5 |
| 6 FILE *setmntent(const char *name, const char *mode) | 6 FILE* setmntent(const char* name, const char* mode) { |
| 7 { | 7 return fopen(name, mode); |
| 8 » return fopen(name, mode); | |
| 9 } | 8 } |
| 10 | 9 |
| 11 int endmntent(FILE *f) | 10 int endmntent(FILE* f) { |
| 12 { | 11 if (f) |
| 13 » if (f) fclose(f); | 12 fclose(f); |
| 14 » return 1; | 13 return 1; |
| 15 } | 14 } |
| 16 | 15 |
| 17 struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int bufle
n) | 16 struct mntent* getmntent_r(FILE* f, |
| 18 { | 17 struct mntent* mnt, |
| 19 » int cnt, n[8]; | 18 char* linebuf, |
| 19 int buflen) { |
| 20 int cnt, n[8]; |
| 20 | 21 |
| 21 » mnt->mnt_freq = 0; | 22 mnt->mnt_freq = 0; |
| 22 » mnt->mnt_passno = 0; | 23 mnt->mnt_passno = 0; |
| 23 | 24 |
| 24 » do { | 25 do { |
| 25 » » fgets(linebuf, buflen, f); | 26 fgets(linebuf, buflen, f); |
| 26 » » if (feof(f) || ferror(f)) return 0; | 27 if (feof(f) || ferror(f)) |
| 27 » » if (!strchr(linebuf, '\n')) { | 28 return 0; |
| 28 » » » fscanf(f, "%*[^\n]%*[\n]"); | 29 if (!strchr(linebuf, '\n')) { |
| 29 » » » errno = ERANGE; | 30 fscanf(f, "%*[^\n]%*[\n]"); |
| 30 » » » return 0; | 31 errno = ERANGE; |
| 31 » » } | 32 return 0; |
| 32 » » cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d", | 33 } |
| 33 » » » n, n+1, n+2, n+3, n+4, n+5, n+6, n+7, | 34 cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d", n, n + 1, |
| 34 » » » &mnt->mnt_freq, &mnt->mnt_passno); | 35 n + 2, n + 3, n + 4, n + 5, n + 6, n + 7, &mnt->mnt_freq, |
| 35 » } while (cnt < 2 || linebuf[n[0]] == '#'); | 36 &mnt->mnt_passno); |
| 37 } while (cnt < 2 || linebuf[n[0]] == '#'); |
| 36 | 38 |
| 37 » linebuf[n[1]] = 0; | 39 linebuf[n[1]] = 0; |
| 38 » linebuf[n[3]] = 0; | 40 linebuf[n[3]] = 0; |
| 39 » linebuf[n[5]] = 0; | 41 linebuf[n[5]] = 0; |
| 40 » linebuf[n[7]] = 0; | 42 linebuf[n[7]] = 0; |
| 41 | 43 |
| 42 » mnt->mnt_fsname = linebuf+n[0]; | 44 mnt->mnt_fsname = linebuf + n[0]; |
| 43 » mnt->mnt_dir = linebuf+n[2]; | 45 mnt->mnt_dir = linebuf + n[2]; |
| 44 » mnt->mnt_type = linebuf+n[4]; | 46 mnt->mnt_type = linebuf + n[4]; |
| 45 » mnt->mnt_opts = linebuf+n[6]; | 47 mnt->mnt_opts = linebuf + n[6]; |
| 46 | 48 |
| 47 » return mnt; | 49 return mnt; |
| 48 } | 50 } |
| 49 | 51 |
| 50 struct mntent *getmntent(FILE *f) | 52 struct mntent* getmntent(FILE* f) { |
| 51 { | 53 static char linebuf[256]; |
| 52 » static char linebuf[256]; | 54 static struct mntent mnt; |
| 53 » static struct mntent mnt; | 55 return getmntent_r(f, &mnt, linebuf, sizeof linebuf); |
| 54 » return getmntent_r(f, &mnt, linebuf, sizeof linebuf); | |
| 55 } | 56 } |
| 56 | 57 |
| 57 int addmntent(FILE *f, const struct mntent *mnt) | 58 int addmntent(FILE* f, const struct mntent* mnt) { |
| 58 { | 59 if (fseek(f, 0, SEEK_END)) |
| 59 » if (fseek(f, 0, SEEK_END)) return 1; | 60 return 1; |
| 60 » return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n", | 61 return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n", mnt->mnt_fsname, mnt->mnt_dir, |
| 61 » » mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts, | 62 mnt->mnt_type, mnt->mnt_opts, mnt->mnt_freq, |
| 62 » » mnt->mnt_freq, mnt->mnt_passno) < 0; | 63 mnt->mnt_passno) < 0; |
| 63 } | 64 } |
| 64 | 65 |
| 65 char *hasmntopt(const struct mntent *mnt, const char *opt) | 66 char* hasmntopt(const struct mntent* mnt, const char* opt) { |
| 66 { | 67 return strstr(mnt->mnt_opts, opt); |
| 67 » return strstr(mnt->mnt_opts, opt); | |
| 68 } | 68 } |
| OLD | NEW |