Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clang-format linter to the CI. #20

Merged
merged 2 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
123 changes: 63 additions & 60 deletions compat/getgrent_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,81 +30,84 @@
// Library.
#if defined(BSD) || (defined(__linux__) && !defined(__GLIBC__))

#include <errno.h>
#include <grp.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdint.h>

#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__)
84 changes: 45 additions & 39 deletions compat/getpwent_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,57 +30,63 @@
// Library.
#if defined(BSD) || (defined(__linux__) && !defined(__GLIBC__))

#include <errno.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

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__)
2 changes: 1 addition & 1 deletion gen_getent.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions nss_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

#ifdef DEBUG
#undef DEBUG
#define DEBUG(fmt, ...) \
do { \
#define DEBUG(fmt, ...) \
do { \
fprintf(stderr, fmt, ##__VA_ARGS__); \
} while (0)
#else
Expand Down
7 changes: 3 additions & 4 deletions test/last_pw_errno_test.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#include <sys/types.h>
#include <pwd.h>
#include <errno.h>
#include <pwd.h>
#include <stdio.h>
#include <sys/types.h>

int main(int argc, char **argv) {
setpwent();
for (;;) {
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;
}
}
Expand Down