linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Improve strtol(3) example
@ 2020-10-28  9:33 Alejandro Colomar
  2020-10-28  9:33 ` [PATCH 1/3] strtol.3: EXAMPLES: Delimit output string using "" Alejandro Colomar
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Alejandro Colomar @ 2020-10-28  9:33 UTC (permalink / raw)
  To: mtk.manpages; +Cc: Alejandro Colomar, linux-man

Hi Michael,

Here are a few improvements for the strtol(3) example.

Cheers,

Alex

Alejandro Colomar (3):
  strtol.3: EXAMPLES: Delimit output string using ""
  strtol.3: EXAMPLES: As the default base, use special value 0
  strtol.3: EXAMPLES: Simplify errno checking (no expected change in
    behavior)

 man3/strtol.3 | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

-- 
2.28.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] strtol.3: EXAMPLES: Delimit output string using ""
  2020-10-28  9:33 [PATCH 0/3] Improve strtol(3) example Alejandro Colomar
@ 2020-10-28  9:33 ` Alejandro Colomar
  2020-10-28  9:33 ` [PATCH 2/3] strtol.3: EXAMPLES: As the default base, use special value 0 Alejandro Colomar
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Alejandro Colomar @ 2020-10-28  9:33 UTC (permalink / raw)
  To: mtk.manpages; +Cc: Alejandro Colomar, linux-man

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
 man3/strtol.3 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man3/strtol.3 b/man3/strtol.3
index 20b453330..0feb12dbb 100644
--- a/man3/strtol.3
+++ b/man3/strtol.3
@@ -236,7 +236,7 @@ strtol() returned 123
 strtol() returned 123
 .RB "$" " ./a.out 123abc"
 strtol() returned 123
-Further characters after number: abc
+Further characters after number: "abc"
 .RB "$" " ./a.out 123abc 55"
 strtol: Invalid argument
 .RB "$" " ./a.out \(aq\(aq"
@@ -289,7 +289,7 @@ main(int argc, char *argv[])
     printf("strtol() returned %ld\en", val);
 
     if (*endptr != \(aq\e0\(aq)        /* Not necessarily an error... */
-        printf("Further characters after number: %s\en", endptr);
+        printf("Further characters after number: \e"%s\e"\en", endptr);
 
     exit(EXIT_SUCCESS);
 }
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] strtol.3: EXAMPLES: As the default base, use special value 0
  2020-10-28  9:33 [PATCH 0/3] Improve strtol(3) example Alejandro Colomar
  2020-10-28  9:33 ` [PATCH 1/3] strtol.3: EXAMPLES: Delimit output string using "" Alejandro Colomar
@ 2020-10-28  9:33 ` Alejandro Colomar
  2020-10-28  9:33 ` [PATCH 3/3] strtol.3: EXAMPLES: Simplify errno checking (no expected change in behavior) Alejandro Colomar
  2020-10-28 10:13 ` [PATCH 0/3] Improve strtol(3) example Michael Kerrisk (man-pages)
  3 siblings, 0 replies; 5+ messages in thread
From: Alejandro Colomar @ 2020-10-28  9:33 UTC (permalink / raw)
  To: mtk.manpages; +Cc: Alejandro Colomar, linux-man

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
 man3/strtol.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/strtol.3 b/man3/strtol.3
index 0feb12dbb..35252295e 100644
--- a/man3/strtol.3
+++ b/man3/strtol.3
@@ -266,7 +266,7 @@ main(int argc, char *argv[])
     }
 
     str = argv[1];
-    base = (argc > 2) ? atoi(argv[2]) : 10;
+    base = (argc > 2) ? atoi(argv[2]) : 0;
 
     errno = 0;    /* To distinguish success/failure after call */
     val = strtol(str, &endptr, base);
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] strtol.3: EXAMPLES: Simplify errno checking (no expected change in behavior)
  2020-10-28  9:33 [PATCH 0/3] Improve strtol(3) example Alejandro Colomar
  2020-10-28  9:33 ` [PATCH 1/3] strtol.3: EXAMPLES: Delimit output string using "" Alejandro Colomar
  2020-10-28  9:33 ` [PATCH 2/3] strtol.3: EXAMPLES: As the default base, use special value 0 Alejandro Colomar
@ 2020-10-28  9:33 ` Alejandro Colomar
  2020-10-28 10:13 ` [PATCH 0/3] Improve strtol(3) example Michael Kerrisk (man-pages)
  3 siblings, 0 replies; 5+ messages in thread
From: Alejandro Colomar @ 2020-10-28  9:33 UTC (permalink / raw)
  To: mtk.manpages; +Cc: Alejandro Colomar, linux-man

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
 man3/strtol.3 | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/man3/strtol.3 b/man3/strtol.3
index 35252295e..6b328fefe 100644
--- a/man3/strtol.3
+++ b/man3/strtol.3
@@ -273,8 +273,7 @@ main(int argc, char *argv[])
 
     /* Check for various possible errors */
 
-    if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
-            || (errno != 0 && val == 0)) {
+    if (errno != 0) {
         perror("strtol");
         exit(EXIT_FAILURE);
     }
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] Improve strtol(3) example
  2020-10-28  9:33 [PATCH 0/3] Improve strtol(3) example Alejandro Colomar
                   ` (2 preceding siblings ...)
  2020-10-28  9:33 ` [PATCH 3/3] strtol.3: EXAMPLES: Simplify errno checking (no expected change in behavior) Alejandro Colomar
@ 2020-10-28 10:13 ` Michael Kerrisk (man-pages)
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-10-28 10:13 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man

On 10/28/20 10:33 AM, Alejandro Colomar wrote:
> Hi Michael,
> 
> Here are a few improvements for the strtol(3) example.

Thanks, Alex. I've applied all of these.

Cheers,

Michael

> Cheers,
> 
> Alex
> 
> Alejandro Colomar (3):
>   strtol.3: EXAMPLES: Delimit output string using ""
>   strtol.3: EXAMPLES: As the default base, use special value 0
>   strtol.3: EXAMPLES: Simplify errno checking (no expected change in
>     behavior)
> 
>  man3/strtol.3 | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-29  1:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-28  9:33 [PATCH 0/3] Improve strtol(3) example Alejandro Colomar
2020-10-28  9:33 ` [PATCH 1/3] strtol.3: EXAMPLES: Delimit output string using "" Alejandro Colomar
2020-10-28  9:33 ` [PATCH 2/3] strtol.3: EXAMPLES: As the default base, use special value 0 Alejandro Colomar
2020-10-28  9:33 ` [PATCH 3/3] strtol.3: EXAMPLES: Simplify errno checking (no expected change in behavior) Alejandro Colomar
2020-10-28 10:13 ` [PATCH 0/3] Improve strtol(3) example Michael Kerrisk (man-pages)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).