diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7291ef9..588a0d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,3 +26,11 @@ jobs: run: make all - name: test run: make check + + fmt-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: jidicula/clang-format-action@v4.3.0 + with: + fallback-style: "Google" diff --git a/compat/getgrent_r.c b/compat/getgrent_r.c index 0bd5295..586f041 100644 --- a/compat/getgrent_r.c +++ b/compat/getgrent_r.c @@ -30,81 +30,84 @@ // Library. #if defined(BSD) || (defined(__linux__) && !defined(__GLIBC__)) +#include #include #include +#include #include #include -#include #include -#include #define ALIGNBYTES (sizeof(uintptr_t) - 1) -#define ALIGN(p)((((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)) -static unsigned atou(char **s) -{ - unsigned x; - for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0'); - return x; +#define ALIGN(p) ((((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)) +static unsigned atou(char **s) { + unsigned x; + for (x = 0; **s - '0' < 10U; ++*s) x = 10 * x + (**s - '0'); + return x; } -int fgetgrent_r(FILE *f, struct group *gr, char *line, size_t size, struct group **res) -{ - char *s, *mems; - size_t i, nmem, need; - int rv = 0; - int ep; - ptrdiff_t remain; - for (;;) { - line[size-1] = '\xff'; - if ( (fgets(line, size, f) == NULL) || ferror(f) || (line[size-1] != '\xff') ) { - rv = (line[size-1] != '\xff') ? ERANGE : ENOENT; - line = 0; - gr = 0; - goto end; - } - ep = strcspn(line, "\n"); - line[ep] = 0; +int fgetgrent_r(FILE *f, struct group *gr, char *line, size_t size, + struct group **res) { + char *s, *mems; + size_t i, nmem, need; + int rv = 0; + int ep; + ptrdiff_t remain; + for (;;) { + line[size - 1] = '\xff'; + if ((fgets(line, size, f) == NULL) || ferror(f) || + (line[size - 1] != '\xff')) { + rv = (line[size - 1] != '\xff') ? ERANGE : ENOENT; + line = 0; + gr = 0; + goto end; + } + ep = strcspn(line, "\n"); + line[ep] = 0; - s = line; - gr->gr_name = s++; - if (!(s = strchr(s, ':'))) continue; + s = line; + gr->gr_name = s++; + if (!(s = strchr(s, ':'))) continue; - *s++ = 0; gr->gr_passwd = s; - if (!(s = strchr(s, ':'))) continue; + *s++ = 0; + gr->gr_passwd = s; + if (!(s = strchr(s, ':'))) continue; - *s++ = 0; gr->gr_gid = atou(&s); - if (*s != ':') continue; + *s++ = 0; + gr->gr_gid = atou(&s); + if (*s != ':') continue; - *s++ = 0; mems = s; - break; - } + *s++ = 0; + mems = s; + break; + } - for (nmem=!!*s; *s; s++) - if (*s==',') ++nmem; + for (nmem = !!*s; *s; s++) + if (*s == ',') ++nmem; - ++ep; - remain = (void *) &line[size] - (void *) &line[ep]; - need = (sizeof(char *) * (nmem+1)) + ALIGNBYTES; - if (need > remain) { - rv = ERANGE; - line = 0; - gr = 0; - goto end; - } - memset(&line[ep], 0, need); - gr->gr_mem = (char **) ALIGN(&line[ep]); + ++ep; + remain = (void *)&line[size] - (void *)&line[ep]; + need = (sizeof(char *) * (nmem + 1)) + ALIGNBYTES; + if (need > remain) { + rv = ERANGE; + line = 0; + gr = 0; + goto end; + } + memset(&line[ep], 0, need); + gr->gr_mem = (char **)ALIGN(&line[ep]); - if (*mems) { - gr->gr_mem[0] = mems; - for (s=mems, i=0; *s; s++) - if (*s==',') *s++ = 0, gr->gr_mem[++i] = s; - gr->gr_mem[++i] = 0; - } else { - gr->gr_mem[0] = 0; - } + if (*mems) { + gr->gr_mem[0] = mems; + for (s = mems, i = 0; *s; s++) + if (*s == ',') *s++ = 0, gr->gr_mem[++i] = s; + gr->gr_mem[++i] = 0; + } else { + gr->gr_mem[0] = 0; + } end: - *res = gr; - if(rv) errno = rv; - return rv; + *res = gr; + if (rv) errno = rv; + return rv; } -#endif //#if defined(BSD) || defined(__linux__) && !defined(__GLIBC__) +#endif //#if defined(BSD) || defined(__linux__) && !defined(__GLIBC__) diff --git a/compat/getpwent_r.c b/compat/getpwent_r.c index f383f59..e7de338 100644 --- a/compat/getpwent_r.c +++ b/compat/getpwent_r.c @@ -30,57 +30,63 @@ // Library. #if defined(BSD) || (defined(__linux__) && !defined(__GLIBC__)) +#include #include #include #include -#include #include -static unsigned atou(char **s) -{ - unsigned x; - for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0'); - return x; +static unsigned atou(char **s) { + unsigned x; + for (x = 0; **s - '0' < 10U; ++*s) x = 10 * x + (**s - '0'); + return x; } -int fgetpwent_r(FILE *f, struct passwd *pw, char *line, size_t size, struct passwd **res) -{ - char *s; - int rv = 0; - for (;;) { - line[size-1] = '\xff'; - if ( (fgets(line, size, f) == NULL) || ferror(f) || line[size-1] != '\xff' ) { - rv = (line[size-1] != '\xff') ? ERANGE : ENOENT; - line = 0; - pw = 0; - break; - } - line[strcspn(line, "\n")] = 0; +int fgetpwent_r(FILE *f, struct passwd *pw, char *line, size_t size, + struct passwd **res) { + char *s; + int rv = 0; + for (;;) { + line[size - 1] = '\xff'; + if ((fgets(line, size, f) == NULL) || ferror(f) || + line[size - 1] != '\xff') { + rv = (line[size - 1] != '\xff') ? ERANGE : ENOENT; + line = 0; + pw = 0; + break; + } + line[strcspn(line, "\n")] = 0; - s = line; - pw->pw_name = s++; - if (!(s = strchr(s, ':'))) continue; + s = line; + pw->pw_name = s++; + if (!(s = strchr(s, ':'))) continue; - *s++ = 0; pw->pw_passwd = s; - if (!(s = strchr(s, ':'))) continue; + *s++ = 0; + pw->pw_passwd = s; + if (!(s = strchr(s, ':'))) continue; - *s++ = 0; pw->pw_uid = atou(&s); - if (*s != ':') continue; + *s++ = 0; + pw->pw_uid = atou(&s); + if (*s != ':') continue; - *s++ = 0; pw->pw_gid = atou(&s); - if (*s != ':') continue; + *s++ = 0; + pw->pw_gid = atou(&s); + if (*s != ':') continue; - *s++ = 0; pw->pw_gecos = s; - if (!(s = strchr(s, ':'))) continue; + *s++ = 0; + pw->pw_gecos = s; + if (!(s = strchr(s, ':'))) continue; - *s++ = 0; pw->pw_dir = s; - if (!(s = strchr(s, ':'))) continue; + *s++ = 0; + pw->pw_dir = s; + if (!(s = strchr(s, ':'))) continue; - *s++ = 0; pw->pw_shell = s; - break; - } - *res = pw; - if (rv) errno = rv; - return rv; + *s++ = 0; + pw->pw_shell = s; + break; + } + *res = pw; + if (rv) errno = rv; + return rv; } -#endif //#if defined(BSD) || defined(__linux__) && !defined(__GLIBC__) +#endif //#if defined(BSD) || defined(__linux__) && !defined(__GLIBC__) diff --git a/gen_getent.c b/gen_getent.c index 6e0dfd6..b67b7b2 100644 --- a/gen_getent.c +++ b/gen_getent.c @@ -172,7 +172,7 @@ static int getspent_to_file(FILE *output) { } if (ret == NSS_STATUS_UNAVAIL) { perror("ERROR: failed to access shadow test data"); - free(buffer); + free(buffer); return 1; } } while (ret == NSS_STATUS_SUCCESS || ret == NSS_STATUS_TRYAGAIN); diff --git a/nss_cache.h b/nss_cache.h index 7cf6401..d1067a0 100644 --- a/nss_cache.h +++ b/nss_cache.h @@ -38,8 +38,8 @@ #ifdef DEBUG #undef DEBUG -#define DEBUG(fmt, ...) \ - do { \ +#define DEBUG(fmt, ...) \ + do { \ fprintf(stderr, fmt, ##__VA_ARGS__); \ } while (0) #else diff --git a/test/last_pw_errno_test.c b/test/last_pw_errno_test.c index a3c1a4d..6316440 100644 --- a/test/last_pw_errno_test.c +++ b/test/last_pw_errno_test.c @@ -1,7 +1,7 @@ -#include -#include #include +#include #include +#include int main(int argc, char **argv) { setpwent(); @@ -9,8 +9,7 @@ int main(int argc, char **argv) { errno = 0; struct passwd *pw = getpwent(); if (!pw) { - if (errno != 0) - printf("ERRNO: %u %m\n", errno); + if (errno != 0) printf("ERRNO: %u %m\n", errno); break; } }