Perform inconsequential code cleanup

This commit is contained in:
Justine Tunney 2023-08-07 20:22:49 -07:00
parent 929478c524
commit decf216655
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
52 changed files with 326 additions and 442 deletions

View file

@ -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;
}