|
|
1.1 ! root 1: #include <fstab.h> ! 2: #include <stdio.h> ! 3: #include <ctype.h> ! 4: ! 5: static struct fstab fs; ! 6: static FILE *fs_file = 0; ! 7: ! 8: static char *fs_string(back, string, lg, end) ! 9: char *string, *back; ! 10: int lg; /* length of field to stuff into */ ! 11: char end; ! 12: { ! 13: register char *cp; ! 14: for (cp = string; *cp && *cp != end; cp++) ! 15: continue; ! 16: if (*cp == '\0') return(0); ! 17: *cp = '\0'; ! 18: strncpy(back, string, lg-1); ! 19: return(cp+1); ! 20: } ! 21: static char *fs_digit(backp, string, end) ! 22: int *backp; ! 23: char *string; ! 24: char end; ! 25: { ! 26: register int value = 0; ! 27: register char *cp; ! 28: for (cp = string; *cp && isdigit(*cp); cp++){ ! 29: value *= 10; ! 30: value += *cp - '0'; ! 31: } ! 32: if (*cp == '\0') return(0); ! 33: *backp = value; ! 34: while ( *cp && *cp != end) ! 35: cp++; ! 36: if (*cp == '\0') return(0); ! 37: return(cp+1); ! 38: } ! 39: ! 40: static int fstabscan(fsp) ! 41: struct fstab *fsp; ! 42: { ! 43: register char *cp; ! 44: char buf[256]; ! 45: if (fgets(buf, 256, fs_file) == NULL) ! 46: return(EOF); ! 47: cp = buf; ! 48: cp = fs_string(&fsp->fs_spec[0], cp, FSNMLG, ':'); ! 49: if (cp == 0) return(0); ! 50: cp = fs_string(&fsp->fs_file[0], cp, FSNMLG, ':'); ! 51: if (cp == 0) return(1); ! 52: cp = fs_string(&fsp->fs_type[0], cp, 3, ':'); ! 53: if (cp == 0) return(2); ! 54: cp = fs_digit(&fsp->fs_freq, cp, ':'); ! 55: if (cp == 0) return(3); ! 56: cp = fs_digit(&fsp->fs_passno, cp, '\n'); ! 57: if (cp == 0) return(4); ! 58: return(5); ! 59: } ! 60: ! 61: int setfsent() ! 62: { ! 63: if (fs_file) ! 64: endfsent(); ! 65: if ( (fs_file = fopen(FSTAB, "r")) == NULL){ ! 66: fs_file = 0; ! 67: return(0); ! 68: } ! 69: return(1); ! 70: } ! 71: ! 72: int endfsent() ! 73: { ! 74: if (fs_file){ ! 75: fclose(fs_file); ! 76: } ! 77: return(1); ! 78: } ! 79: ! 80: struct fstab *getfsent() ! 81: { ! 82: int nfields; ! 83: ! 84: if ( (fs_file == 0) && (setfsent() == 0) ) ! 85: return(0); ! 86: nfields = fstabscan(&fs); ! 87: if (nfields == EOF || nfields != FSTABNARGS) ! 88: return(0); ! 89: return(&fs); ! 90: } ! 91: struct fstab *getfsspec(name) ! 92: char *name; ! 93: { ! 94: register struct fstab *fsp; ! 95: if (setfsent() == 0) /* start from the beginning */ ! 96: return(0); ! 97: while( (fsp = getfsent()) != 0){ ! 98: if (strncmp(fsp->fs_spec, name, sizeof(fsp->fs_spec)) == 0) ! 99: return(fsp); ! 100: } ! 101: return(0); ! 102: } ! 103: struct fstab *getfsfile(name) ! 104: char *name; ! 105: { ! 106: register struct fstab *fsp; ! 107: if (setfsent() == 0) /* start from the beginning */ ! 108: return(0); ! 109: while ( (fsp = getfsent()) != 0){ ! 110: if (strncmp(fsp->fs_file, name, sizeof(fsp->fs_spec)) == 0) ! 111: return(fsp); ! 112: } ! 113: return(0); ! 114: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.