Make minor improvements

This commit is contained in:
Justine Tunney 2020-12-23 23:42:56 -08:00
parent 04caf6f9ad
commit 95b142e4e5
95 changed files with 3818 additions and 2760 deletions

View file

@ -19,7 +19,6 @@ long labs(long) libcesque pureconst;
long long llabs(long long) libcesque pureconst;
char *ltpcpy(char *, long) paramsnonnull() libcesque nocallback;
int llog10(unsigned long) libcesque pureconst;
int unsleb128(const void *, size_t, int64_t *);
int atoi(const char *) paramsnonnull() libcesque;
long atol(const char *) paramsnonnull() libcesque;
long long atoll(const char *) paramsnonnull() libcesque;

View file

@ -22,6 +22,10 @@
#define ISDELIM(c) (c == '/' || c == '\\' || c == '.')
/**
* Returns directory portion of path.
* @param s is mutated
*/
char *dirname(char *s) {
size_t i, n;
if (!(n = strlen(s))) return s;

11
libc/fmt/leb128.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef COSMOPOLITAN_LIBC_FMT_LEB128_H_
#define COSMOPOLITAN_LIBC_FMT_LEB128_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int sleb128(const void *, size_t, int128_t);
int unsleb128(const void *, size_t, int128_t *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_FMT_LEB128_H_ */

View file

@ -46,7 +46,7 @@
#define ___PFLINK(FMT, FN, C) 1
#else
#define ___PFLINK(FMT, FN, C) \
!isconstant(FMT) || ((FMT) && __builtin_##FN(FMT, C) != NULL)
!__builtin_constant_p(FMT) || ((FMT) && __builtin_##FN(FMT, C) != NULL)
#endif
#if defined(__GNUC__) && __GNUC__ < 6

39
libc/fmt/sleb128.c Normal file
View file

@ -0,0 +1,39 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 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/fmt/leb128.h"
/**
* Encodes sleb-128 signed integer.
*/
int sleb128(const void *buf, size_t size, int128_t x) {
int c;
unsigned i;
for (i = 0; i < size; ++i) {
c = x & 0x7f;
x >>= 7;
if ((x == 0 && !(c & 0x40)) || (x == -1 && (c & 0x40))) {
break;
} else {
c |= 0x80;
}
((char *)buf)[i] = c;
}
return i;
}

View file

@ -24,7 +24,7 @@
* @see strerror_r()
*/
char *strerror(int err) {
alignas(1) static char buf[512];
_Alignas(1) static char buf[512];
strerror_r(err, buf, sizeof(buf));
return buf;
}

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/fmt/conv.h"
#include "libc/fmt/leb128.h"
/**
* Decodes a GNU-style varint from a buffer.
@ -25,9 +25,9 @@
* The GNU Assembler is able to encode numbers this way, since it's used
* by the DWARF debug format.
*/
int unsleb128(const void *buf, size_t size, int64_t *out) {
int unsleb128(const void *buf, size_t size, int128_t *out) {
int b;
int64_t r, w;
int128_t r, w;
unsigned char c;
const unsigned char *p, *pe;
pe = (p = buf) + size;