Commit Graph

6383 Commits

Author SHA1 Message Date
Alejandro Colomar 96c63a40af aiocb.3: New link to new documented type in system_data_types(7)
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-18 23:27:22 +02:00
Alejandro Colomar 62f4b73a5e regmatch_t.3: New link for new documented type in system_data_types(7)
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-18 22:45:02 +02:00
Alejandro Colomar 1c0569eac3 regoff_t.3: New link to new documented type in system_data_types(7)
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-18 22:31:15 +02:00
Alejandro Colomar f723e17664 ptrdiff_t.3: New link to new documented type in system_data_types(7)
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-18 22:19:56 +02:00
Alejandro Colomar 231b22152a size_t.3: New link to new documented type in system_data_types(7)
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-18 22:06:55 +02:00
Michael Kerrisk 9f2a6007d1 intro.2, intro.3, feature_test_macros.7, standards.7: SEE ALSO: add system_data_types(7)
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-17 22:54:01 +02:00
Alejandro Colomar 9334a43e41 sigval.3, ssize_t.3, suseconds_t.3, time_t.3, timer_t.3, timespec.3, timeval.3: New links to new system_data_types(7) page
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-17 22:54:01 +02:00
Marko Hrastovec a23b00988a freeaddrinfo.3: Fix memory leaks in freeaddrinfo() examples
[mtk: the coding style used in the example could lead people to
inject memory leaks in their code if they cut/paste/modify the
code to replace "exit" paths with "return" paths from a library
function.]

[Marko, from the mail thread discussing this patch:]
You are right about terminating the process. However, people copy
that example and put the code in a function changing "exit" to
"return". There are a bunch of examples like that here
https://beej.us/guide/bgnet/html/#poll, for instance. That error
bothered me when reading the network programming guide
https://beej.us/guide/bgnet/html/. Than I looked for information
elsewhere:

https://stackoverflow.com/questions/6712740/valgrind-reporting-that-getaddrinfo-is-leaking-memory

https://stackoverflow.com/questions/15690303/server-client-sockets-freeaddrinfo3-placement

And finally, I checked manual pages and saw where these errors
come from.

When you change that to a function and return without doing
freeaddrinfo, that is a memory leak. I believe an example should
show good programming practices. Relying on exiting and clearing
the memory in that case is not such a case. In my opinion, these
examples lead people to make mistakes in their programs.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-17 09:12:24 +02:00
Alejandro Colomar 8eb90116f1 add_key.2, clock_getres.2, clone.2, futex.2, getdents.2, getpid.2, getrlimit.2, ioctl_ns.2, kcmp.2, keyctl.2, memfd_create.2, request_key.2, stat.2, timer_create.2, wait.2, clock_getcpuclockid.3, dl_iterate_phdr.3, getgrent_r.3, getpwent_r.3, getpwnam.3, posix_spawn.3, pthread_getcpuclockid.3, strcat.3, feature_test_macros.7, user_namespaces.7: Switch printf() casts to use [u]intmax_t + %ju / %jd
Let's move to the 21st century. Instead of casting system data
types to long/long long/etc. in printf() calls, instead cast to
intmax_t or uintmax_t, the largest available signed/unsigned
integer types.

[mtk: rewrote commit message]

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-15 07:39:19 +02:00
Alejandro Colomar 627a256ed6 malloc_hook.3: Remove unneeded cast, and print 'size_t' with "%zu"
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-13 07:44:06 +02:00
Alejandro Colomar dc97703b4a eventfd.2, mprotect.2, pidfd_open.2, spu_run.2, timer_create.2, bswap.3, dl_iterate_phdr.3, endian.3, pthread_attr_init.3, pthread_getattr_np.3, vcs.4, rtld-audit.7: In printf(): s/0x%/%#/ except when followed by X instead of x
Use printf()'s '#' flag character to prepend the string "0x".

However, when the number is printed in uppercase, and the prefix
is in lowercase, the string "0x" needs to be manually written.

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-12 08:38:20 +02:00
Alejandro Colomar ec8b00033c getaddrinfo_a.3: Use C99 style to declare loop counter variables
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-12 08:38:20 +02:00
Alejandro Colomar ae85f653e4 msgctl.2, outb.2, abs.3, dl_iterate_phdr.3, drand48.3, drand48_r.3, encrypt.3, ffs.3, lrint.3, lround.3, ntp_gettime.3, printf.3, random.3, scalbln.3, scanf.3, strtol.3, strtoul.3, utmp.5, feature_test_macros.7, rtld-audit.7: Omit 'int' keyword for 'short', 'long' and 'long long' types, both signed and 'unsigned'
For consistency.

The types are written both with and without the redundant 'int' keyword
all over the man-pages.  However, the most used form, by far, is the one
without 'int'.

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-12 08:37:41 +02:00
Michael Kerrisk 7d9746136e pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3: Use correct type (size_t) for some variables
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-11 14:24:56 +02:00
Michael Kerrisk 404990aeb9 pthread_getattr_np.3: tfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-11 14:22:59 +02:00
Jakub Wilk 581c3ea730 bswap.3: Use strtoull() for parsing 64-bit numbers
Before, on 32-bit systems:

    $ ./a.out 0x0123456789abcdef
    0xffffffff ==> 0xffffffff00000000

After:

    $ ./a.out 0x0123456789abcdef
    0x123456789abcdef ==> 0xefcdab8967452301

Signed-off-by: Jakub Wilk <jwilk@jwilk.net>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-11 14:11:10 +02:00
Alejandro Colomar 0ef3e1b730 clock_getcpuclockid.3: Remove unneeded cast
Member 'tv_nsec' of 'struct timespec' is of type 'long' (see time.h.0p),
and therefore, the cast is completely redundant.

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-11 13:04:21 +02:00
Michael Kerrisk 49f06c0010 pthread_setname_np.3: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-11 11:33:28 +02:00
Alejandro Colomar cbb22338cf fread.3: Move ARRAY_SIZE logic into macro
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-11 11:33:28 +02:00
Alejandro Colomar 1656c1702d getpwent_r.3: Use sizeof() to get buffer size (instead of hardcoding macro name)
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-11 09:17:50 +02:00
Alejandro Colomar cf254328fe getgrent_r.3: Use sizeof() to get buffer size (instead of hardcoding macro name)
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-11 09:17:45 +02:00
Alejandro Colomar 9a84e3383f get_phys_pages.3: Write 'long' instead of 'long int'
For consistency.

Most man pages use 'long' instead of 'long int'.

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-11 08:43:37 +02:00
Alejandro Colomar 4e4e6e5e14 getpwent_r.3: Declare variables with different types in different lines
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-11 08:43:14 +02:00
Alejandro Colomar 2bbfed1b16 offsetof.3: Use "%zu" rather than "%zd" when printing 'size_t' values
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-11 08:41:18 +02:00
Jakub Wilk a99abf87e2 dlopen.3, gnu_get_libc_version.3: tfix
Escape hyphens.

Signed-off-by: Jakub Wilk <jwilk@jwilk.net>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-10 12:40:34 +02:00
Michael Kerrisk ea4cec5f87 dlopen.3: Clarify DT_RUNPATH/DT_RPATH details
It is the DT_RUNPATH/DT_RPATH of the calling object (not the
executable) that is relevant for the library search. Verified
by experiment.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-10 11:48:08 +02:00
Michael Kerrisk 4f247e780f getopt.3: Minor wording fix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-10 09:35:27 +02:00
Mike Frysinger 4e0df17fce posix_spawn.3: tfix
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-08 07:29:33 +02:00
Alejandro Colomar b33535f535 bsearch.3: Declare variables with different types in different lines
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-08 07:26:00 +02:00
Alejandro Colomar 037c6fd4ee pthread_getattr_np.3: Use "%zu" and "%zx" when printing 'size_t' values
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-07 22:21:52 +02:00
Alejandro Colomar a3eeca342d fopencookie.3: Fix bugs in example
fread(3), unlike read(2) which returns a ssize_t, returns a
size_t.  It doesn't distinguish between error and enf-of-file.
Instead, either ferror(3) or feof(3) need to be checked if fread()
returned 0.

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-07 12:32:03 +02:00
Alejandro Colomar a1eb1a6a33 fopencookie.3: printf()'s .* expects an int; cast accordingly
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-07 12:31:10 +02:00
Michael Kerrisk 7497e9d8c8 errno.3: Note that the pthreads APIs do not set errno
Reported-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-07 11:21:06 +02:00
Alejandro Colomar 0ca5f06155 getline.3: Use %zd rather than %zu when printing 'ssize_t' values
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-07 11:00:05 +02:00
Alejandro Colomar 29a95ad159 hcreate.3: Declare variables with different types in different lines
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-07 10:59:47 +02:00
Michael Kerrisk 51c1b1031b dlopen.3: Revert accidentally applied "dlopen.3: Remove unneeded cast"
This reverts commit ffa50fbf01.
2020-09-06 16:58:45 +02:00
Alejandro Colomar 9ba82f225c qsort.3: Fix casts
`p1` (and `p2` too) is `const void *` and it comes from a
`const char **` (for legacy reasons, argv is not `const` but should be
treated as if it were).  That means, the ultimate `char` is `const`:
"a pointer to a pointer to a const char".

Let's see what is going on before the fix first, and then the fix.

Before the fix:

`(char *const *)` (I removed the space on purpose) casts `p1` to be
"a pointer to a const pointer to a non-const char".  That's clearly
not what it originally was.

Then we dereference, ending with a `char *const`, which is
"a const pointer to a non-const char".  But given that the pointer value
is passed to a function, `const` doesn't make sense there, because the
function will already take a copy of it, so it is impossible to modify
the pointer itself.

The fix:

`(const char **)` The only thing that is const is the ultimate `char`,
which is the only thing that matters, because it is the only thing
strcmp(3) has access to (everything else, i.e. the pointers, are
copies).

Then, after the dereference we end up with `const char *`, the type of
argv (more or less, as previously noted), which is also the type of the
arguments to strcmp(3).

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-06 14:58:37 +02:00
Alejandro Colomar 684130db5c bsearch.3: Fix intermediate type and remove unneeded casts
Casting `const void *` to `struct mi *` should result in a warning if
done implicitly.  The explicit cast was probably silencing that warning.
`const` can and should be kept.
Now, casting `const void *` to `const struct mi *` is done implicitly.

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-06 14:58:29 +02:00
Alejandro Colomar a0303c05c4 pthread_sigmask.3: Remove unneeded casts
The type `sigset_t *` is implicitly casted to `void *`.
Explicitly casting can silence warnings when mistakes are made, so it's
better to remove those casts when possible.

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-06 14:57:50 +02:00
Alejandro Colomar ffa50fbf01 dlopen.3: Remove unneeded cast
Casting `void *` to `double (*cosine)(double)` is already done
implicitly.
I had doubts about this one, but `gcc -Wall -Wextra` didn't complain
about it.
Explicitly casting can silence warnings when mistakes are made, so it's
better to remove those casts when possible.

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-06 14:56:18 +02:00
Alejandro Colomar 7ac7f6510b stdarg.3: Declare variables with different types in different lines
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-06 14:52:22 +02:00
Alejandro Colomar 0e00826840 tsearch.3: Simplify type usage and remove unneeded casts
The type of `val` is `int **`, and it will work with tsearch()
anyway because of implicit cast from `void *`, so declaring it as an
`int **` simplifies the code.

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-05 21:42:00 +02:00
Alejandro Colomar c7e5aa83d2 tsearch.3: Remove unneeded cast
Casting `int *` to `const void *` is already done implicitly.
Not only that, but the explicit cast to `void *` was slightly
misleading.

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-05 17:40:44 +02:00
Alejandro Colomar 69003a5891 tsearch.3: Use size_t for malloc() argument
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-05 17:27:46 +02:00
Michael Kerrisk 88893a773c sprof.1, eventfd.2, execve.2, futex.2, getdents.2, mprotect.2, open_by_handle_at.2, recvmmsg.2, sched_setaffinity.2, CPU_SET.3, backtrace.3, bsearch.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, envz_add.3, fopencookie.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrent_r.3, getgrouplist.3, getifaddrs.3, getprotoent_r.3, getservent_r.3, hsearch.3, mallinfo.3, malloc_info.3, mbstowcs.3, mtrace.3, pthread_create.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, qsort.3, rand.3, strcat.3, strtok.3, tsearch.3, wordexp.3, core.5, aio.7, inotify.7, sock_diag.7, unix.7, user_namespaces.7: Use C99 style to declare loop counter variables
Rather than:

    sometype x;

    for (x = ....; ...)

use

    for (sometype x = ...; ...)

This brings the declaration and use closer together (thus aiding
readability) and also clearly indicates the scope of the loop
counter variable.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-05 17:20:12 +02:00
Michael Kerrisk 48d0510307 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>
2020-09-05 16:34:34 +02:00
Alejandro Colomar 3b7e518d44 tsearch.3: Use sizeof consistently
Use ``sizeof`` consistently through all the examples in the following
way:

- Use the name of the variable instead of its type as argument for
  ``sizeof``.

	Rationale:
	https://www.kernel.org/doc/html/v5.8/process/coding-style.html#allocating-memory

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-05 16:22:21 +02:00
Alejandro Colomar 0091da30d5 pthread_create.3: Use sizeof consistently
Use ``sizeof`` consistently through all the examples in the following
way:

- Use the name of the variable instead of its type as argument for
  ``sizeof``.

	Rationale:
	https://www.kernel.org/doc/html/v5.8/process/coding-style.html#allocating-memory

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-05 16:21:33 +02:00
Alejandro Colomar a7751aafaa mbstowcs.3: Use sizeof consistently
Use ``sizeof`` consistently through all the examples in the following
way:

- Use the name of the variable instead of its type as argument for
  ``sizeof``.

	Rationale:
	https://www.kernel.org/doc/html/v5.8/process/coding-style.html#allocating-memory

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-05 16:19:44 +02:00
Alejandro Colomar 5780a2e798 shm_open.3: Use sizeof consistently
Use ``sizeof`` consistently through all the examples in the following
way:

- Use the name of the variable instead of its type as argument for
  ``sizeof``.

	Rationale:
	https://www.kernel.org/doc/html/v5.8/process/coding-style.html#allocating-memory

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-05 14:49:42 +02:00