Re: EXEC(3)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 12/11/2018 21:21, Jonny Grant wrote:
Hi mtk, Jakub!

I looked at this again, when I saw that POSIX and Glibc specs both use "NUL" and "NUL terminator" rather than the man-pages style "null byte".

Likewise lots, eg K&R use "null pointer"

I'll reply in line below with the references.


On 10/11/2018 06:39, Michael Kerrisk (man-pages) wrote:
Hello Jonny,

On 11/9/18 4:33 PM, Jonny Grant wrote:


On 09/11/2018 14:06, Jakub Wilk wrote:
* Jonny Grant <jg@xxxxxxxx>, 2018-11-09, 11:52:
Should these say "NUL-terminated" and "NULL" below?
[...]
So the updated line would be:

argument is an array of pointers to NUL-terminated strings and must be
terminated by a NULL pointer.

No, this would be against conventions documented in man-pages(7):

The preferred term for the pointer is "null pointer" or simply "NULL";
avoid writing "NULL pointer".

The preferred term for the byte is "null byte". Avoid writing "NUL",
since it is too easily confused with "NULL". Avoid also the terms "zero
byte" and "null character". The byte that terminates a C string should
be described as "the terminating null byte"; strings may be described as
"null‐terminated", but avoid the use of "NUL‐terminated".


Thank you for the information Jakub. It looks like the terminology is
documented, so at least man-pages are consistent.

Thanks Jakub, for jumping in.
althouh other pages use longer text, eg

http://man7.org/linux/man-pages/man3/strcat.3.html

"terminating null byte ('\0')"

Worth making them all "null byte" ?

I don't think so. "Terminating" is being used explicitly do
indicate that this is the null byte at the end of a string.

This is the same:
http://man7.org/linux/man-pages/man3/strncpy.3.html

It is a shame as ASCII has always called it NUL.
https://en.wikipedia.org/wiki/ASCII

The same in IEC 646
https://en.wikipedia.org/wiki/ISO/IEC_646

I've not felt confusion about a NULL pointer and a NUL byte myself, but
the names are similar, and usage has overlapped, and not consistently
stuck to using NUL.

You may not be confused, but it is a point of confusion for some
people. Best to remove the possibility of confusion, in my opinion,
and that is what I did back in 2006 with this commit:

commit 28d88c175143bdbc136bab4e30dd9f8d7299584b
Author: Michael Kerrisk <mtk.manpages@xxxxxxxxx>
Date:   Fri Jan 13 02:09:44 2006 +0000

     Global change to many pages...
     Various pages use inconsistent terms for 'null byte' (which
     is the C99/SUSv3 term for the '\0' character).
     To rectify this the following changes were made in these pages:
     Replace 'zero byte' with 'null byte'.
     Replace 'null character' with 'null byte'.
     Replace 'nulls' with 'null bytes'.
     Replace 'NUL-terminated' by 'null-terminated'.
     Replace 'NUL' by 'null byte'.
     Replace 'terminating NUL' by 'terminating null byte'.
     Replace 'final NUL' by 'terminating null byte'.
     Replace 'NUL character' by 'null byte'.

As you can see, there was a mass of varying terminology.
I tried to reduce that range of terminology, and move more
closely to the terms used in the standards.



Ref 1:
https://en.wikipedia.org/wiki/Null-terminated_string


Ref 2:
Plenty of NUL use:

"C designer Dennis Ritchie chose to follow the convention of NUL-termination, already established in BCPL, to avoid the limitation on the length of a string and because maintaining the count seemed, in his experience, less convenient than using a terminator."


Ref 3:
glibc  wchar.h refers to "NUL wide character", and a function wcschrnul() is there too
/usr/include/wchar.h


Ref 4 POSIX:
POSIX strcpy()
http://pubs.opengroup.org/onlinepubs/9699919799/functions/strcpy.html

"including the terminating NUL character"


Ref 5 glibc:
https://www.gnu.org/software/libc/manual/html_node/Converting-Strings.html

It has various uses of "NUL", rather than "null" for the NUL ASCII character.

ie
"terminating NUL byte"
"NUL wide character at the end"

There is a risk the man-pages may actually increase confusion, I can see a programmer might mistakenly believe a char* could be terminated by str[0] = NULL;


Ref 6:
Apple developer strcpy() man page

https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/strcpy.3.html

Ref 7:
BSD man page of strcpy()



Re not writing "NULL pointer", it seems odd as the byte preferred term
is "null byte". You'll no doubt be aware that C++ has nullptr keyword,
so it's conventionally known as a pointer. The C spec calls it the "null
pointer".

Yes, but to me "NULL" is "the null pointer", and thus "NULL pointer"
reads to me as "the null pointer pointer" :-).

Ref 8:
yes, I agree that if NULL is a void* pointer, however, convention is more along the lines of calling it the NULL pointer. Both Brian W. Kernighan and Dennis M. Ritchie call it a "null pointer" in this book

http://www.skiesanduniverses.org/resources/The_C_Programming_Language.pdf

Ref9:
The C99 spec refers to it as "null pointer" consistently throughout:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf

Ref 10:
Likewise POSIX refers to "null pointer" consistently throughout:

http://pubs.opengroup.org/onlinepubs/009604599/functions/opendir.html


Ref 11:
It does seem to be generally known as "null pointer"

https://en.wikipedia.org/wiki/Null_pointer#The_null_pointer

Ref 12:
There are many reputable articles

https://queue.acm.org/detail.cfm?id=2010365


Therefore, based on this, I would ask to reconsider, and propose to align with POSIX and the specs.

* NUL terminator - for strings
* NULL pointer (or null pointer) for NULL

BSD man strcpy also uses NUL saw today

https://www.freebsd.org/cgi/man.cgi?query=strcpy&apropos=0&sektion=3&manpath=FreeBSD+11.2-RELEASE+and+Ports&arch=default&format=html


Jonny



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux