mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-03 11:12:27 +00:00
Perform inconsequential code cleanup
This commit is contained in:
parent
929478c524
commit
decf216655
52 changed files with 326 additions and 442 deletions
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
|
@ -24,16 +25,21 @@
|
|||
* 1. If SRC is too long, it's truncated and *not* NUL-terminated.
|
||||
* 2. If SRC is too short, the remainder is zero-filled.
|
||||
*
|
||||
* @return dest
|
||||
* @see stpncpy(), memccpy()
|
||||
* @param dst is output buffer
|
||||
* @param src is a nul-terminated string
|
||||
* @param dstlen is size of `dst` buffer
|
||||
* @return dst
|
||||
* @asyncsignalsafe
|
||||
* @vforksafe
|
||||
* @see stpncpy()
|
||||
* @see strlcpy()
|
||||
* @see memccpy()
|
||||
*/
|
||||
char *strncpy(char *dest, const char *src, size_t stride) {
|
||||
size_t i;
|
||||
for (i = 0; i < stride; ++i) {
|
||||
if (!(dest[i] = src[i])) break;
|
||||
}
|
||||
bzero(dest + i, stride - i);
|
||||
return dest;
|
||||
char *strncpy(char *dst, const char *src, size_t dstlen) {
|
||||
size_t srclen, cpylen, zerlen;
|
||||
srclen = strlen(src);
|
||||
cpylen = MIN(srclen, dstlen);
|
||||
if (cpylen) memcpy(dst, src, cpylen);
|
||||
zerlen = dstlen - cpylen;
|
||||
if (zerlen) bzero(dst + cpylen, zerlen);
|
||||
return dst;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue