All of lore.kernel.org
 help / color / mirror / Atom feed
From: dave@treblig.org
To: alx@kernel.org
Cc: linux-man@vger.kernel.org, "Dr. David Alan Gilbert" <dave@treblig.org>
Subject: [PATCH] man/man3/pthread_attr_init.3: Replace errc
Date: Wed, 20 Aug 2025 02:27:25 +0100	[thread overview]
Message-ID: <20250820012725.440625-1-dave@treblig.org> (raw)

From: "Dr. David Alan Gilbert" <dave@treblig.org>

The pthread_attr_init.3 example uses 'errc' to exit on an error
printing the error code.  However, 'errc' is a BSDism that Linux
doesn't (and has never?) have.

Replace it by 'errx' with a strerror() call.

Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
---
 man/man3/pthread_attr_init.3 | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/man/man3/pthread_attr_init.3 b/man/man3/pthread_attr_init.3
index e9058b8fe..9d0783e54 100644
--- a/man/man3/pthread_attr_init.3
+++ b/man/man3/pthread_attr_init.3
@@ -153,6 +153,7 @@ .SS Program source
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 \&
 static void
@@ -165,7 +166,7 @@ .SS Program source
 \&
     s = pthread_attr_getdetachstate(attr, &i);
     if (s != 0)
-        errc(EXIT_FAILURE, s, "pthread_attr_getdetachstate");
+        errx(EXIT_FAILURE, "pthread_attr_getdetachstate: %s", strerror(s));
     printf("%sDetach state        = %s\[rs]n", prefix,
            (i == PTHREAD_CREATE_DETACHED) ? "PTHREAD_CREATE_DETACHED" :
            (i == PTHREAD_CREATE_JOINABLE) ? "PTHREAD_CREATE_JOINABLE" :
@@ -173,7 +174,7 @@ .SS Program source
 \&
     s = pthread_attr_getscope(attr, &i);
     if (s != 0)
-        errc(EXIT_FAILURE, s, "pthread_attr_getscope");
+        errx(EXIT_FAILURE, "pthread_attr_getscope: %s", strerror(s));
     printf("%sScope               = %s\[rs]n", prefix,
            (i == PTHREAD_SCOPE_SYSTEM)  ? "PTHREAD_SCOPE_SYSTEM" :
            (i == PTHREAD_SCOPE_PROCESS) ? "PTHREAD_SCOPE_PROCESS" :
@@ -181,7 +182,7 @@ .SS Program source
 \&
     s = pthread_attr_getinheritsched(attr, &i);
     if (s != 0)
-        errc(EXIT_FAILURE, s, "pthread_attr_getinheritsched");
+        errx(EXIT_FAILURE, "pthread_attr_getinheritsched: %s", strerror(s));
     printf("%sInherit scheduler   = %s\[rs]n", prefix,
            (i == PTHREAD_INHERIT_SCHED)  ? "PTHREAD_INHERIT_SCHED" :
            (i == PTHREAD_EXPLICIT_SCHED) ? "PTHREAD_EXPLICIT_SCHED" :
@@ -189,7 +190,7 @@ .SS Program source
 \&
     s = pthread_attr_getschedpolicy(attr, &i);
     if (s != 0)
-        errc(EXIT_FAILURE, s, "pthread_attr_getschedpolicy");
+        errx(EXIT_FAILURE, "pthread_attr_getschedpolicy: %s", strerror(s));
     printf("%sScheduling policy   = %s\[rs]n", prefix,
            (i == SCHED_OTHER) ? "SCHED_OTHER" :
            (i == SCHED_FIFO)  ? "SCHED_FIFO" :
@@ -198,17 +199,17 @@ .SS Program source
 \&
     s = pthread_attr_getschedparam(attr, &sp);
     if (s != 0)
-        errc(EXIT_FAILURE, s, "pthread_attr_getschedparam");
+        errx(EXIT_FAILURE, "pthread_attr_getschedparam: %s", strerror(s));
     printf("%sScheduling priority = %d\[rs]n", prefix, sp.sched_priority);
 \&
     s = pthread_attr_getguardsize(attr, &v);
     if (s != 0)
-        errc(EXIT_FAILURE, s, "pthread_attr_getguardsize");
+        errx(EXIT_FAILURE, "pthread_attr_getguardsize: %s", strerror(s));
     printf("%sGuard size          = %zu bytes\[rs]n", prefix, v);
 \&
     s = pthread_attr_getstack(attr, &stkaddr, &v);
     if (s != 0)
-        errc(EXIT_FAILURE, s, "pthread_attr_getstack");
+        errx(EXIT_FAILURE, "pthread_attr_getstack: %s", strerror(s));
     printf("%sStack address       = %p\[rs]n", prefix, stkaddr);
     printf("%sStack size          = %#zx bytes\[rs]n", prefix, v);
 }
@@ -225,7 +226,7 @@ .SS Program source
 \&
     s = pthread_getattr_np(pthread_self(), &gattr);
     if (s != 0)
-        errc(EXIT_FAILURE, s, "pthread_getattr_np");
+        errx(EXIT_FAILURE, "pthread_getattr_np: %s", strerror(s));
 \&
     printf("Thread attributes:\[rs]n");
     display_pthread_attr(&gattr, "\[rs]t");
@@ -255,37 +256,37 @@ .SS Program source
 \&
         s = pthread_attr_init(&attr);
         if (s != 0)
-            errc(EXIT_FAILURE, s, "pthread_attr_init");
+            errx(EXIT_FAILURE, "pthread_attr_init: %s", strerror(s));
 \&
         s = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
         if (s != 0)
-            errc(EXIT_FAILURE, s, "pthread_attr_setdetachstate");
+            errx(EXIT_FAILURE, "pthread_attr_setdetachstate: %s", strerror(s));
 \&
         s = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
         if (s != 0)
-            errc(EXIT_FAILURE, s, "pthread_attr_setinheritsched");
+            errx(EXIT_FAILURE, "pthread_attr_setinheritsched: %s", strerror(s));
 \&
         stack_size = strtoul(argv[1], NULL, 0);
 \&
         s = posix_memalign(&sp, sysconf(_SC_PAGESIZE), stack_size);
         if (s != 0)
-            errc(EXIT_FAILURE, s, "posix_memalign");
+            errx(EXIT_FAILURE, "posix_memalign: %s", strerror(s));
 \&
         printf("posix_memalign() allocated at %p\[rs]n", sp);
 \&
         s = pthread_attr_setstack(&attr, sp, stack_size);
         if (s != 0)
-            errc(EXIT_FAILURE, s, "pthread_attr_setstack");
+            errx(EXIT_FAILURE, "pthread_attr_setstack: %s", strerror(s));
     }
 \&
     s = pthread_create(&thr, attrp, &thread_start, NULL);
     if (s != 0)
-        errc(EXIT_FAILURE, s, "pthread_create");
+        errx(EXIT_FAILURE, "pthread_create: %s", strerror(s));
 \&
     if (attrp != NULL) {
         s = pthread_attr_destroy(attrp);
         if (s != 0)
-            errc(EXIT_FAILURE, s, "pthread_attr_destroy");
+            errx(EXIT_FAILURE, "pthread_attr_destroy: %s", strerror(s));
     }
 \&
     pause();    /* Terminates when other thread calls exit() */
-- 
2.50.1


             reply	other threads:[~2025-08-20  1:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-20  1:27 dave [this message]
2025-08-20  8:12 ` [PATCH] man/man3/pthread_attr_init.3: Replace errc Alejandro Colomar
2025-08-20 14:10   ` Dr. David Alan Gilbert
2025-08-20 15:52     ` Alejandro Colomar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250820012725.440625-1-dave@treblig.org \
    --to=dave@treblig.org \
    --cc=alx@kernel.org \
    --cc=linux-man@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.