home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / mntent / mntent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-06  |  1.5 KB  |  76 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <mntent.h>
  5.  
  6. struct mntent *getmntent(FILE *filep)
  7. {
  8.   char *cp, *sep = " \t\n";
  9.   static char buff[MNTMAXSTR];
  10.   static struct mntent mnt;
  11.  
  12.   /* Loop on the file, skipping comment lines. - FvK 03/07/93 */
  13.   while((cp = fgets(buff, sizeof buff, filep)) != NULL) {
  14.     if (buff[0] == '#' || buff[0] == '\n') continue;
  15.     break;
  16.   }
  17.  
  18.   /* At the EOF, the buffer should be unchanged. We should
  19.    * check the return value from fgets ().
  20.    */
  21.   if (cp == NULL) return NULL;
  22.  
  23.   mnt.mnt_fsname = strtok(buff, sep);
  24.   if (mnt.mnt_fsname == NULL)
  25.     return NULL;
  26.  
  27.   mnt.mnt_dir = strtok(NULL, sep);
  28.   if (mnt.mnt_dir == NULL)
  29.     return NULL;
  30.  
  31.   mnt.mnt_type = strtok(NULL, sep);
  32.   if (mnt.mnt_type == NULL)
  33. #if 0
  34.     mnt.mnt_type = MNTTYPE_MINIX;
  35. #else
  36.     return NULL;
  37. #endif
  38.  
  39.   mnt.mnt_opts = strtok(NULL, sep);
  40.   if (mnt.mnt_opts == NULL)
  41.     mnt.mnt_opts = "";
  42.  
  43.   cp = strtok(NULL, sep);
  44.   mnt.mnt_freq = (cp != NULL) ? atoi(cp) : 0;
  45.  
  46.   cp = strtok(NULL, sep);
  47.   mnt.mnt_passno = (cp != NULL) ? atoi(cp) : 0;
  48.  
  49.   return &mnt;
  50. }
  51.  
  52. int addmntent(FILE *filep, const struct mntent *mnt)
  53. {
  54.   if (fseek(filep, 0, SEEK_END) < 0)
  55.     return 1;
  56.  
  57.   if (fprintf(filep, "%s %s %s %s %d %d\n", mnt->mnt_fsname, mnt->mnt_dir,
  58.           mnt->mnt_type, mnt->mnt_opts, mnt->mnt_freq, mnt->mnt_passno)
  59.       < 1)
  60.     return 1;
  61.  
  62.   return 0;
  63. }
  64.  
  65. char *hasmntopt(const struct mntent *mnt, const char *opt)
  66. {
  67.   return strstr(mnt->mnt_opts, opt);
  68. }
  69.  
  70. int endmntent(FILE *filep)
  71. {
  72.   if (filep != NULL)
  73.     fclose(filep);
  74.   return 1;
  75. }
  76.