Re: Man Page strncpy: Misleading word.

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

 



* Robin Kuzmin <kuzmin.robin@xxxxxxxxx>, 2018-07-11, 09:56:
I see:
The strncpy() function is similar, except that at most n **bytes** of src are copied
I expected:
The strncpy() function is similar, except that at most n **characters** of src are copied

The difference is important because if the `char` size (in bytes) is different from 1 byte on some implementation then "the number of characters" and "the number of bytes" are different.

This is a common misconception about the C language. No, the size of char is always exactly one byte. (Now, that byte might be wider than 8 bits the people are used to, but that's a different story...)

The confirmation to my words is in C99:
7.21.2.4 The strncpy function
The strncpy function copies not more than n **characters** ...

In C99, "character" is another name for "single-byte character".

On the other hand, in POSIX lingo, "character" means multi-byte character.

POSIX uses the term "byte" in their definitions of strncpy and similar functions, which is compatible with C99 and unambiguous. Linux man pages should do the same.

--
Jakub Wilk
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[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