diff options
| author | Michael Kerrisk <mtk.manpages@gmail.com> | 2020-09-05 16:34:34 +0200 |
|---|---|---|
| committer | Michael Kerrisk <mtk.manpages@gmail.com> | 2020-09-05 16:34:34 +0200 |
| commit | 48d05103071830b6708a3ecabeddcdef5f3daa44 (patch) | |
| tree | f1082a1ba85049eb3da7ff1d27d54255822414b2 /man3 | |
| parent | 3b7e518d4455d8c4e66094a275547134369a83d4 (diff) | |
| download | man-pages-48d05103071830b6708a3ecabeddcdef5f3daa44.tar.gz | |
getgrouplist.3, insque.3, malloc_info.3, pthread_create.3, tsearch.3, aio.7: Use C99-style declarations for readability
Rather than writing things such as:
struct sometype *x;
...
x = malloc(sizeof(*x));
let's use C99 style so that the type info is in the same line as
the allocation:
struct sometype *x = malloc(sizeof(*x));
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Diffstat (limited to 'man3')
| -rw-r--r-- | man3/getgrouplist.3 | 3 | ||||
| -rw-r--r-- | man3/insque.3 | 4 | ||||
| -rw-r--r-- | man3/malloc_info.3 | 3 | ||||
| -rw-r--r-- | man3/pthread_create.3 | 3 | ||||
| -rw-r--r-- | man3/tsearch.3 | 4 |
5 files changed, 6 insertions, 11 deletions
diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3 index ff8d89e3f4..36a134949c 100644 --- a/man3/getgrouplist.3 +++ b/man3/getgrouplist.3 @@ -153,7 +153,6 @@ int main(int argc, char *argv[]) { int j, ngroups; - gid_t *groups; struct passwd *pw; struct group *gr; @@ -164,7 +163,7 @@ main(int argc, char *argv[]) ngroups = atoi(argv[2]); - groups = malloc(sizeof(*groups) * ngroups); + gid_t *groups = malloc(sizeof(*groups) * ngroups); if (groups == NULL) { perror("malloc"); exit(EXIT_FAILURE); diff --git a/man3/insque.3 b/man3/insque.3 index 005ad8cc19..b49040c1b3 100644 --- a/man3/insque.3 +++ b/man3/insque.3 @@ -180,9 +180,7 @@ struct element { static struct element * new_element(void) { - struct element *e; - - e = malloc(sizeof(*e)); + struct element *e = malloc(sizeof(*e)); if (e == NULL) { fprintf(stderr, "malloc() failed\en"); exit(EXIT_FAILURE); diff --git a/man3/malloc_info.3 b/man3/malloc_info.3 index 598478dcc9..a5a3195580 100644 --- a/man3/malloc_info.3 +++ b/man3/malloc_info.3 @@ -212,7 +212,6 @@ int main(int argc, char *argv[]) { int j, tn, sleepTime; - pthread_t *thr; if (argc < 4) { fprintf(stderr, @@ -226,7 +225,7 @@ main(int argc, char *argv[]) blockSize = atoi(argv[3]); sleepTime = (argc > 4) ? atoi(argv[4]) : 0; - thr = calloc(numThreads, sizeof(*thr)); + pthread_t *thr = calloc(numThreads, sizeof(*thr)); if (thr == NULL) errExit("calloc"); diff --git a/man3/pthread_create.3 b/man3/pthread_create.3 index 5ffb145869..9df8cfcda9 100644 --- a/man3/pthread_create.3 +++ b/man3/pthread_create.3 @@ -324,7 +324,6 @@ int main(int argc, char *argv[]) { int s, tnum, opt, num_threads; - struct thread_info *tinfo; pthread_attr_t attr; int stack_size; void *res; @@ -361,7 +360,7 @@ main(int argc, char *argv[]) /* Allocate memory for pthread_create() arguments */ - tinfo = calloc(num_threads, sizeof(*tinfo)); + struct thread_info *tinfo = calloc(num_threads, sizeof(*tinfo)); if (tinfo == NULL) handle_error("calloc"); diff --git a/man3/tsearch.3 b/man3/tsearch.3 index f0ff80e8cd..b34ef516c3 100644 --- a/man3/tsearch.3 +++ b/man3/tsearch.3 @@ -322,12 +322,12 @@ action(const void *nodep, VISIT which, int depth) int main(void) { - int i, *ptr; + int i; void *val; srand(time(NULL)); for (i = 0; i < 12; i++) { - ptr = xmalloc(sizeof(*ptr)); + int *ptr = xmalloc(sizeof(*ptr)); *ptr = rand() & 0xff; val = tsearch((void *) ptr, &root, compare); if (val == NULL) |
