It seems checkpatch errors krept in, this is a first go. Next run will go into usr/kinit directory. No code changes, just codingstyle fixes (verified with size(3)). maximilian attems (5): [klibc] sleep: have argument on next line [klibc] readklink: remove unneeded braces [klibc] mount: whitespace policy [klibc] ls: fix various checkpatch complaints [klibc] tests: checkpatch fixlets usr/klibc/tests/environ.c | 3 +- usr/klibc/tests/fcntl.c | 3 +- usr/klibc/tests/setjmptest.c | 5 +-- usr/klibc/tests/sigint.c | 2 +- usr/utils/ls.c | 73 +++++++++++++++++++++++++++-------------- usr/utils/mount_main.c | 4 +- usr/utils/readlink.c | 3 +- usr/utils/sleep.c | 3 +- 8 files changed, 59 insertions(+), 37 deletions(-) -- 1.7.5.4
maximilian attems
2011-Jul-07 13:23 UTC
[klibc] [PATCH 1/5] sleep: have argument on next line
fixes: ERROR: trailing statements should be on next line Signed-off-by: maximilian attems <max at stro.at> --- usr/utils/sleep.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/usr/utils/sleep.c b/usr/utils/sleep.c index 62b2238..991cdbe 100644 --- a/usr/utils/sleep.c +++ b/usr/utils/sleep.c @@ -15,7 +15,8 @@ int main(int argc, char *argv[]) if (*p) goto err; - while (nanosleep(&ts, &ts) == -1 && errno == EINTR) ; + while (nanosleep(&ts, &ts) == -1 && errno == EINTR) + ; return 0; -- 1.7.5.4
maximilian attems
2011-Jul-07 13:24 UTC
[klibc] [PATCH 2/5] readklink: remove unneeded braces
fixes:
WARNING: braces {} are not necessary for single statement blocks
Signed-off-by: maximilian attems <max at stro.at>
---
usr/utils/readlink.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/usr/utils/readlink.c b/usr/utils/readlink.c
index 6a5412c..5ea4e41 100644
--- a/usr/utils/readlink.c
+++ b/usr/utils/readlink.c
@@ -28,9 +28,8 @@ int main(int argc, char *argv[])
exit(1);
}
- if (readlink(name, link_name, max_siz) == -1) {
+ if (readlink(name, link_name, max_siz) == -1)
exit(1);
- }
printf("%s\n", link_name);
exit(0);
--
1.7.5.4
fix:
WARNING: space prohibited between function name and open parenthesis '('
Signed-off-by: maximilian attems <max at stro.at>
---
usr/utils/mount_main.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/usr/utils/mount_main.c b/usr/utils/mount_main.c
index ee08720..ab3cb71 100644
--- a/usr/utils/mount_main.c
+++ b/usr/utils/mount_main.c
@@ -44,9 +44,9 @@ static __noreturn print_mount(char *type)
continue;
printf("%s on %s", mnt->mnt_fsname, mnt->mnt_dir);
if (mnt->mnt_type != NULL && mnt->mnt_type != '\0')
- printf (" type %s", mnt->mnt_type);
+ printf(" type %s", mnt->mnt_type);
if (mnt->mnt_opts != NULL && mnt->mnt_opts != '\0')
- printf (" (%s)", mnt->mnt_opts);
+ printf(" (%s)", mnt->mnt_opts);
printf("\n");
}
endmntent(mfp);
--
1.7.5.4
maximilian attems
2011-Jul-07 13:24 UTC
[klibc] [PATCH 4/5] ls: fix various checkpatch complaints
fix several of these:
WARNING: line over 80 characters
..
ERROR: do not use assignment in if condition
..
ERROR: else should follow close brace '}'
..
ERROR: switch and case should be at the same indent
ERROR: trailing statements should be on next line
..
ERROR: space required after that ',' (ctx:VxV)
..
ERROR: code indent should use tabs where possible
..
Signed-off-by: maximilian attems <max at stro.at>
---
usr/utils/ls.c | 73 ++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 48 insertions(+), 25 deletions(-)
diff --git a/usr/utils/ls.c b/usr/utils/ls.c
index 859142a..9677bc0 100644
--- a/usr/utils/ls.c
+++ b/usr/utils/ls.c
@@ -20,26 +20,31 @@ static void do_preformat(const struct stat *st)
{
int bytes;
- if ((bytes = snprintf(NULL, 0, "%ju", (uintmax_t) st->st_nlink))
> max_nlinks)
+ bytes = snprintf(NULL, 0, "%ju", (uintmax_t) st->st_nlink);
+ if (bytes > max_nlinks)
max_nlinks = bytes;
- if ((bytes = snprintf(NULL, 0, "%ju", (uintmax_t) st->st_uid))
> max_uid)
+ bytes = snprintf(NULL, 0, "%ju", (uintmax_t) st->st_uid);
+ if (bytes > max_uid)
max_uid = bytes;
- if ((bytes = snprintf(NULL, 0, "%ju", (uintmax_t) st->st_gid))
> max_gid)
+ bytes = snprintf(NULL, 0, "%ju", (uintmax_t) st->st_gid);
+ if (bytes > max_gid)
max_gid = bytes;
if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
- if ((bytes = snprintf(NULL, 0, "%u", major(st->st_rdev))) >
max_maj)
+ bytes = snprintf(NULL, 0, "%u", major(st->st_rdev));
+ if (bytes > max_maj)
max_maj = bytes;
- if ((bytes = snprintf(NULL, 0, "%u", minor(st->st_rdev))) >
max_min)
+ bytes = snprintf(NULL, 0, "%u", minor(st->st_rdev));
+ if (bytes > max_min)
max_min = bytes;
max_size = max_maj + max_min + 1;
- }
- else {
- if ((bytes = snprintf(NULL, 0, "%ju", (uintmax_t) st->st_size))
> max_size)
+ } else {
+ bytes = snprintf(NULL, 0, "%ju", (uintmax_t) st->st_size);
+ if (bytes > max_size)
max_size = bytes;
}
return;
@@ -51,14 +56,30 @@ static void do_stat(const struct stat *st, const char *path)
int rc;
switch (st->st_mode & S_IFMT) {
- case S_IFBLK: putchar('b'); break;
- case S_IFCHR: putchar('c'); break;
- case S_IFDIR: putchar('d'); break;
- case S_IFIFO: putchar('p'); break;
- case S_IFLNK: putchar('l'); break;
- case S_IFSOCK: putchar('s'); break;
- case S_IFREG: putchar('-'); break;
- default: putchar('?'); break;
+ case S_IFBLK:
+ putchar('b');
+ break;
+ case S_IFCHR:
+ putchar('c');
+ break;
+ case S_IFDIR:
+ putchar('d');
+ break;
+ case S_IFIFO:
+ putchar('p');
+ break;
+ case S_IFLNK:
+ putchar('l');
+ break;
+ case S_IFSOCK:
+ putchar('s');
+ break;
+ case S_IFREG:
+ putchar('-');
+ break;
+ default:
+ putchar('?');
+ break;
}
putchar(STAT_ISSET(st->st_mode, S_IRUSR) ? 'r' : '-');
putchar(STAT_ISSET(st->st_mode, S_IWUSR) ? 'w' : '-');
@@ -82,8 +103,8 @@ static void do_stat(const struct stat *st, const char *path)
putchar(S_ISDIR(st->st_mode) ? 't' : 'T');
if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
- rc = asprintf(&fmt," %%%dju %%%dju %%%dju %%%du,%%%du %%s",
- max_nlinks, max_uid, max_gid, max_maj, max_min);
+ rc = asprintf(&fmt, " %%%dju %%%dju %%%dju %%%du,%%%du %%s",
+ max_nlinks, max_uid, max_gid, max_maj, max_min);
if (rc == -1) {
perror("asprintf");
exit(1);
@@ -95,10 +116,9 @@ static void do_stat(const struct stat *st, const char *path)
major(st->st_rdev),
minor(st->st_rdev),
path);
- }
- else {
- rc = asprintf(&fmt," %%%dju %%%dju %%%dju %%%dju %%s",
- max_nlinks, max_uid, max_gid, max_size);
+ } else {
+ rc = asprintf(&fmt, " %%%dju %%%dju %%%dju %%%dju %%s",
+ max_nlinks, max_uid, max_gid, max_size);
if (rc == -1) {
perror("asprintf");
exit(1);
@@ -113,11 +133,13 @@ static void do_stat(const struct stat *st, const char
*path)
free(fmt);
if (S_ISLNK(st->st_mode)) {
- if ((link_name = malloc(max_linksiz)) == NULL) {
+ link_name = malloc(max_linksiz);
+ if (link_name == NULL) {
perror("malloc");
exit(1);
}
- if ((rc = readlink(path, link_name, max_linksiz)) == -1) {
+ rc = readlink(path, link_name, max_linksiz);
+ if (rc == -1) {
free(link_name);
perror("readlink");
exit(1);
@@ -142,7 +164,8 @@ static void do_dir(const char *path, int preformat)
exit(1);
}
- if ((dir = opendir(path)) == NULL) {
+ dir = opendir(path);
+ if (dir == NULL) {
perror(path);
exit(1);
}
--
1.7.5.4
fix:
WARNING: braces {} are not necessary for single statement blocks
ERROR: do not use assignment in if condition
WARNING: braces {} are not necessary for any arm of this statement
WARNING: static char array declaration should probably be static const char
Signed-off-by: maximilian attems <max at stro.at>
---
usr/klibc/tests/environ.c | 3 +--
usr/klibc/tests/fcntl.c | 3 ++-
usr/klibc/tests/setjmptest.c | 5 ++---
usr/klibc/tests/sigint.c | 2 +-
4 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/usr/klibc/tests/environ.c b/usr/klibc/tests/environ.c
index b5b082d..5253d51 100644
--- a/usr/klibc/tests/environ.c
+++ b/usr/klibc/tests/environ.c
@@ -12,9 +12,8 @@ int main(int argc, char *argv[], char *envp[])
/* Test argc/argv */
printf("argc = %d, argv = %p\n", argc, argv);
- for (i = 0; i < argc; i++) {
+ for (i = 0; i < argc; i++)
printf("argv[%2d] = %s\n", i, argv[i]);
- }
/* Test environ */
for (i = 0; envp[i]; i++)
diff --git a/usr/klibc/tests/fcntl.c b/usr/klibc/tests/fcntl.c
index 219423e..30cc900 100644
--- a/usr/klibc/tests/fcntl.c
+++ b/usr/klibc/tests/fcntl.c
@@ -23,7 +23,8 @@ int main(int argc, char *argv[])
/* Get the flags on this FD */
- if ((flags = fcntl(fd, F_GETFL)) == -1) {
+ flags = fcntl(fd, F_GETFL);
+ if (flags == -1) {
perror("F_GETFL");
exit(1);
}
diff --git a/usr/klibc/tests/setjmptest.c b/usr/klibc/tests/setjmptest.c
index 30c4e16..fd9cb1c 100644
--- a/usr/klibc/tests/setjmptest.c
+++ b/usr/klibc/tests/setjmptest.c
@@ -15,11 +15,10 @@ void do_stuff(int v)
void recurse(int ctr, int v)
{
- if (ctr--) {
+ if (ctr--)
recurse(ctr, v);
- } else {
+ else
do_stuff(v);
- }
printf("ERROR!\n"); /* We should never get here... */
}
diff --git a/usr/klibc/tests/sigint.c b/usr/klibc/tests/sigint.c
index f11ae1f..ec62e33 100644
--- a/usr/klibc/tests/sigint.c
+++ b/usr/klibc/tests/sigint.c
@@ -7,7 +7,7 @@ static sig_atomic_t counter = 0;
static void sig_handler(int signum)
{
- static char msg[] = "Signal handler\n";
+ static const char msg[] = "Signal handler\n";
(void)signum;
--
1.7.5.4