| OLD | NEW |
| 1 #include "pwf.h" | 1 #include "pwf.h" |
| 2 #include <pthread.h> | 2 #include <pthread.h> |
| 3 | 3 |
| 4 static unsigned atou(char **s) | 4 static unsigned atou(char** s) { |
| 5 { | 5 unsigned x; |
| 6 » unsigned x; | 6 for (x = 0; **s - '0' < 10U; ++*s) |
| 7 » for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0'); | 7 x = 10 * x + (**s - '0'); |
| 8 » return x; | 8 return x; |
| 9 } | 9 } |
| 10 | 10 |
| 11 int __getgrent_a(FILE *f, struct group *gr, char **line, size_t *size, char ***m
em, size_t *nmem, struct group **res) | 11 int __getgrent_a(FILE* f, |
| 12 { | 12 struct group* gr, |
| 13 » ssize_t l; | 13 char** line, |
| 14 » char *s, *mems; | 14 size_t* size, |
| 15 » size_t i; | 15 char*** mem, |
| 16 » int rv = 0; | 16 size_t* nmem, |
| 17 » int cs; | 17 struct group** res) { |
| 18 » pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | 18 ssize_t l; |
| 19 » for (;;) { | 19 char *s, *mems; |
| 20 » » if ((l=getline(line, size, f)) < 0) { | 20 size_t i; |
| 21 » » » rv = ferror(f) ? errno : 0; | 21 int rv = 0; |
| 22 » » » free(*line); | 22 int cs; |
| 23 » » » *line = 0; | 23 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); |
| 24 » » » gr = 0; | 24 for (;;) { |
| 25 » » » goto end; | 25 if ((l = getline(line, size, f)) < 0) { |
| 26 » » } | 26 rv = ferror(f) ? errno : 0; |
| 27 » » line[0][l-1] = 0; | 27 free(*line); |
| 28 *line = 0; |
| 29 gr = 0; |
| 30 goto end; |
| 31 } |
| 32 line[0][l - 1] = 0; |
| 28 | 33 |
| 29 » » s = line[0]; | 34 s = line[0]; |
| 30 » » gr->gr_name = s++; | 35 gr->gr_name = s++; |
| 31 » » if (!(s = strchr(s, ':'))) continue; | 36 if (!(s = strchr(s, ':'))) |
| 37 continue; |
| 32 | 38 |
| 33 » » *s++ = 0; gr->gr_passwd = s; | 39 *s++ = 0; |
| 34 » » if (!(s = strchr(s, ':'))) continue; | 40 gr->gr_passwd = s; |
| 41 if (!(s = strchr(s, ':'))) |
| 42 continue; |
| 35 | 43 |
| 36 » » *s++ = 0; gr->gr_gid = atou(&s); | 44 *s++ = 0; |
| 37 » » if (*s != ':') continue; | 45 gr->gr_gid = atou(&s); |
| 46 if (*s != ':') |
| 47 continue; |
| 38 | 48 |
| 39 » » *s++ = 0; mems = s; | 49 *s++ = 0; |
| 40 » » break; | 50 mems = s; |
| 41 » } | 51 break; |
| 52 } |
| 42 | 53 |
| 43 » for (*nmem=!!*s; *s; s++) | 54 for (*nmem = !!*s; *s; s++) |
| 44 » » if (*s==',') ++*nmem; | 55 if (*s == ',') |
| 45 » free(*mem); | 56 ++*nmem; |
| 46 » *mem = calloc(sizeof(char *), *nmem+1); | 57 free(*mem); |
| 47 » if (!*mem) { | 58 *mem = calloc(sizeof(char*), *nmem + 1); |
| 48 » » rv = errno; | 59 if (!*mem) { |
| 49 » » free(*line); | 60 rv = errno; |
| 50 » » *line = 0; | 61 free(*line); |
| 51 » » gr = 0; | 62 *line = 0; |
| 52 » » goto end; | 63 gr = 0; |
| 53 » } | 64 goto end; |
| 54 » if (*mems) { | 65 } |
| 55 » » mem[0][0] = mems; | 66 if (*mems) { |
| 56 » » for (s=mems, i=0; *s; s++) | 67 mem[0][0] = mems; |
| 57 » » » if (*s==',') *s++ = 0, mem[0][++i] = s; | 68 for (s = mems, i = 0; *s; s++) |
| 58 » » mem[0][++i] = 0; | 69 if (*s == ',') |
| 59 » } else { | 70 *s++ = 0, mem[0][++i] = s; |
| 60 » » mem[0][0] = 0; | 71 mem[0][++i] = 0; |
| 61 » } | 72 } else { |
| 62 » gr->gr_mem = *mem; | 73 mem[0][0] = 0; |
| 74 } |
| 75 gr->gr_mem = *mem; |
| 63 end: | 76 end: |
| 64 » pthread_setcancelstate(cs, 0); | 77 pthread_setcancelstate(cs, 0); |
| 65 » *res = gr; | 78 *res = gr; |
| 66 » if(rv) errno = rv; | 79 if (rv) |
| 67 » return rv; | 80 errno = rv; |
| 81 return rv; |
| 68 } | 82 } |
| OLD | NEW |