Replace PyString usage with PyBytes everywhere
[platform/upstream/rpm.git] / misc / getmntent.c
1 #include "system.h"
2
3 #ifdef __aix__
4 #define COMMENTCHAR '*'
5 #else
6 #define COMMENTCHAR '#'
7 #endif
8
9 #if HAVE_STRUCT_MNTTAB 
10 our_mntent * getmntent(FILE *filep) {
11     static struct mnttab entry;
12     static our_mntent item;
13
14     if (!fread(&entry, sizeof(entry), 1, filep)) return NULL;
15     item.our_mntdir = entry.mt_filsys;
16
17     return &item;
18 }
19 #else 
20 our_mntent *getmntent(FILE *filep) {
21     static our_mntent item = { NULL };
22     char buf[1024], * start;
23     char * chptr;
24
25     if (item.our_mntdir) {
26         free(item.our_mntdir);
27     }
28     
29     while (fgets(buf, sizeof(buf) - 1, filep)) {
30         /* chop off \n */
31         buf[strlen(buf) - 1] = '\0';
32
33         chptr = buf;
34         while (isspace(*chptr)) chptr++;
35
36         if (*chptr == COMMENTCHAR) continue;
37
38 #       if __aix__
39             /* aix uses a screwed up file format */
40             if (*chptr == '/') {
41                 start = chptr;
42                 while (*chptr != ':') chptr++;
43                 *chptr = '\0';
44                 item.mnt_dir = strdup(start);
45                 return &item;
46             }
47 #       else 
48             while (!isspace(*chptr) && (*chptr)) chptr++;
49             if (!*chptr) return NULL;
50
51             while (isspace(*chptr) && (*chptr)) chptr++;
52             if (!*chptr) return NULL;
53             start = chptr;
54         
55             while (!isspace(*chptr) && (*chptr)) chptr++;
56             *chptr = '\0';
57
58             item.our_mntdir = strdup(start);
59             return &item;
60 #       endif
61     }
62
63     return NULL;
64 }
65 #endif
66