Re: jot: use strchr(3) and strspn(3) in getprec()

2016-08-12 Thread Jeremie Courreges-Anglas
Theo Buehler  writes:

> Here's one final diff I have for jot for now:
>
> Use strchr(3) and strspn(3) instead of handrolled functions.
>
> Part of dsl@NetBSD's r1.20.

ok jca@

-- 
jca | PGP: 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



jot: use strchr(3) and strspn(3) in getprec()

2016-08-12 Thread Theo Buehler
Here's one final diff I have for jot for now:

Use strchr(3) and strspn(3) instead of handrolled functions.

Part of dsl@NetBSD's r1.20.

Index: jot.c
===
RCS file: /cvs/src/usr.bin/jot/jot.c,v
retrieving revision 1.33
diff -u -p -r1.33 jot.c
--- jot.c   12 Aug 2016 21:31:11 -  1.33
+++ jot.c   12 Aug 2016 21:35:07 -
@@ -348,18 +348,9 @@ usage(void)
 static int
 getprec(char *s)
 {
-   char*p;
-   char*q;
-
-   for (p = s; *p != '\0'; p++)
-   if (*p == '.')
-   break;
-   if (*p == '\0')
+   if ((s = strchr(s, '.')) == NULL)
return (0);
-   for (q = ++p; *p != '\0'; p++)
-   if (!isdigit((unsigned char)*p))
-   break;
-   return (p - q);
+   return (strspn(s + 1, "0123456789"));
 }
 
 static void