Make minor improvements

This commit is contained in:
Justine Tunney 2020-12-19 11:21:04 -08:00
parent 1fc91f3580
commit b562d6fdb3
41 changed files with 1948 additions and 92 deletions

View file

@ -238,9 +238,6 @@ char *strsignal(int) returnsnonnull libcesque;
*/
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
char *__strncpy(char *, const char *, size_t) memcpyesque;
#define strncpy(DEST, SRC, N) __strncpy(DEST, SRC, N) /* pacify bad warning */
#define explicit_bzero(STR, BYTES) \
do { \
void *Str; \

View file

@ -33,10 +33,11 @@
* @see stpncpy(), memccpy()
* @asyncsignalsafe
*/
char *(strncpy)(char *dest, const char *src, size_t stride) {
char *p;
if ((p = memccpy(dest, src, '\0', stride))) {
memset(p, 0, dest + stride - p);
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;
}
memset(dest + i, 0, stride - i);
return dest;
}

View file

@ -1,24 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
__strncpy:
jmp strncpy
.endfn __strncpy,globl

View file

@ -19,6 +19,9 @@
*/
#include "libc/str/str.h"
/**
* Converts character to lower case.
*/
int tolower(int c) {
return 'A' <= c && c <= 'Z' ? c + ('a' - 'A') : c;
}

View file

@ -19,6 +19,9 @@
*/
#include "libc/str/str.h"
/**
* Converts character to upper case.
*/
int toupper(int c) {
return 'a' <= c && c <= 'z' ? c - ('a' - 'A') : c;
}

View file

@ -19,6 +19,9 @@
*/
#include "libc/str/str.h"
/**
* Converts wide character to lower case.
*/
wint_t towlower(wint_t wc) {
return tolower(wc);
}

View file

@ -19,6 +19,9 @@
*/
#include "libc/str/str.h"
/**
* Converts wide character to upper case.
*/
wint_t towupper(wint_t wc) {
return toupper(wc);
}

View file

@ -31,6 +31,6 @@ int wcscasecmp(const wchar_t *a, const wchar_t *b) {
size_t i = 0;
unsigned x, y;
if (a == b) return 0;
while ((x = tolower(a[i])) == (y = tolower(b[i])) && b[i]) ++i;
while ((x = towlower(a[i])) == (y = towlower(b[i])) && b[i]) ++i;
return x - y;
}