Re: svn commit: r329237 - head/sys/libkern

2018-02-13 Thread Bruce Evans

On Tue, 13 Feb 2018, Ian Lepore wrote:


On Tue, 2018-02-13 at 14:43 -0500, Ed Maste wrote:

On 13 February 2018 at 14:23, Ian Lepore  wrote:


On Tue, 2018-02-13 at 19:17 +, Ed Maste wrote:


Author: emaste
Date: Tue Feb 13 19:17:48 2018
New Revision: 329237
URL: https://svnweb.freebsd.org/changeset/base/329237

Log:
? libkern: use nul for terminating char rather than 0

? Akin to the change made in r188080 for lib/libc/string/.

? Reported by:bde
? Sponsored by:???The FreeBSD Foundation

There are many ways to spell 0.??Why are we using something other
than
the simplest way???Is it a style rule thing, or is it portability-
correctness, or what?


style(9) requires '\0' (by always spelling the character constant with
value 0 like that).


I made the change to improve consistency between lib/libc/string and
sys/libkern, which is what Bruce commented on some time ago. I don't
have a personal preference for 0 or '\0' but definitely believe that
if we have multiple, similar copies of a function they ought to avoid
gratuitous differences. (I'm happy to change both trees to 0 if
that's
preferred.)


Core parts of libc like stdio and (MI) string use '\0' fairly consistently.
There were about 10-20 plain 0's in string in FreeBSD-5, but most of these
have been changed to '\0'.  This gives a much larger set of examples of
normal style.


Oh, I agree completely about consistancy being important. ?I just
wanted to know whether I should try to remember to always use \0
because it's a rule or has some benefit I didn't know about.

20+ years ago I used to slavishly ensure I always used \0 when a char
type was involved, just as a personal style thing. ?Then over time I
came to the conclusion that "0 is 0 no matter how you spell it, so keep
it simple" (except for pointers... even in c++ I've always used NULL).


Probably the BSD style rule has the same origin.

Bruce___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r329237 - head/sys/libkern

2018-02-13 Thread Warner Losh
On Tue, Feb 13, 2018 at 1:40 PM, Ravi Pokala <rpok...@mac.com> wrote:

> -Original Message-
> From: <owner-src-committ...@freebsd.org> on behalf of Eric van Gyzen <
> e...@vangyzen.net>
> Date: 2018-02-13, Tuesday at 11:52
> To: Ed Maste <ema...@freebsd.org>, Ian Lepore <i...@freebsd.org>
> Cc: src-committers <src-committ...@freebsd.org>, <svn-src-all@freebsd.org>,
> <svn-src-h...@freebsd.org>
> Subject: Re: svn commit: r329237 - head/sys/libkern
>
> > ...
> >
> > I prefer '\0' here because it tells the reader that it's a NUL
> > character, as opposed to a NULL pointer or a zero integer.  Yes, the
> > reader should already know that, but the author can /help/ the reader by
> > communicating more clearly and completely.
> >
> > Eric
>
> Out of morbid curiosity, does any standard (or any of our non-standard
> headers) define a "NUL" macro for use as a manual string terminator?
>

No. There's no standard define.

Warner
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r329237 - head/sys/libkern

2018-02-13 Thread Ravi Pokala
-Original Message-
From: <owner-src-committ...@freebsd.org> on behalf of Eric van Gyzen 
<e...@vangyzen.net>
Date: 2018-02-13, Tuesday at 11:52
To: Ed Maste <ema...@freebsd.org>, Ian Lepore <i...@freebsd.org>
Cc: src-committers <src-committ...@freebsd.org>, <svn-src-all@freebsd.org>, 
<svn-src-h...@freebsd.org>
Subject: Re: svn commit: r329237 - head/sys/libkern

> ...
> 
> I prefer '\0' here because it tells the reader that it's a NUL
> character, as opposed to a NULL pointer or a zero integer.  Yes, the
> reader should already know that, but the author can /help/ the reader by
> communicating more clearly and completely.
>
> Eric

Out of morbid curiosity, does any standard (or any of our non-standard headers) 
define a "NUL" macro for use as a manual string terminator?

-Ravi (rpokala@)


___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r329237 - head/sys/libkern

2018-02-13 Thread Conrad Meyer
On Tue, Feb 13, 2018 at 11:52 AM, Eric van Gyzen  wrote:
> On 02/13/2018 13:43, Ed Maste wrote:
>> On 13 February 2018 at 14:23, Ian Lepore  wrote:
>>> There are many ways to spell 0.  Why are we using something other than
>>> the simplest way?  Is it a style rule thing, or is it portability-
>>> correctness, or what?
>>
>> I made the change to improve consistency between lib/libc/string and
>> sys/libkern,
>> ...
>
> I prefer '\0' here because it tells the reader that it's a NUL
> character, as opposed to a NULL pointer or a zero integer.  Yes, the
> reader should already know that, but the author can /help/ the reader by
> communicating more clearly and completely.

And I prefer 0, because it's easier to type and conveys exactly the
same meaning.  A character NUL is simply a zero integer of char type.

These are standard library string manipulation routines with char
pointer types.  It is already extremely clear to the reader that the
zeros involved are end-of-string sentinels.

Best,
Conrad
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r329237 - head/sys/libkern

2018-02-13 Thread Ian Lepore
On Tue, 2018-02-13 at 14:43 -0500, Ed Maste wrote:
> On 13 February 2018 at 14:23, Ian Lepore  wrote:
> > 
> > On Tue, 2018-02-13 at 19:17 +, Ed Maste wrote:
> > > 
> > > Author: emaste
> > > Date: Tue Feb 13 19:17:48 2018
> > > New Revision: 329237
> > > URL: https://svnweb.freebsd.org/changeset/base/329237
> > > 
> > > Log:
> > >   libkern: use nul for terminating char rather than 0
> > > 
> > >   Akin to the change made in r188080 for lib/libc/string/.
> > > 
> > >   Reported by:bde
> > >   Sponsored by:   The FreeBSD Foundation
> > There are many ways to spell 0.  Why are we using something other
> > than
> > the simplest way?  Is it a style rule thing, or is it portability-
> > correctness, or what?
> I made the change to improve consistency between lib/libc/string and
> sys/libkern, which is what Bruce commented on some time ago. I don't
> have a personal preference for 0 or '\0' but definitely believe that
> if we have multiple, similar copies of a function they ought to avoid
> gratuitous differences. (I'm happy to change both trees to 0 if
> that's
> preferred.)
> 

Oh, I agree completely about consistancy being important.  I just
wanted to know whether I should try to remember to always use \0
because it's a rule or has some benefit I didn't know about.

20+ years ago I used to slavishly ensure I always used \0 when a char
type was involved, just as a personal style thing.  Then over time I
came to the conclusion that "0 is 0 no matter how you spell it, so keep
it simple" (except for pointers... even in c++ I've always used NULL).

-- Ian
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r329237 - head/sys/libkern

2018-02-13 Thread Eric van Gyzen
On 02/13/2018 13:43, Ed Maste wrote:
> On 13 February 2018 at 14:23, Ian Lepore  wrote:
>> On Tue, 2018-02-13 at 19:17 +, Ed Maste wrote:
>>> Author: emaste
>>> Date: Tue Feb 13 19:17:48 2018
>>> New Revision: 329237
>>> URL: https://svnweb.freebsd.org/changeset/base/329237
>>>
>>> Log:
>>>   libkern: use nul for terminating char rather than 0
>>>
>>>   Akin to the change made in r188080 for lib/libc/string/.
>>>
>>>   Reported by:bde
>>>   Sponsored by:   The FreeBSD Foundation
>>
>> There are many ways to spell 0.  Why are we using something other than
>> the simplest way?  Is it a style rule thing, or is it portability-
>> correctness, or what?
> 
> I made the change to improve consistency between lib/libc/string and
> sys/libkern, which is what Bruce commented on some time ago. I don't
> have a personal preference for 0 or '\0' but definitely believe that
> if we have multiple, similar copies of a function they ought to avoid
> gratuitous differences. (I'm happy to change both trees to 0 if that's
> preferred.)

I prefer '\0' here because it tells the reader that it's a NUL
character, as opposed to a NULL pointer or a zero integer.  Yes, the
reader should already know that, but the author can /help/ the reader by
communicating more clearly and completely.

Eric
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r329237 - head/sys/libkern

2018-02-13 Thread Ed Maste
On 13 February 2018 at 14:23, Ian Lepore  wrote:
> On Tue, 2018-02-13 at 19:17 +, Ed Maste wrote:
>> Author: emaste
>> Date: Tue Feb 13 19:17:48 2018
>> New Revision: 329237
>> URL: https://svnweb.freebsd.org/changeset/base/329237
>>
>> Log:
>>   libkern: use nul for terminating char rather than 0
>>
>>   Akin to the change made in r188080 for lib/libc/string/.
>>
>>   Reported by:bde
>>   Sponsored by:   The FreeBSD Foundation
>
> There are many ways to spell 0.  Why are we using something other than
> the simplest way?  Is it a style rule thing, or is it portability-
> correctness, or what?

I made the change to improve consistency between lib/libc/string and
sys/libkern, which is what Bruce commented on some time ago. I don't
have a personal preference for 0 or '\0' but definitely believe that
if we have multiple, similar copies of a function they ought to avoid
gratuitous differences. (I'm happy to change both trees to 0 if that's
preferred.)
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r329237 - head/sys/libkern

2018-02-13 Thread Ian Lepore
On Tue, 2018-02-13 at 19:17 +, Ed Maste wrote:
> Author: emaste
> Date: Tue Feb 13 19:17:48 2018
> New Revision: 329237
> URL: https://svnweb.freebsd.org/changeset/base/329237
> 
> Log:
>   libkern: use nul for terminating char rather than 0
>   
>   Akin to the change made in r188080 for lib/libc/string/.
>   
>   Reported by:bde
>   Sponsored by:   The FreeBSD Foundation

There are many ways to spell 0.  Why are we using something other than
the simplest way?  Is it a style rule thing, or is it portability-
correctness, or what?

-- Ian
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r329237 - head/sys/libkern

2018-02-13 Thread Ed Maste
Author: emaste
Date: Tue Feb 13 19:17:48 2018
New Revision: 329237
URL: https://svnweb.freebsd.org/changeset/base/329237

Log:
  libkern: use nul for terminating char rather than 0
  
  Akin to the change made in r188080 for lib/libc/string/.
  
  Reported by:  bde
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/libkern/strcmp.c
  head/sys/libkern/strncat.c
  head/sys/libkern/strncpy.c
  head/sys/libkern/strsep.c
  head/sys/libkern/strstr.c

Modified: head/sys/libkern/strcmp.c
==
--- head/sys/libkern/strcmp.c   Tue Feb 13 19:17:33 2018(r329236)
+++ head/sys/libkern/strcmp.c   Tue Feb 13 19:17:48 2018(r329237)
@@ -44,7 +44,7 @@ int
 strcmp(const char *s1, const char *s2)
 {
while (*s1 == *s2++)
-   if (*s1++ == 0)
+   if (*s1++ == '\0')
return (0);
return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1));
 }

Modified: head/sys/libkern/strncat.c
==
--- head/sys/libkern/strncat.c  Tue Feb 13 19:17:33 2018(r329236)
+++ head/sys/libkern/strncat.c  Tue Feb 13 19:17:48 2018(r329237)
@@ -53,11 +53,11 @@ strncat(char *dst, const char *src, size_t n)
while (*d != 0)
d++;
do {
-   if ((*d = *s++) == 0)
+   if ((*d = *s++) == '\0')
break;
d++;
} while (--n != 0);
-   *d = 0;
+   *d = '\0';
}
return (dst);
 }

Modified: head/sys/libkern/strncpy.c
==
--- head/sys/libkern/strncpy.c  Tue Feb 13 19:17:33 2018(r329236)
+++ head/sys/libkern/strncpy.c  Tue Feb 13 19:17:48 2018(r329237)
@@ -49,10 +49,10 @@ strncpy(char * __restrict dst, const char * __restrict
const char *s = src;
 
do {
-   if ((*d++ = *s++) == 0) {
+   if ((*d++ = *s++) == '\0') {
/* NUL pad the remaining n-1 bytes */
while (--n != 0)
-   *d++ = 0;
+   *d++ = '\0';
break;
}
} while (--n != 0);

Modified: head/sys/libkern/strsep.c
==
--- head/sys/libkern/strsep.c   Tue Feb 13 19:17:33 2018(r329236)
+++ head/sys/libkern/strsep.c   Tue Feb 13 19:17:48 2018(r329237)
@@ -64,14 +64,14 @@ strsep(char **stringp, const char *delim)
spanp = delim;
do {
if ((sc = *spanp++) == c) {
-   if (c == 0)
+   if (c == '\0')
s = NULL;
else
-   s[-1] = 0;
+   s[-1] = '\0';
*stringp = s;
return (tok);
}
-   } while (sc != 0);
+   } while (sc != '\0');
}
/* NOTREACHED */
 }

Modified: head/sys/libkern/strstr.c
==
--- head/sys/libkern/strstr.c   Tue Feb 13 19:17:33 2018(r329236)
+++ head/sys/libkern/strstr.c   Tue Feb 13 19:17:48 2018(r329237)
@@ -51,7 +51,7 @@ strstr(const char *s, const char *find)
len = strlen(find);
do {
do {
-   if ((sc = *s++) == 0)
+   if ((sc = *s++) == '\0')
return (NULL);
} while (sc != c);
} while (strncmp(s, find, len) != 0);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"