mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 16:28:30 +00:00
Brush up some more code
This commit is contained in:
parent
ee6566a152
commit
a2d269dc38
32 changed files with 251 additions and 335 deletions
|
@ -24,39 +24,6 @@
|
|||
* 1. If SRC is too long, it's truncated and *not* NUL-terminated.
|
||||
* 2. If SRC is too short, the remainder is zero-filled.
|
||||
*
|
||||
* Please note this function isn't designed to prevent untrustworthy
|
||||
* data from modifying memory without authorization; the memccpy()
|
||||
* function can be used for that purpose.
|
||||
*
|
||||
* Here's an example of the only use case we know of for strncpy:
|
||||
*
|
||||
* static const struct People {
|
||||
* char name[8];
|
||||
* int age;
|
||||
* } kPeople[] = {
|
||||
* {"alice", 29}, //
|
||||
* {"bob", 42}, //
|
||||
* };
|
||||
*
|
||||
* int GetAge(const char *name) {
|
||||
* char k[8];
|
||||
* int m, l, r;
|
||||
* l = 0;
|
||||
* r = ARRAYLEN(kPeople) - 1;
|
||||
* strncpy(k, name, 8);
|
||||
* while (l <= r) {
|
||||
* m = (l + r) >> 1;
|
||||
* if (READ64BE(kPeople[m].name) < READ64BE(k)) {
|
||||
* l = m + 1;
|
||||
* } else if (READ64BE(kPeople[m].name) > READ64BE(k)) {
|
||||
* r = m - 1;
|
||||
* } else {
|
||||
* return kPeople[m].age;
|
||||
* }
|
||||
* }
|
||||
* return -1;
|
||||
* }
|
||||
*
|
||||
* @return dest
|
||||
* @see stpncpy(), memccpy()
|
||||
* @asyncsignalsafe
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue