mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Fix warnings
This change fixes Cosmopolitan so it has fewer opinions about compiler warnings. The whole repository had to be cleaned up to be buildable in -Werror -Wall mode. This lets us benefit from things like strict const checking. Some actual bugs might have been caught too.
This commit is contained in:
parent
e2b3c3618e
commit
0d748ad58e
571 changed files with 1306 additions and 1888 deletions
|
@ -5,7 +5,7 @@ COSMOPOLITAN_C_START_
|
|||
|
||||
__funline unsigned char C121(unsigned char al, unsigned char bl,
|
||||
unsigned char cl) {
|
||||
unsigned short ax, bx;
|
||||
unsigned short ax;
|
||||
ax = al;
|
||||
ax += bl;
|
||||
ax += bl;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
__funline signed char C121S(signed char al, signed char bl, signed char cl) {
|
||||
short ax, bx;
|
||||
short ax;
|
||||
ax = al;
|
||||
ax += bl;
|
||||
ax += bl;
|
||||
|
|
|
@ -31,13 +31,14 @@
|
|||
* @param y needs to be 16-byte aligned
|
||||
*/
|
||||
void sad16x8n(size_t n, short x[n][8], const short y[n][8]) {
|
||||
size_t i, j;
|
||||
size_t i;
|
||||
for (i = 0; i < n; ++i) {
|
||||
#ifdef __x86_64__
|
||||
*(__m128i *)x[i] = _mm_adds_epi16(*(__m128i *)x[i], *(__m128i *)y[i]);
|
||||
#elif defined(__aarch64__)
|
||||
*(int16x4_t *)x[i] = vqadd_s16(*(int16x4_t *)x[i], *(int16x4_t *)y[i]);
|
||||
#else
|
||||
size_t j;
|
||||
for (j = 0; j < 8; ++j) {
|
||||
x[i][j] = MIN(MAX(x[i][j] + y[i][j], INT16_MIN), INT16_MAX);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
* @note discovered by Nasir Ahmed
|
||||
*/
|
||||
void plm_video_idct(int block[8][8]) {
|
||||
int i, j, t1, t2, m0;
|
||||
int i, t1, t2, m0;
|
||||
int b1, b3, b4, b6, b7;
|
||||
int y3, y4, y5, y6, y7;
|
||||
int x0, x1, x2, x3, x4;
|
||||
|
|
|
@ -1105,12 +1105,12 @@ plm_video_t *plm_video_create_with_buffer(plm_buffer_t *buffer,
|
|||
|
||||
static textstartup void plm_video_init(void) {
|
||||
PLM_VIDEO_MACROBLOCK_TYPE[0] = NULL;
|
||||
PLM_VIDEO_MACROBLOCK_TYPE[1] = PLM_VIDEO_MACROBLOCK_TYPE_INTRA;
|
||||
PLM_VIDEO_MACROBLOCK_TYPE[2] = PLM_VIDEO_MACROBLOCK_TYPE_PREDICTIVE,
|
||||
PLM_VIDEO_MACROBLOCK_TYPE[3] = PLM_VIDEO_MACROBLOCK_TYPE_B;
|
||||
PLM_VIDEO_DCT_SIZE[0] = PLM_VIDEO_DCT_SIZE_LUMINANCE;
|
||||
PLM_VIDEO_DCT_SIZE[1] = PLM_VIDEO_DCT_SIZE_CHROMINANCE;
|
||||
PLM_VIDEO_DCT_SIZE[2] = PLM_VIDEO_DCT_SIZE_CHROMINANCE;
|
||||
PLM_VIDEO_MACROBLOCK_TYPE[1] = (void *)PLM_VIDEO_MACROBLOCK_TYPE_INTRA;
|
||||
PLM_VIDEO_MACROBLOCK_TYPE[2] = (void *)PLM_VIDEO_MACROBLOCK_TYPE_PREDICTIVE;
|
||||
PLM_VIDEO_MACROBLOCK_TYPE[3] = (void *)PLM_VIDEO_MACROBLOCK_TYPE_B;
|
||||
PLM_VIDEO_DCT_SIZE[0] = (void *)PLM_VIDEO_DCT_SIZE_LUMINANCE;
|
||||
PLM_VIDEO_DCT_SIZE[1] = (void *)PLM_VIDEO_DCT_SIZE_CHROMINANCE;
|
||||
PLM_VIDEO_DCT_SIZE[2] = (void *)PLM_VIDEO_DCT_SIZE_CHROMINANCE;
|
||||
}
|
||||
|
||||
const void *const plm_video_init_ctor[] initarray = {plm_video_init};
|
||||
|
|
|
@ -55,10 +55,10 @@ void *cDecimate2xUint8x8(unsigned long n, unsigned char A[n],
|
|||
K[4], K[5], K[4], K[5], K[4], K[5], K[4], K[5]};
|
||||
signed char kMadd4[16] = {K[6], K[7], K[6], K[7], K[6], K[7], K[6], K[7],
|
||||
K[6], K[7], K[6], K[7], K[6], K[7], K[6], K[7]};
|
||||
unsigned char in1[16], in2[16], in3[16], in4[32];
|
||||
unsigned char bv0[16], bv1[16], bv2[16], bv3[16];
|
||||
unsigned char in1[16], in2[16], in3[16];
|
||||
short wv0[8], wv1[8], wv2[8], wv3[8];
|
||||
unsigned long i, j, v, w, o;
|
||||
unsigned long i, j, w;
|
||||
if (n >= STRIDE) {
|
||||
i = 0;
|
||||
w = (n + RATIO / 2) / RATIO;
|
||||
|
|
|
@ -82,7 +82,6 @@ static bool IsNormalized(int n, double A[n]) {
|
|||
}
|
||||
|
||||
void FreeSamplingSolution(struct SamplingSolution *ss) {
|
||||
long i;
|
||||
if (ss) {
|
||||
free(ss->indices);
|
||||
free(ss->weights);
|
||||
|
@ -93,7 +92,7 @@ void FreeSamplingSolution(struct SamplingSolution *ss) {
|
|||
struct SamplingSolution *ComputeSamplingSolution(long dn, long sn, double dar,
|
||||
double off, double par) {
|
||||
double *fweights;
|
||||
double sum, hw, w, x, f;
|
||||
double sum, hw, x, f;
|
||||
short *weights, *indices;
|
||||
struct SamplingSolution *res;
|
||||
long j, i, k, n, min, max, s, N[6];
|
||||
|
@ -151,8 +150,8 @@ static void GyaradosImpl(long dyw, long dxw, int dst[dyw][dxw], long syw,
|
|||
const short fyi[dyn][yfn], const short fyw[dyn][yfn],
|
||||
const short fxi[dxn][xfn], const short fxw[dxn][xfn],
|
||||
bool sharpen) {
|
||||
long i, j;
|
||||
int eax, dy, dx, sy, sx;
|
||||
long i;
|
||||
int eax, dy, dx, sx;
|
||||
for (sx = 0; sx < sxn; ++sx) {
|
||||
for (dy = 0; dy < dyn; ++dy) {
|
||||
for (eax = i = 0; i < yfn; ++i) {
|
||||
|
|
|
@ -98,8 +98,8 @@ static int uncube(int x) {
|
|||
}
|
||||
|
||||
static textstartup void rgb2ansi_init(void) {
|
||||
uint8_t c, y;
|
||||
uint32_t i, j;
|
||||
uint8_t c;
|
||||
uint32_t i;
|
||||
memcpy(g_ansi2rgb_, &kCgaPalette, sizeof(kCgaPalette));
|
||||
for (i = 16; i < 232; ++i) {
|
||||
g_ansi2rgb_[i].r = kXtermCube[((i - 020) / 044) % 06];
|
||||
|
|
|
@ -609,7 +609,7 @@ static struct Pick PickBlockUnicodeAnsi(struct TtyRgb tl, struct TtyRgb tr,
|
|||
struct TtyRgb tr2 = GetQuant(tr);
|
||||
struct TtyRgb bl2 = GetQuant(bl);
|
||||
struct TtyRgb br2 = GetQuant(br);
|
||||
unsigned i, p1, p2;
|
||||
unsigned p1, p2;
|
||||
uint16_t picks1[96] forcealign(32);
|
||||
uint16_t picks2[32] forcealign(32);
|
||||
memset(picks1, 0x79, sizeof(picks1));
|
||||
|
@ -646,7 +646,7 @@ static struct Pick PickBlockCp437Ansi(struct TtyRgb tl, struct TtyRgb tr,
|
|||
struct TtyRgb tr2 = GetQuant(tr);
|
||||
struct TtyRgb bl2 = GetQuant(bl);
|
||||
struct TtyRgb br2 = GetQuant(br);
|
||||
unsigned i, p1, p2;
|
||||
unsigned p1, p2;
|
||||
uint16_t picks1[32] forcealign(32);
|
||||
uint16_t picks2[32] forcealign(32);
|
||||
memset(picks1, 0x79, sizeof(picks1));
|
||||
|
@ -660,7 +660,6 @@ static struct Pick PickBlockCp437Ansi(struct TtyRgb tl, struct TtyRgb tr,
|
|||
|
||||
static struct Pick PickBlockCp437True(struct TtyRgb tl, struct TtyRgb tr,
|
||||
struct TtyRgb bl, struct TtyRgb br) {
|
||||
unsigned i;
|
||||
uint16_t picks[32] forcealign(32);
|
||||
memset(picks, 0x79, sizeof(picks));
|
||||
PickCp437(picks, tl, tr, bl, br, tl, tr, bl, br);
|
||||
|
|
|
@ -38,8 +38,8 @@
|
|||
* @return 0 on success, or -1 w/ errno
|
||||
*/
|
||||
ssize_t ttywrite(int fd, const void *data, size_t size) {
|
||||
char *p;
|
||||
ssize_t rc;
|
||||
const char *p;
|
||||
size_t wrote, n;
|
||||
p = data;
|
||||
n = size;
|
||||
|
|
|
@ -93,10 +93,8 @@ static void CompleteFilename(const char *p, const char *q, const char *b,
|
|||
}
|
||||
|
||||
static void ShellCompletion(const char *p, linenoiseCompletions *c) {
|
||||
bool slashed;
|
||||
const char *q, *b;
|
||||
for (slashed = false, b = p, q = (p += strlen(p)); p > b; --p) {
|
||||
if (p[-1] == '/' && p[-1] == '\\') slashed = true;
|
||||
for (b = p, q = (p += strlen(p)); p > b; --p) {
|
||||
if (!isalnum(p[-1]) &&
|
||||
(p[-1] != '.' && p[-1] != '_' && p[-1] != '-' && p[-1] != '+' &&
|
||||
p[-1] != '[' && p[-1] != '/' && p[-1] != '\\')) {
|
||||
|
@ -143,8 +141,8 @@ int main(int argc, char *argv[]) {
|
|||
char *prog, path[PATH_MAX];
|
||||
sigset_t chldmask, savemask;
|
||||
int stdoutflags, stderrflags;
|
||||
int n, rc, ws, child, killcount;
|
||||
const char *stdoutpath, *stderrpath;
|
||||
int n, rc, ws, pid, child, killcount;
|
||||
struct sigaction sa, saveint, savequit;
|
||||
char *p, *line, **args, *arg, *start, *state, prompt[1024];
|
||||
linenoiseSetFreeHintsCallback(free);
|
||||
|
|
|
@ -36,6 +36,7 @@ dontubsan int main(int argc, char *argv[]) {
|
|||
volatile double a = 0;
|
||||
volatile double b = 23;
|
||||
volatile double c = exp(b) / a;
|
||||
(void)c;
|
||||
|
||||
volatile int64_t x;
|
||||
return 1 / (x = 0);
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
*/
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
volatile int64_t x;
|
||||
ShowCrashReports();
|
||||
printf("please press ctrl+\\ and see what happens...\n");
|
||||
sigsuspend(0);
|
||||
|
|
|
@ -35,8 +35,7 @@ void PrintUsage(int rc, FILE *f) {
|
|||
|
||||
void PrintUri(const char *path) {
|
||||
size_t n;
|
||||
void *img, *src, *mime;
|
||||
int opt, i;
|
||||
void *img;
|
||||
if (!(img = gc(xslurp(path, &n)))) exit(2);
|
||||
fputs("data:", stdout);
|
||||
fputs(FindContentType(path, -1), stdout);
|
||||
|
|
|
@ -7,15 +7,15 @@
|
|||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
* Cosmopolitan C is just as awesome as Go!
|
||||
* Example contributed by @Keithcat1 (#266)
|
||||
*/
|
||||
main() {
|
||||
int main() {
|
||||
_defer(printf, "Done!\n");
|
||||
for (long i = 0; i < 100000; i++) {
|
||||
printf("%i ", i);
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "libc/stdio/stdio.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int pid;
|
||||
if (argc < 3) {
|
||||
fputs("USAGE: FORKEXEC.COM PROG ARGV₀ [ARGV₁...]\n", stderr);
|
||||
return 1;
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
#include "libc/stdio/stdio.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int pid;
|
||||
volatile void *p;
|
||||
if (argc < 3) {
|
||||
fputs("USAGE: FORKEXECWAIT.COM PROG ARGV₀ [ARGV₁...]\n", stderr);
|
||||
return 1;
|
||||
|
|
|
@ -21,7 +21,7 @@ int main(int argc, char *argv[]) {
|
|||
struct tm tm;
|
||||
struct timeval tv;
|
||||
rc = gettimeofday(&tv, 0);
|
||||
assert(!rc);
|
||||
unassert(!rc);
|
||||
t = tv.tv_sec;
|
||||
gmtime_r(&t, &tm);
|
||||
FormatHttpDateTime(p, &tm);
|
||||
|
|
|
@ -148,14 +148,13 @@ void *Worker(void *id) {
|
|||
while (!closingtime) {
|
||||
struct tm tm;
|
||||
int64_t unixts;
|
||||
struct Url url;
|
||||
ssize_t got, sent;
|
||||
struct timespec ts;
|
||||
struct HttpMessage msg;
|
||||
uint32_t clientaddrsize;
|
||||
struct sockaddr_in clientaddr;
|
||||
char inbuf[1500], outbuf[512], *p, *q;
|
||||
int clientip, client, inmsglen, outmsglen;
|
||||
int client, inmsglen, outmsglen;
|
||||
|
||||
// this slows the server down a lot but is needed on non-Linux to
|
||||
// react to keyboard ctrl-c
|
||||
|
|
|
@ -38,8 +38,8 @@
|
|||
*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/time/time.h"
|
||||
|
@ -178,8 +178,7 @@ void youwon()
|
|||
printf("you win, the word is %s\n",realword);
|
||||
}
|
||||
|
||||
main(argc,argv)
|
||||
char **argv;
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
if(argc==1) dictfile=DICT;
|
||||
else dictfile=argv[1];
|
||||
|
|
|
@ -24,7 +24,7 @@ int main(int argc, char *argv[]) {
|
|||
luaL_openlibs(L);
|
||||
lua_pushcfunction(L, NativeAdd);
|
||||
lua_setglobal(L, "NativeAdd");
|
||||
luaL_dofile(L, "/zip/examples/hellolua.lua");
|
||||
(void)luaL_dofile(L, "/zip/examples/hellolua.lua");
|
||||
lua_close(L);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -44,14 +44,14 @@ void PrintUsage(int rc, FILE *f) {
|
|||
|
||||
void PrintImg(const char *path) {
|
||||
size_t n;
|
||||
int opt, i, yn, xn, cn, w, h;
|
||||
void *img, *pix, *src, *mime;
|
||||
int yn, xn, cn, w, h;
|
||||
void *img, *pix, *src;
|
||||
if (!(img = _gc(xslurp(path, &n)))) exit(2);
|
||||
if (!(pix = _gc(stbi_load_from_memory(img, n, &xn, &yn, &cn, 0)))) exit(3);
|
||||
if (linktag) {
|
||||
printf("<a href=\"%s\"\n >", path);
|
||||
}
|
||||
src = path;
|
||||
src = (void *)path;
|
||||
if (datauri) {
|
||||
src = xasprintf("data:%s;base64,%s", FindContentType(path, -1),
|
||||
_gc(EncodeBase64(img, n, &n)));
|
||||
|
|
|
@ -413,9 +413,9 @@ void editorUpdateSyntax(erow *row) {
|
|||
int i, prev_sep, in_string, in_comment;
|
||||
char *p;
|
||||
const char *const *keywords = E.syntax->keywords;
|
||||
char *scs = E.syntax->singleline_comment_start;
|
||||
char *mcs = E.syntax->multiline_comment_start;
|
||||
char *mce = E.syntax->multiline_comment_end;
|
||||
const char *scs = E.syntax->singleline_comment_start;
|
||||
const char *mcs = E.syntax->multiline_comment_start;
|
||||
const char *mce = E.syntax->multiline_comment_end;
|
||||
|
||||
/* Point to the first non-space char. */
|
||||
p = row->render;
|
||||
|
@ -575,7 +575,7 @@ int editorSyntaxToColor(int hl) {
|
|||
* setting it in the global state E.syntax. */
|
||||
void editorSelectSyntaxHighlight(char *filename) {
|
||||
for (unsigned j = 0; j < HLDB_ENTRIES; j++) {
|
||||
struct editorSyntax *s = HLDB + j;
|
||||
const struct editorSyntax *s = HLDB + j;
|
||||
unsigned i = 0;
|
||||
while (s->filematch[i]) {
|
||||
char *p;
|
||||
|
@ -898,7 +898,7 @@ struct abuf {
|
|||
};
|
||||
|
||||
static void abAppend(struct abuf *ab, const char *s, int len) {
|
||||
CONCAT(&ab->p, &ab->i, &ab->n, s, len);
|
||||
CONCAT(&ab->p, &ab->i, &ab->n, (void *)s, len);
|
||||
}
|
||||
|
||||
/* This function writes the whole screen using VT100 escape characters
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
int main(int argc, char *argv[]) {
|
||||
long i, ns;
|
||||
struct timespec x, y, w;
|
||||
struct timespec x, y;
|
||||
timespec_sleep(timespec_fromnanos(0)); // warmup
|
||||
|
||||
printf("\nrelative sleep\n");
|
||||
|
|
|
@ -45,10 +45,10 @@
|
|||
int main(int argc, char *argv[]) {
|
||||
ssize_t rc;
|
||||
size_t i, got;
|
||||
int opt, sock;
|
||||
char buf[1500];
|
||||
bool halfclose = true;
|
||||
const char *host, *port;
|
||||
int opt, err, toto, sock;
|
||||
struct addrinfo *ai = NULL;
|
||||
struct linger linger = {true, 1};
|
||||
struct pollfd fds[2] = {{-1, POLLIN}, {-1, POLLIN}};
|
||||
|
|
|
@ -164,7 +164,6 @@ static struct TtyRgb* ttyrgb_;
|
|||
static unsigned char *R, *G, *B;
|
||||
static struct ZipGames zipgames_;
|
||||
static struct Action arrow_, button_;
|
||||
static struct SamplingSolution* asx_;
|
||||
static struct SamplingSolution* ssy_;
|
||||
static struct SamplingSolution* ssx_;
|
||||
static unsigned char pixels_[3][DYN][DXN];
|
||||
|
@ -585,7 +584,6 @@ void Raster(void) {
|
|||
f->p = stpcpy(f->p, "\e[0m\e[H");
|
||||
f->p = stpcpy(f->p, status_.text);
|
||||
}
|
||||
CHECK_LT(f->p - f->mem, vtsize_);
|
||||
PollAndSynchronize();
|
||||
}
|
||||
|
||||
|
@ -599,7 +597,6 @@ void FlushScanline(unsigned py) {
|
|||
}
|
||||
|
||||
static void PutPixel(unsigned px, unsigned py, unsigned pixel, int offset) {
|
||||
unsigned rgb;
|
||||
static unsigned prev;
|
||||
pixels_[0][py][px] = palette_[offset][prev % 64][pixel][2];
|
||||
pixels_[1][py][px] = palette_[offset][prev % 64][pixel][1];
|
||||
|
@ -1811,8 +1808,8 @@ void GetOpts(int argc, char* argv[]) {
|
|||
|
||||
size_t FindZipGames(void) {
|
||||
char* name;
|
||||
size_t i, cf;
|
||||
struct Zipos* zipos;
|
||||
size_t i, cf, namesize;
|
||||
if ((zipos = __zipos_get())) {
|
||||
for (i = 0, cf = ZIP_CDIR_OFFSET(zipos->cdir);
|
||||
i < ZIP_CDIR_RECORDS(zipos->cdir);
|
||||
|
@ -1834,14 +1831,14 @@ int SelectGameFromZip(void) {
|
|||
int i, rc;
|
||||
char *line, *uri;
|
||||
fputs("\nCOSMOPOLITAN NESEMU1\n\n", stdout);
|
||||
for (i = 0; i < zipgames_.i; ++i) {
|
||||
for (i = 0; i < (int)zipgames_.i; ++i) {
|
||||
printf(" [%d] %s\n", i, zipgames_.p[i]);
|
||||
}
|
||||
fputs("\nPlease choose a game (or CTRL-C to quit) [default 0]: ", stdout);
|
||||
fflush(stdout);
|
||||
rc = 0;
|
||||
if ((line = GetLine())) {
|
||||
i = MAX(0, MIN(zipgames_.i - 1, atoi(line)));
|
||||
i = MAX(0, MIN((int)zipgames_.i - 1, atoi(line)));
|
||||
uri = zipgames_.p[i];
|
||||
rc = PlayGame(uri, NULL);
|
||||
free(uri);
|
||||
|
|
|
@ -122,7 +122,7 @@ void Clear(void) {
|
|||
}
|
||||
|
||||
void Layout(void) {
|
||||
long i, j;
|
||||
long i;
|
||||
i = txn >> 1;
|
||||
pan.left.top = 0;
|
||||
pan.left.left = 0;
|
||||
|
|
|
@ -113,9 +113,9 @@ main(int argc, char *argv[])
|
|||
static char obuf[BUFSIZ];
|
||||
static char ibuf[BUFSIZ];
|
||||
fd_set rfd;
|
||||
int fm_fd;
|
||||
int aflg, Fflg, kflg, pflg, ch, k, n;
|
||||
int flushtime, readstdin;
|
||||
int fm_fd, fm_log;
|
||||
|
||||
aflg = Fflg = kflg = pflg = 0;
|
||||
usesleep = 1;
|
||||
|
@ -125,6 +125,8 @@ main(int argc, char *argv[])
|
|||
warning. (not needed w/clang) */
|
||||
showexit = 0;
|
||||
|
||||
(void)fm_fd;
|
||||
|
||||
while ((ch = getopt(argc, argv, "adeFfkpqrt:")) != -1)
|
||||
switch(ch) {
|
||||
case 'a':
|
||||
|
|
|
@ -1026,7 +1026,6 @@ struct t_op {
|
|||
│ cosmopolitan § the unbourne shell » bss ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
static int inter;
|
||||
static char **argptr; /* argument list for builtin commands */
|
||||
static char **gargv;
|
||||
static char **t_wp;
|
||||
|
@ -5747,7 +5746,7 @@ static void CompleteCommand(const char *p, const char *q, const char *b,
|
|||
}
|
||||
closedir(d);
|
||||
}
|
||||
free(path);
|
||||
free((void *)path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5784,7 +5783,6 @@ static void CompleteFilename(const char *p, const char *q, const char *b,
|
|||
static void ShellCompletion(const char *p, linenoiseCompletions *c) {
|
||||
bool slashed;
|
||||
const char *q, *b;
|
||||
struct tblentry **pp, *cmdp;
|
||||
for (slashed = false, b = p, q = (p += strlen(p)); p > b; --p) {
|
||||
if (p[-1] == '/' && p[-1] == '\\') slashed = true;
|
||||
if (!isalnum(p[-1]) &&
|
||||
|
|
|
@ -75,7 +75,6 @@ char *GetHost(void) {
|
|||
}
|
||||
|
||||
char *GetTime(void) {
|
||||
int64_t t;
|
||||
struct tm tm;
|
||||
struct timespec ts;
|
||||
clock_gettime(0, &ts);
|
||||
|
|
|
@ -183,7 +183,7 @@ textwindows bool __sig_handle(int sigops, int sig, int si_code,
|
|||
if (__sig_is_fatal(sig)) {
|
||||
intptr_t hStderr;
|
||||
const char *signame;
|
||||
char *end, sigbuf[15], output[16];
|
||||
char *end, sigbuf[21], output[22];
|
||||
signame = strsignal_r(sig, sigbuf);
|
||||
STRACE("terminating due to uncaught %s", signame);
|
||||
hStderr = GetStdHandle(kNtStdErrorHandle);
|
||||
|
@ -274,7 +274,6 @@ textwindows int __sig_add(int tid, int sig, int si_code) {
|
|||
* @threadsafe
|
||||
*/
|
||||
textwindows bool __sig_check(int sigops) {
|
||||
unsigned rva;
|
||||
bool delivered;
|
||||
struct Signal *sig;
|
||||
delivered = false;
|
||||
|
|
|
@ -37,7 +37,6 @@ static void sys_clock_gettime_mono_init(void) {
|
|||
int sys_clock_gettime_mono(struct timespec *time) {
|
||||
uint64_t nanos;
|
||||
uint64_t cycles;
|
||||
struct timespec res;
|
||||
if (X86_HAVE(INVTSC)) {
|
||||
cosmo_once(&g_mono.once, sys_clock_gettime_mono_init);
|
||||
cycles = rdtsc() - g_mono.base_tick;
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
*/
|
||||
int closefrom(int first) {
|
||||
int rc, err;
|
||||
(void)err;
|
||||
if (first < 0) {
|
||||
// consistent with openbsd
|
||||
// freebsd allows this but it's dangerous
|
||||
|
|
|
@ -39,8 +39,8 @@ static struct CopyFileRange {
|
|||
} g_copy_file_range;
|
||||
|
||||
static bool HasCopyFileRange(void) {
|
||||
int e;
|
||||
bool ok;
|
||||
int e, rc;
|
||||
e = errno;
|
||||
BLOCK_CANCELLATIONS;
|
||||
if (IsLinux()) {
|
||||
|
|
|
@ -43,9 +43,9 @@ int execl(const char *exe, const char *arg, ... /*, NULL*/) {
|
|||
va_end(va);
|
||||
argv = alloca((i + 2) * sizeof(char *));
|
||||
va_start(vb, arg);
|
||||
argv[0] = arg;
|
||||
argv[0] = (char *)arg;
|
||||
for (i = 1;; ++i) {
|
||||
if (!(argv[i] = va_arg(vb, const char *))) break;
|
||||
if (!(argv[i] = va_arg(vb, char *))) break;
|
||||
}
|
||||
va_end(vb);
|
||||
return execv(exe, argv);
|
||||
|
|
|
@ -45,9 +45,9 @@ int execle(const char *exe, const char *arg,
|
|||
va_end(va);
|
||||
argv = alloca((i + 2) * sizeof(char *));
|
||||
va_start(vb, arg);
|
||||
argv[0] = arg;
|
||||
argv[0] = (char *)arg;
|
||||
for (i = 1;; ++i) {
|
||||
if (!(argv[i] = va_arg(vb, const char *))) break;
|
||||
if (!(argv[i] = va_arg(vb, char *))) break;
|
||||
}
|
||||
va_end(vb);
|
||||
return execve(exe, argv, envp);
|
||||
|
|
|
@ -49,9 +49,9 @@ int execlp(const char *prog, const char *arg, ... /*, NULL*/) {
|
|||
va_end(va);
|
||||
argv = alloca((i + 2) * sizeof(char *));
|
||||
va_start(vb, arg);
|
||||
argv[0] = arg;
|
||||
argv[0] = (char *)arg;
|
||||
for (i = 1;; ++i) {
|
||||
if (!(argv[i] = va_arg(vb, const char *))) break;
|
||||
if (!(argv[i] = va_arg(vb, char *))) break;
|
||||
}
|
||||
va_end(vb);
|
||||
|
||||
|
|
|
@ -89,15 +89,15 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
|
|||
".ape-" APE_VERSION_STR, buf))) ||
|
||||
CanExecute((ape = Join(firstnonnull(getenv("HOME"), "."),
|
||||
".ape-" APE_VERSION_STR, buf))))) {
|
||||
shargs[0] = ape;
|
||||
shargs[1] = "-";
|
||||
shargs[2] = prog;
|
||||
shargs[0] = (char *)ape;
|
||||
shargs[1] = (char *)"-";
|
||||
shargs[2] = (char *)prog;
|
||||
memcpy(shargs + 3, argv, (i + 1) * sizeof(char *));
|
||||
errno = e;
|
||||
rc = __sys_execve(shargs[0], shargs, envp);
|
||||
} else if (CanExecute(prog)) {
|
||||
shargs[0] = _PATH_BSHELL;
|
||||
shargs[1] = prog;
|
||||
shargs[1] = (char *)prog;
|
||||
memcpy(shargs + 2, argv + 1, i * sizeof(char *));
|
||||
errno = e;
|
||||
rc = __sys_execve(shargs[0], shargs, envp);
|
||||
|
|
|
@ -56,9 +56,8 @@
|
|||
* @vforksafe
|
||||
*/
|
||||
int execve(const char *prog, char *const argv[], char *const envp[]) {
|
||||
struct ZiposUri uri;
|
||||
int rc;
|
||||
size_t i;
|
||||
struct ZiposUri uri;
|
||||
if (!prog || !argv || !envp ||
|
||||
(IsAsan() && (!__asan_is_valid_str(prog) || //
|
||||
!__asan_is_valid_strlist(argv) || //
|
||||
|
|
|
@ -43,7 +43,7 @@ int sys_fadvise_netbsd(int, int, int64_t, int64_t, int) asm("sys_fadvise");
|
|||
* @raise ENOSYS on XNU and OpenBSD
|
||||
*/
|
||||
int fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
|
||||
int rc, e = errno;
|
||||
int rc;
|
||||
if (IsLinux()) {
|
||||
rc = sys_fadvise(fd, offset, len, advice);
|
||||
} else if (IsFreebsd() || IsNetbsd()) {
|
||||
|
|
|
@ -124,11 +124,10 @@ textwindows void sys_fcntl_nt_lock_cleanup(int fd) {
|
|||
|
||||
static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd,
|
||||
uintptr_t arg) {
|
||||
int e;
|
||||
uint32_t flags;
|
||||
struct flock *l;
|
||||
uint32_t flags, err;
|
||||
int64_t pos, off, len, end;
|
||||
struct FileLock *fl, *ft, **flp;
|
||||
int64_t pos, off, len, end, size;
|
||||
|
||||
l = (struct flock *)arg;
|
||||
len = l->l_len;
|
||||
|
@ -171,7 +170,7 @@ static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd,
|
|||
for (flp = &g_locks.list, fl = *flp; fl;) {
|
||||
if (fl->fd == fd) {
|
||||
if (EqualsFileLock(fl, off, len)) {
|
||||
if (fl->exc == l->l_type == F_WRLCK) {
|
||||
if (fl->exc == (l->l_type == F_WRLCK)) {
|
||||
// we already have this lock
|
||||
return 0;
|
||||
} else {
|
||||
|
@ -205,7 +204,7 @@ static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd,
|
|||
l->l_whence = SEEK_SET;
|
||||
l->l_start = fl->off;
|
||||
l->l_len = fl->len;
|
||||
l->l_type == fl->exc ? F_WRLCK : F_RDLCK;
|
||||
l->l_type = fl->exc ? F_WRLCK : F_RDLCK;
|
||||
l->l_pid = getpid();
|
||||
return 0;
|
||||
}
|
||||
|
@ -360,7 +359,6 @@ static textwindows int sys_fcntl_nt_setfl(int fd, unsigned *flags,
|
|||
|
||||
textwindows int sys_fcntl_nt(int fd, int cmd, uintptr_t arg) {
|
||||
int rc;
|
||||
uint32_t flags;
|
||||
if (__isfdkind(fd, kFdFile) || //
|
||||
__isfdkind(fd, kFdSocket) || //
|
||||
__isfdkind(fd, kFdConsole)) {
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
|
||||
static bool IsAPEFd(const int fd) {
|
||||
char buf[8];
|
||||
bool res;
|
||||
return (sys_pread(fd, buf, 8, 0, 0) == 8) && IsAPEMagic(buf);
|
||||
}
|
||||
|
||||
|
@ -115,7 +114,7 @@ static bool ape_to_elf(void *ape, const size_t apesize) {
|
|||
* This does an inplace conversion of APE to ELF when detected!!!!
|
||||
*/
|
||||
static int fd_to_mem_fd(const int infd, char *path) {
|
||||
if (!IsLinux() && !IsFreebsd() || !_weaken(mmap) || !_weaken(munmap)) {
|
||||
if ((!IsLinux() && !IsFreebsd()) || !_weaken(mmap) || !_weaken(munmap)) {
|
||||
return enosys();
|
||||
}
|
||||
|
||||
|
@ -143,9 +142,9 @@ static int fd_to_mem_fd(const int infd, char *path) {
|
|||
bool success = readRc != -1;
|
||||
if (success && (st.st_size > 8) && IsAPEMagic(space)) {
|
||||
int flags = fcntl(fd, F_GETFD);
|
||||
if (success = (flags != -1) &&
|
||||
(fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC)) != -1) &&
|
||||
ape_to_elf(space, st.st_size)) {
|
||||
if ((success = (flags != -1) &&
|
||||
(fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC)) != -1) &&
|
||||
ape_to_elf(space, st.st_size))) {
|
||||
const int newfd = fcntl(fd, F_DUPFD, 9001);
|
||||
if (newfd != -1) {
|
||||
close(fd);
|
||||
|
@ -232,7 +231,7 @@ int fexecve(int fd, char *const argv[], char *const envp[]) {
|
|||
}
|
||||
size_t numenvs;
|
||||
for (numenvs = 0; envp[numenvs];) ++numenvs;
|
||||
const size_t desenvs = min(500, max(numenvs + 1, 2));
|
||||
// const size_t desenvs = min(500, max(numenvs + 1, 2));
|
||||
static _Thread_local char *envs[500];
|
||||
memcpy(envs, envp, numenvs * sizeof(char *));
|
||||
envs[numenvs] = path;
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
*/
|
||||
int32_t sys_fstatat(int32_t dirfd, const char *path, struct stat *st,
|
||||
int32_t flags) {
|
||||
int rc;
|
||||
void *p;
|
||||
union metastat ms;
|
||||
if (IsAsan() && !__asan_is_valid_str(path)) return efault();
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
textwindows int sys_fstatfs_nt(int64_t handle, struct statfs *f) {
|
||||
uint64_t w;
|
||||
NtStatus st;
|
||||
uint32_t type;
|
||||
uint32_t h, i, j;
|
||||
struct NtIoStatusBlock io;
|
||||
struct NtFileFsFullSizeInformation fs;
|
||||
|
|
|
@ -57,7 +57,6 @@ textwindows int sys_getloadavg_nt(double *a, int n) {
|
|||
}
|
||||
|
||||
static textstartup void sys_getloadavg_nt_init(void) {
|
||||
double a[3];
|
||||
if (IsWindows()) {
|
||||
load = 1;
|
||||
cpus = __get_cpu_count() / 2;
|
||||
|
|
|
@ -55,7 +55,6 @@ static gettimeofday_f *__gettimeofday = __gettimeofday_init;
|
|||
*/
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz) {
|
||||
int rc;
|
||||
axdx_t ad;
|
||||
if (IsAsan() && ((tv && !__asan_is_valid(tv, sizeof(*tv))) ||
|
||||
(tz && !__asan_is_valid(tz, sizeof(*tz))))) {
|
||||
rc = efault();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
COSMOPOLITAN_C_START_
|
||||
|
||||
int sys_getgroups(int size, uint32_t list[]);
|
||||
int sys_setgroups(size_t size, uint32_t list[]);
|
||||
int sys_setgroups(size_t size, const uint32_t list[]);
|
||||
|
||||
const char *DescribeGidList(char[128], int, int, const uint32_t list[]);
|
||||
#define DescribeGidList(rc, length, gidlist) \
|
||||
|
|
|
@ -72,7 +72,6 @@ static struct HostAdapterInfoNode {
|
|||
|
||||
static int ioctl_default(int fd, unsigned long request, void *arg) {
|
||||
int rc;
|
||||
va_list va;
|
||||
int64_t handle;
|
||||
if (!IsWindows()) {
|
||||
return sys_ioctl(fd, request, arg);
|
||||
|
@ -94,7 +93,6 @@ static int ioctl_default(int fd, unsigned long request, void *arg) {
|
|||
|
||||
static int ioctl_fionread(int fd, uint32_t *arg) {
|
||||
int rc;
|
||||
va_list va;
|
||||
int64_t handle;
|
||||
uint32_t avail;
|
||||
if (!IsWindows()) {
|
||||
|
@ -323,7 +321,6 @@ static textwindows int createHostInfo(
|
|||
struct NtIpAdapterPrefix *ap;
|
||||
struct HostAdapterInfoNode *node = NULL;
|
||||
char baseName[IFNAMSIZ];
|
||||
char name[IFNAMSIZ];
|
||||
int count, i;
|
||||
/* __hostInfo must be empty */
|
||||
unassert(__hostInfo == NULL);
|
||||
|
@ -416,7 +413,6 @@ err:
|
|||
|
||||
static textwindows int ioctl_siocgifconf_nt(int fd, struct ifconf *ifc) {
|
||||
struct ifreq *ptr;
|
||||
struct NtIpAdapterAddresses *aa;
|
||||
struct HostAdapterInfoNode *node;
|
||||
if (__hostInfo) {
|
||||
freeHostInfo();
|
||||
|
@ -480,12 +476,12 @@ static int ioctl_siocgifconf_sysv(int fd, struct ifconf *ifc) {
|
|||
* BSD ABIs mainly differ by having sockaddr::sa_len
|
||||
* XNU uses a 32-bit length in a struct that's packed!
|
||||
*/
|
||||
int i, rc, fam;
|
||||
int rc, fam;
|
||||
size_t bufMax;
|
||||
char *b, *p, *e;
|
||||
char ifcBsd[16];
|
||||
struct ifreq *req;
|
||||
uint32_t bufLen, ip;
|
||||
size_t numReq, bufMax;
|
||||
if (IsLinux()) {
|
||||
return sys_ioctl(fd, SIOCGIFCONF, ifc);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
* @raise EPERM if pledge() was used without tty
|
||||
*/
|
||||
bool32 isatty(int fd) {
|
||||
int e;
|
||||
bool32 res;
|
||||
struct winsize ws;
|
||||
if (__isfdkind(fd, kFdZip)) {
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
*/
|
||||
int mkfifo(const char *pathname, unsigned mode) {
|
||||
// TODO(jart): Windows?
|
||||
int e, rc;
|
||||
int rc;
|
||||
if (IsAsan() && !__asan_is_valid_str(pathname)) {
|
||||
rc = efault();
|
||||
} else if (IsLinux()) {
|
||||
|
|
|
@ -71,7 +71,6 @@ textwindows int mkntcmdline(char16_t cmdline[ARG_MAX / 2], char *const argv[]) {
|
|||
wint_t x, y;
|
||||
int slashes, n;
|
||||
bool needsquote;
|
||||
char16_t cbuf[2];
|
||||
char *ansiargv[2];
|
||||
size_t i, j, k, s;
|
||||
if (!argv[0]) {
|
||||
|
|
|
@ -36,9 +36,9 @@ static inline int IsAlpha(int c) {
|
|||
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
|
||||
}
|
||||
|
||||
static inline char *StrChr(char *s, int c) {
|
||||
static inline char *StrChr(const char *s, int c) {
|
||||
for (;; ++s) {
|
||||
if ((*s & 255) == (c & 255)) return s;
|
||||
if ((*s & 255) == (c & 255)) return (char *)s;
|
||||
if (!*s) return 0;
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,6 @@ static textwindows inline int CompareStrings(const char *l, const char *r) {
|
|||
|
||||
static textwindows void FixPath(char *path) {
|
||||
char *p;
|
||||
size_t i;
|
||||
|
||||
// skip over variable name
|
||||
while (*path++) {
|
||||
|
@ -71,7 +70,7 @@ static textwindows void FixPath(char *path) {
|
|||
|
||||
// turn \c\... into c:\...
|
||||
p = path;
|
||||
if ((p[0] == '/' | p[0] == '\\') && IsAlpha(p[1]) &&
|
||||
if ((p[0] == '/' || p[0] == '\\') && IsAlpha(p[1]) &&
|
||||
(p[2] == '/' || p[2] == '\\')) {
|
||||
p[0] = p[1];
|
||||
p[1] = ':';
|
||||
|
@ -92,7 +91,7 @@ static textwindows void FixPath(char *path) {
|
|||
}
|
||||
}
|
||||
|
||||
static textwindows void InsertString(char **a, size_t i, char *s,
|
||||
static textwindows void InsertString(char **a, size_t i, const char *s,
|
||||
char buf[ARG_MAX], size_t *bufi,
|
||||
bool *have_systemroot) {
|
||||
char *v;
|
||||
|
@ -119,7 +118,7 @@ static textwindows void InsertString(char **a, size_t i, char *s,
|
|||
for (j = i; j > 0 && CompareStrings(s, a[j - 1]) < 0; --j) {
|
||||
a[j] = a[j - 1];
|
||||
}
|
||||
a[j] = s;
|
||||
a[j] = (char *)s;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,8 +135,6 @@ static textwindows void InsertString(char **a, size_t i, char *s,
|
|||
textwindows int mkntenvblock(char16_t envvars[ARG_MAX / 2], char *const envp[],
|
||||
const char *extravar, char buf[ARG_MAX]) {
|
||||
bool v;
|
||||
char *t;
|
||||
axdx_t rc;
|
||||
uint64_t w;
|
||||
char **vars;
|
||||
wint_t x, y;
|
||||
|
|
|
@ -25,7 +25,7 @@ int32_t sys_mount_linux(const char *source, const char *target,
|
|||
const char *filesystemtype, uint64_t mountflags,
|
||||
const void *data) asm("sys_mount");
|
||||
int32_t sys_mount_bsd(const char *type, const char *dir, int32_t flags,
|
||||
void *data) asm("sys_mount");
|
||||
const void *data) asm("sys_mount");
|
||||
|
||||
/**
|
||||
* Mounts file system.
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
void *sys_mremap(void *p, size_t n, size_t m, int f, void *q) {
|
||||
#ifdef __x86_64__
|
||||
bool cf;
|
||||
uintptr_t res, rdi, rsi, rdx;
|
||||
uintptr_t res, rdx;
|
||||
register uintptr_t r8 asm("r8");
|
||||
register uintptr_t r10 asm("r10");
|
||||
if (IsLinux()) {
|
||||
|
|
|
@ -102,7 +102,6 @@ static long double nowl_vdso(void) {
|
|||
|
||||
long double nowl_setup(void) {
|
||||
bool isfast;
|
||||
uint64_t ticks;
|
||||
__gettime = __clock_gettime_get(&isfast);
|
||||
if (isfast) {
|
||||
nowl = nowl_vdso;
|
||||
|
|
|
@ -26,13 +26,12 @@
|
|||
#include "libc/sysv/consts/sicode.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/thread/tls.h"
|
||||
#include "libc/thread/tls2.h"
|
||||
#include "libc/thread/tls2.internal.h"
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
||||
textwindows bool32 __onntconsoleevent(uint32_t dwCtrlType) {
|
||||
struct CosmoTib tib;
|
||||
struct StackFrame *fr;
|
||||
|
||||
// win32 spawns a thread on its own just to deliver sigint
|
||||
// TODO(jart): make signal code lockless so we can delete!
|
||||
|
|
|
@ -48,7 +48,7 @@ struct IoctlPtmGet {
|
|||
static int openpty_impl(int *mfd, int *sfd, char *name,
|
||||
const struct termios *tio, //
|
||||
const struct winsize *wsz) {
|
||||
int m, s, p;
|
||||
int m, s;
|
||||
struct IoctlPtmGet t;
|
||||
RETURN_ON_ERROR((m = posix_openpt(O_RDWR | O_NOCTTY)));
|
||||
if (!IsOpenbsd()) {
|
||||
|
@ -66,7 +66,7 @@ static int openpty_impl(int *mfd, int *sfd, char *name,
|
|||
*sfd = s;
|
||||
if (name) strcpy(name, t.sname);
|
||||
if (tio) npassert(!tcsetattr(s, TCSAFLUSH, tio));
|
||||
if (wsz) npassert(!tcgetwinsize(s, wsz));
|
||||
if (wsz) npassert(!tcsetwinsize(s, wsz));
|
||||
return 0;
|
||||
OnError:
|
||||
if (m != -1) sys_close(m);
|
||||
|
|
|
@ -1079,11 +1079,11 @@ static privileged int GetTid(void) {
|
|||
}
|
||||
|
||||
static privileged void Log(const char *s, ...) {
|
||||
int res;
|
||||
va_list va;
|
||||
va_start(va, s);
|
||||
do {
|
||||
#ifdef __x86_64__
|
||||
int res;
|
||||
asm volatile("syscall"
|
||||
: "=a"(res)
|
||||
: "0"(__NR_linux_write), "D"(2), "S"(s), "d"(StrLen(s))
|
||||
|
@ -1156,10 +1156,10 @@ static privileged int SigProcMask(int how, int64_t set, int64_t *old) {
|
|||
}
|
||||
|
||||
static privileged void KillThisProcess(void) {
|
||||
int res;
|
||||
SigAction(Sigabrt, &(struct sigaction){0}, 0);
|
||||
SigProcMask(Sig_Setmask, -1, 0);
|
||||
#ifdef __x86_64__
|
||||
int res;
|
||||
asm volatile("syscall"
|
||||
: "=a"(res)
|
||||
: "0"(__NR_linux_kill), "D"(GetPid()), "S"(Sigabrt)
|
||||
|
@ -1196,10 +1196,10 @@ static privileged void KillThisProcess(void) {
|
|||
}
|
||||
|
||||
static privileged void KillThisThread(void) {
|
||||
int res;
|
||||
SigAction(Sigabrt, &(struct sigaction){0}, 0);
|
||||
SigProcMask(Sig_Setmask, -1, 0);
|
||||
#ifdef __x86_64__
|
||||
int res;
|
||||
asm volatile("syscall"
|
||||
: "=a"(res)
|
||||
: "0"(__NR_linux_tkill), "D"(GetTid()), "S"(Sigabrt)
|
||||
|
@ -1233,7 +1233,7 @@ static privileged const char *GetSyscallName(uint16_t n) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
static privileged int HasSyscall(struct Pledges *p, uint16_t n) {
|
||||
static privileged int HasSyscall(const struct Pledges *p, uint16_t n) {
|
||||
int i;
|
||||
for (i = 0; i < p->len; ++i) {
|
||||
if (p->syscalls[i] == n) {
|
||||
|
@ -1249,11 +1249,11 @@ static privileged int HasSyscall(struct Pledges *p, uint16_t n) {
|
|||
static privileged void OnSigSys(int sig, siginfo_t *si, void *vctx) {
|
||||
bool found;
|
||||
char ord[17];
|
||||
int i, ok, mode = si->si_errno;
|
||||
int i, mode = si->si_errno;
|
||||
ucontext_t *ctx = vctx;
|
||||
ctx->uc_mcontext.MCONTEXT_SYSCALL_RESULT_REGISTER = -Eperm;
|
||||
FixCpy(ord, si->si_syscall, 12);
|
||||
for (found = i = 0; i < ARRAYLEN(kPledge); ++i) {
|
||||
for (found = false, i = 0; i < ARRAYLEN(kPledge); ++i) {
|
||||
if (HasSyscall(kPledge + i, si->si_syscall)) {
|
||||
Log("error: protected syscall ", GetSyscallName(si->si_syscall),
|
||||
" (ord=", ord, "); pledge promise '", kPledge[i].name, "' to allow\n",
|
||||
|
@ -1289,8 +1289,8 @@ static privileged void MonitorSigSys(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static privileged void AppendFilter(struct Filter *f, struct sock_filter *p,
|
||||
size_t n) {
|
||||
static privileged void AppendFilter(struct Filter *f,
|
||||
const struct sock_filter *p, size_t n) {
|
||||
if (UNLIKELY(f->n + n > ARRAYLEN(f->p))) notpossible;
|
||||
MemCpy(f->p + f->n, p, n * sizeof(*f->p));
|
||||
f->n += n;
|
||||
|
@ -2290,8 +2290,8 @@ static privileged void AppendPledge(struct Filter *f, //
|
|||
* @vforksafe
|
||||
*/
|
||||
privileged int sys_pledge_linux(unsigned long ipromises, int mode) {
|
||||
int i, rc = -1;
|
||||
struct Filter f;
|
||||
int i, e, rc = -1;
|
||||
struct sock_filter sf[1] = {BPF_STMT(BPF_RET | BPF_K, 0)};
|
||||
CheckLargeStackAllocation(&f, sizeof(f));
|
||||
f.n = 0;
|
||||
|
|
|
@ -67,7 +67,7 @@ ssize_t pwrite(int fd, const void *buf, size_t size, int64_t offset) {
|
|||
} else if (__isfdkind(fd, kFdSocket)) {
|
||||
rc = espipe();
|
||||
} else if (__isfdkind(fd, kFdFile)) {
|
||||
rc = sys_write_nt(fd, (struct iovec[]){{buf, size}}, 1, offset);
|
||||
rc = sys_write_nt(fd, (struct iovec[]){{(void *)buf, size}}, 1, offset);
|
||||
} else {
|
||||
return ebadf();
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ static dontubsan void RaiseSigFpe(void) {
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
int raise(int sig) {
|
||||
int rc, tid, event;
|
||||
int rc;
|
||||
STRACE("raise(%G) → ...", sig);
|
||||
if (sig == SIGTRAP) {
|
||||
DebugBreak();
|
||||
|
|
|
@ -66,7 +66,6 @@ static textwindows ssize_t sys_read_nt_impl(struct Fd *fd, void *data,
|
|||
int filetype;
|
||||
int64_t handle;
|
||||
uint32_t remain;
|
||||
uint32_t conmode;
|
||||
char *targetdata;
|
||||
uint32_t targetsize;
|
||||
bool is_console_input;
|
||||
|
@ -205,7 +204,6 @@ StartOver:
|
|||
textwindows ssize_t sys_read_nt(struct Fd *fd, const struct iovec *iov,
|
||||
size_t iovlen, int64_t opt_offset) {
|
||||
ssize_t rc;
|
||||
uint32_t size;
|
||||
size_t i, total;
|
||||
if (opt_offset < -1) return einval();
|
||||
if (_check_interrupts(kSigOpRestartable)) return -1;
|
||||
|
|
|
@ -45,7 +45,7 @@ textwindows ssize_t sys_readlinkat_nt(int dirfd, const char *path, char *buf,
|
|||
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
|
||||
mem = 16384;
|
||||
memory = alloca(mem);
|
||||
CheckLargeStackAllocation(memory, mem);
|
||||
CheckLargeStackAllocation((char *)memory, mem);
|
||||
rdb = (struct NtReparseDataBuffer *)memory;
|
||||
if ((h = CreateFile(path16, 0, 0, 0, kNtOpenExisting,
|
||||
kNtFileFlagOpenReparsePoint | kNtFileFlagBackupSemantics,
|
||||
|
|
|
@ -26,7 +26,7 @@ static bool IsDataAvailable(struct Fd *fd) {
|
|||
return inb(fd->handle + UART_LSR) & UART_TTYDA;
|
||||
}
|
||||
|
||||
static int GetFirstIov(struct iovec *iov, int iovlen) {
|
||||
static int GetFirstIov(const struct iovec *iov, int iovlen) {
|
||||
int i;
|
||||
for (i = 0; i < iovlen; ++i) {
|
||||
if (iov[i].iov_len) {
|
||||
|
|
|
@ -39,7 +39,6 @@ static volatile size_t mapsize;
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
int __ensurefds_unlocked(int fd) {
|
||||
bool relocate;
|
||||
if (fd < g_fds.n) return fd;
|
||||
g_fds.n = fd + 1;
|
||||
g_fds.e = _extend(g_fds.p, g_fds.n * sizeof(*g_fds.p), g_fds.e, MAP_PRIVATE,
|
||||
|
|
|
@ -488,7 +488,6 @@ static privileged void linuxssefpustate2xnu(
|
|||
privileged void __sigenter_xnu(void *fn, int infostyle, int sig,
|
||||
struct siginfo_xnu *xnuinfo,
|
||||
struct __darwin_ucontext *xnuctx) {
|
||||
intptr_t ax;
|
||||
int rva, flags;
|
||||
struct Goodies {
|
||||
ucontext_t uc;
|
||||
|
@ -571,6 +570,7 @@ privileged void __sigenter_xnu(void *fn, int infostyle, int sig,
|
|||
}
|
||||
|
||||
#ifdef __x86_64__
|
||||
intptr_t ax;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ax)
|
||||
: "0"(0x20000b8 /* sigreturn */), "D"(xnuctx), "S"(infostyle)
|
||||
|
|
|
@ -50,9 +50,8 @@
|
|||
* @vforksafe
|
||||
*/
|
||||
int sigprocmask(int how, const sigset_t *opt_set, sigset_t *opt_out_oldset) {
|
||||
int res, rc, arg1;
|
||||
int rc;
|
||||
sigset_t old = {0};
|
||||
const sigset_t *arg2;
|
||||
if (IsAsan() &&
|
||||
((opt_set && !__asan_is_valid(opt_set, sizeof(*opt_set))) ||
|
||||
(opt_out_oldset &&
|
||||
|
|
|
@ -47,7 +47,8 @@
|
|||
*/
|
||||
int sigsuspend(const sigset_t *ignore) {
|
||||
int rc;
|
||||
sigset_t save, *arg, mask = {0};
|
||||
const sigset_t *arg;
|
||||
sigset_t save, mask = {0};
|
||||
STRACE("sigsuspend(%s) → ...", DescribeSigset(0, ignore));
|
||||
BEGIN_CANCELLATION_POINT;
|
||||
|
||||
|
|
|
@ -47,10 +47,11 @@
|
|||
int sigtimedwait(const sigset_t *set, siginfo_t *info,
|
||||
const struct timespec *timeout) {
|
||||
int rc;
|
||||
char strsig[15];
|
||||
char strsig[21];
|
||||
struct timespec ts;
|
||||
union siginfo_meta si = {0};
|
||||
BEGIN_CANCELLATION_POINT;
|
||||
(void)strsig;
|
||||
|
||||
if (IsAsan() && (!__asan_is_valid(set, sizeof(*set)) ||
|
||||
(info && !__asan_is_valid(info, sizeof(*info))) ||
|
||||
|
|
|
@ -36,8 +36,8 @@ static struct Splice {
|
|||
} g_splice;
|
||||
|
||||
static bool HasSplice(void) {
|
||||
int e;
|
||||
bool ok;
|
||||
int e, rc;
|
||||
e = errno;
|
||||
if (IsLinux()) {
|
||||
// Our testing indicates splice() doesn't work as documneted on
|
||||
|
|
|
@ -15,7 +15,7 @@ struct sock_filter {
|
|||
|
||||
struct sock_fprog {
|
||||
unsigned short len;
|
||||
struct sock_filter *filter;
|
||||
const struct sock_filter *filter;
|
||||
};
|
||||
|
||||
#define BPF_RVAL(code) ((code)&0x18)
|
||||
|
|
|
@ -21,7 +21,7 @@ ssize_t sys_writev_metal(struct Fd *, const struct iovec *, int);
|
|||
ssize_t sys_writev_nt(int, const struct iovec *, int);
|
||||
ssize_t sys_writev_serial(struct Fd *, const struct iovec *, int);
|
||||
ssize_t sys_send_nt(int, const struct iovec *, size_t, uint32_t);
|
||||
ssize_t sys_sendto_nt(int, const struct iovec *, size_t, uint32_t, void *,
|
||||
ssize_t sys_sendto_nt(int, const struct iovec *, size_t, uint32_t, const void *,
|
||||
uint32_t);
|
||||
|
||||
const char *DescribeIovec(char[300], ssize_t, const struct iovec *, int);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
const char *DescribeTermios(char[1024], ssize_t, struct termios *);
|
||||
const char *DescribeTermios(char[1024], ssize_t, const struct termios *);
|
||||
|
||||
#define DescribeTermios(rc, tio) DescribeTermios(alloca(1024), rc, tio)
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ static inline bool timespec_iszero(struct timespec __ts) {
|
|||
return !(__ts.tv_sec | __ts.tv_nsec);
|
||||
}
|
||||
static inline bool timespec_isvalid(struct timespec __ts) {
|
||||
return __ts.tv_sec >= 0 && __ts.tv_nsec < 1000000000ull;
|
||||
return __ts.tv_sec >= 0 && __ts.tv_nsec + 0ull < 1000000000ull;
|
||||
}
|
||||
#endif /* _COSMO_SOURCE */
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ static inline bool timeval_iszero(struct timeval __tv) {
|
|||
return !(__tv.tv_sec | __tv.tv_usec);
|
||||
}
|
||||
static inline bool timeval_isvalid(struct timeval __tv) {
|
||||
return __tv.tv_sec >= 0 && __tv.tv_usec < 1000000ull;
|
||||
return __tv.tv_sec >= 0 && __tv.tv_usec + 0ull < 1000000ull;
|
||||
}
|
||||
#endif /* _COSMO_SOURCE */
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
COSMOPOLITAN_C_START_
|
||||
|
||||
int tcgetwinsize_nt(int, struct winsize *);
|
||||
const char *DescribeWinsize(char[64], int, struct winsize *);
|
||||
const char *DescribeWinsize(char[64], int, const struct winsize *);
|
||||
#define DescribeWinsize(rc, ws) DescribeWinsize(alloca(64), rc, ws)
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
|
@ -164,7 +164,6 @@ textwindows void __echo_terminal_input(struct Fd *fd, char *p, size_t n) {
|
|||
|
||||
textwindows int tcsetattr_nt(int fd, int opt, const struct termios *tio) {
|
||||
bool32 ok;
|
||||
int infd;
|
||||
int64_t hInput, hOutput;
|
||||
uint32_t inmode, outmode;
|
||||
if (__isfdkind(fd, kFdConsole)) {
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
static textwindows errno_t sys_ttyname_nt(int fd, char *buf, size_t size) {
|
||||
uint32_t mode;
|
||||
const char *s;
|
||||
if (GetConsoleMode(g_fds.p[fd].handle, &mode)) {
|
||||
if (strlcpy(buf,
|
||||
(mode & kNtEnableVirtualTerminalInput) ? "CONIN$" : "CONOUT$",
|
||||
|
|
|
@ -66,7 +66,6 @@ static void GetBsdStr(int c0, int c1, char *s) {
|
|||
|
||||
// Gets NT name ignoring errors with guaranteed NUL-terminator.
|
||||
static textwindows void GetNtName(char *name, int kind) {
|
||||
uint32_t n = SYS_NMLN;
|
||||
char16_t name16[256];
|
||||
uint32_t size = ARRAYLEN(name16);
|
||||
if (GetComputerNameEx(kind, name16, &size)) {
|
||||
|
|
|
@ -211,8 +211,8 @@ static int unveil_init(void) {
|
|||
static char *JoinPaths(char *buf, size_t size, const char *path,
|
||||
const char *other) {
|
||||
size_t pathlen, otherlen;
|
||||
if (!other) return path;
|
||||
if (!path) return other;
|
||||
if (!other) return (char *)path;
|
||||
if (!path) return (char *)other;
|
||||
pathlen = strlen(path);
|
||||
if (!pathlen || *other == '/') {
|
||||
return (/*unconst*/ char *)other;
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
|
||||
int sys_utimensat_xnu(int dirfd, const char *path, const struct timespec ts[2],
|
||||
int flags) {
|
||||
int i;
|
||||
struct stat st;
|
||||
struct timeval now, tv[2];
|
||||
if (flags) return einval();
|
||||
|
|
|
@ -81,11 +81,11 @@ static textwindows void AddProcessStats(int64_t h, struct rusage *ru) {
|
|||
static textwindows int sys_wait4_nt_impl(int *pid, int *opt_out_wstatus,
|
||||
int options,
|
||||
struct rusage *opt_out_rusage) {
|
||||
int pids[64];
|
||||
int64_t handle;
|
||||
int rc, pids[64];
|
||||
uint32_t i, count;
|
||||
int64_t handles[64];
|
||||
uint32_t dwExitCode;
|
||||
uint32_t i, j, count;
|
||||
if (*pid != -1 && *pid != 0) {
|
||||
if (*pid < 0) {
|
||||
// XXX: this is sloppy
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "libc/sysv/consts/sicode.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/thread/tls.h"
|
||||
#include "libc/thread/tls2.h"
|
||||
#include "libc/thread/tls2.internal.h"
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
||||
|
|
|
@ -101,7 +101,6 @@ Finish:
|
|||
// this makes it possible for our read() implementation to periodically
|
||||
// poll for signals while performing a blocking overlapped io operation
|
||||
dontasan dontubsan dontinstrument textwindows void WinMainStdin(void) {
|
||||
uint32_t mode;
|
||||
char16_t pipename[64];
|
||||
int64_t hStdin, hWriter, hReader, hThread, hSemaphore;
|
||||
if (!SupportsWindows()) return;
|
||||
|
|
|
@ -79,9 +79,9 @@ ssize_t write(int fd, const void *buf, size_t size) {
|
|||
} else if (fd >= g_fds.n) {
|
||||
rc = ebadf();
|
||||
} else if (IsMetal()) {
|
||||
rc = sys_writev_metal(g_fds.p + fd, &(struct iovec){buf, size}, 1);
|
||||
rc = sys_writev_metal(g_fds.p + fd, &(struct iovec){(void *)buf, size}, 1);
|
||||
} else if (IsWindows()) {
|
||||
rc = sys_writev_nt(fd, &(struct iovec){buf, size}, 1);
|
||||
rc = sys_writev_nt(fd, &(struct iovec){(void *)buf, size}, 1);
|
||||
} else {
|
||||
rc = enosys();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ int getaddrinfo(const char *name, const char *service,
|
|||
const struct addrinfo *hints, struct addrinfo **res) {
|
||||
int rc, port;
|
||||
const char *canon;
|
||||
size_t protolen;
|
||||
struct addrinfo *ai;
|
||||
char proto[32];
|
||||
port = 0;
|
||||
|
|
|
@ -58,7 +58,7 @@ int getnameinfo(const struct sockaddr *addr, uint32_t addrlen, char *name,
|
|||
int flags) {
|
||||
char *p, rdomain[1 + sizeof "255.255.255.255.in-addr.arpa"];
|
||||
char info[NI_MAXHOST + 1];
|
||||
int rc, port;
|
||||
int port;
|
||||
uint8_t *ip;
|
||||
unsigned int valid_flags;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ COSMOPOLITAN_C_START_
|
|||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § executable linkable format ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
/* clang-format off */
|
||||
|
||||
bool IsElfSymbolContent(const Elf64_Sym *);
|
||||
bool IsElf64Binary(const Elf64_Ehdr *, size_t);
|
||||
|
@ -18,11 +19,11 @@ Elf64_Sym *GetElfSymbols(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
|
|||
Elf64_Shdr *GetElfSymbolTable(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
|
||||
Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
|
||||
Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
|
||||
Elf64_Shdr *FindElfSectionByName(Elf64_Ehdr *, size_t, char *, const char *);
|
||||
const char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word);
|
||||
Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *, size_t, char *, const char *);
|
||||
char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word);
|
||||
void *GetElfSectionAddress(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
|
||||
void *GetElfSegmentAddress(const Elf64_Ehdr *, size_t, const Elf64_Phdr *);
|
||||
const char *GetElfSectionName(const Elf64_Ehdr *, size_t, Elf64_Shdr *);
|
||||
char *GetElfSectionName(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
|
||||
char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
* @param mapsize is the number of bytes past `elf` we can access
|
||||
* @return pointer to section header within image, or null
|
||||
*/
|
||||
Elf64_Shdr *FindElfSectionByName(Elf64_Ehdr *elf, size_t mapsize,
|
||||
Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *elf, size_t mapsize,
|
||||
char *shdrstrtab, const char *name) {
|
||||
long i;
|
||||
Elf64_Shdr *shdr;
|
||||
|
|
|
@ -39,7 +39,7 @@ void *GetElfSectionAddress(const Elf64_Ehdr *elf, // validated
|
|||
const Elf64_Shdr *shdr) { // foreign
|
||||
Elf64_Off last;
|
||||
if (!shdr) return 0;
|
||||
if (!shdr->sh_size) return elf;
|
||||
if (!shdr->sh_size) return (void *)elf;
|
||||
if (shdr->sh_type == SHT_NOBITS) return 0;
|
||||
if (ckd_add(&last, shdr->sh_offset, shdr->sh_size)) return 0;
|
||||
if (last > mapsize) return 0;
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/elf/elf.h"
|
||||
|
||||
const char *GetElfSectionName(const Elf64_Ehdr *elf, size_t mapsize,
|
||||
Elf64_Shdr *shdr) {
|
||||
char *GetElfSectionName(const Elf64_Ehdr *elf, size_t mapsize,
|
||||
const Elf64_Shdr *shdr) {
|
||||
if (!shdr) return 0;
|
||||
return GetElfString(elf, mapsize, GetElfSectionNameStringTable(elf, mapsize),
|
||||
shdr->sh_name);
|
||||
|
|
|
@ -39,10 +39,10 @@
|
|||
* 3. a nul byte wasn't present within `[strtab+i,elf+mapsize)`, or
|
||||
* 4. an arithmetic overflow occurred
|
||||
*/
|
||||
const char *GetElfString(const Elf64_Ehdr *elf, // validated
|
||||
size_t mapsize, // validated
|
||||
const char *strtab, // validated
|
||||
Elf64_Word i) { // foreign
|
||||
char *GetElfString(const Elf64_Ehdr *elf, // validated
|
||||
size_t mapsize, // validated
|
||||
const char *strtab, // validated
|
||||
Elf64_Word i) { // foreign
|
||||
const char *e;
|
||||
if (!i) return "";
|
||||
e = (const char *)elf;
|
||||
|
@ -50,5 +50,5 @@ const char *GetElfString(const Elf64_Ehdr *elf, // validated
|
|||
if (i >= mapsize) return 0;
|
||||
if (strtab + i >= e + mapsize) return 0;
|
||||
if (!memchr(strtab + i, 0, (e + mapsize) - (strtab + i))) return 0;
|
||||
return (const char *)strtab + i;
|
||||
return (char *)strtab + i;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ char *GetElfStringTable(const Elf64_Ehdr *elf, //
|
|||
const char *section_name) {
|
||||
int i;
|
||||
char *name;
|
||||
Elf64_Shdr *shdr;
|
||||
const Elf64_Shdr *shdr;
|
||||
for (i = 0; i < elf->e_shnum; ++i) {
|
||||
if ((shdr = GetElfSectionHeaderAddress(elf, mapsize, i)) &&
|
||||
shdr->sh_type == SHT_STRTAB &&
|
||||
|
|
|
@ -22,7 +22,7 @@ COSMOPOLITAN_C_START_
|
|||
((Elf64_Shdr *)((intptr_t)(e) + (e)->e_shoff + \
|
||||
(unsigned)(e)->e_shentsize * (i)))
|
||||
|
||||
static inline char *GetStrtab(Elf64_Ehdr *e, size_t *n) {
|
||||
static inline char *GetStrtab(const Elf64_Ehdr *e, size_t *n) {
|
||||
int i;
|
||||
char *name;
|
||||
Elf64_Shdr *shdr;
|
||||
|
@ -39,7 +39,7 @@ static inline char *GetStrtab(Elf64_Ehdr *e, size_t *n) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline Elf64_Sym *GetSymtab(Elf64_Ehdr *e, Elf64_Xword *n) {
|
||||
static inline Elf64_Sym *GetSymtab(const Elf64_Ehdr *e, Elf64_Xword *n) {
|
||||
int i;
|
||||
Elf64_Shdr *shdr;
|
||||
for (i = e->e_shnum; i-- > 0;) {
|
||||
|
@ -52,9 +52,10 @@ static inline Elf64_Sym *GetSymtab(Elf64_Ehdr *e, Elf64_Xword *n) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline void GetImageRange(Elf64_Ehdr *elf, intptr_t *x, intptr_t *y) {
|
||||
static inline void GetImageRange(const Elf64_Ehdr *elf, intptr_t *x,
|
||||
intptr_t *y) {
|
||||
unsigned i;
|
||||
Elf64_Phdr *phdr;
|
||||
const Elf64_Phdr *phdr;
|
||||
intptr_t start, end, pstart, pend;
|
||||
start = INTPTR_MAX;
|
||||
end = 0;
|
||||
|
|
|
@ -17,7 +17,7 @@ int snprintf(char *, size_t, const char *, ...)
|
|||
printfesque(3) dontthrow nocallback;
|
||||
int vsnprintf(char *, size_t, const char *, va_list)
|
||||
dontthrow nocallback;
|
||||
int sprintf(char *, const char *, ...) printfesque(2) dontthrow nocallback;
|
||||
int sprintf(char *, const char *, ...) dontthrow nocallback;
|
||||
int vsprintf(char *, const char *, va_list)
|
||||
dontthrow nocallback;
|
||||
int sscanf(const char *, const char *, ...) scanfesque(2);
|
||||
|
|
|
@ -14,7 +14,7 @@ char *sleb64(char *, int64_t);
|
|||
char *zleb64(char[hasatleast 10], int64_t);
|
||||
char *uleb64(char[hasatleast 10], uint64_t);
|
||||
int unzleb64(const char *, size_t, int64_t *);
|
||||
int unuleb64(char *, size_t, uint64_t *);
|
||||
int unuleb64(const char *, size_t, uint64_t *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* _COSMO_SOURCE */
|
||||
|
|
|
@ -28,9 +28,9 @@ extern const struct MagnumStr kSockOptnames[];
|
|||
extern const struct MagnumStr kTcpOptnames[];
|
||||
extern const struct MagnumStr kPollNames[];
|
||||
|
||||
char *DescribeMagnum(char *, const struct MagnumStr *, const char *, int);
|
||||
const char *DescribeMagnum(char *, const struct MagnumStr *, const char *, int);
|
||||
|
||||
__funline char *GetMagnumStr(const struct MagnumStr *ms, int x) {
|
||||
__funline const char *GetMagnumStr(const struct MagnumStr *ms, int x) {
|
||||
int i;
|
||||
for (i = 0; ms[i].x != MAGNUM_TERMINATOR; ++i) {
|
||||
if (x == MAGNUM_NUMBER(ms, i)) {
|
||||
|
@ -44,7 +44,7 @@ __funline char *GetMagnumStr(const struct MagnumStr *ms, int x) {
|
|||
* Converts errno value to descriptive sentence.
|
||||
* @return non-null rodata string or null if not found
|
||||
*/
|
||||
__funline char *_strerdoc(int x) {
|
||||
__funline const char *_strerdoc(int x) {
|
||||
if (x) {
|
||||
return GetMagnumStr(kErrnoDocs, x);
|
||||
} else {
|
||||
|
@ -56,7 +56,7 @@ __funline char *_strerdoc(int x) {
|
|||
* Converts errno value to symbolic name.
|
||||
* @return non-null rodata string or null if not found
|
||||
*/
|
||||
__funline char *_strerrno(int x) {
|
||||
__funline const char *_strerrno(int x) {
|
||||
if (x) {
|
||||
return GetMagnumStr(kErrnoNames, x);
|
||||
} else {
|
||||
|
|
|
@ -53,7 +53,7 @@ long strtol(const char *s, char **endptr, int base) {
|
|||
char t = 0;
|
||||
long x = 0;
|
||||
int d, c = *s;
|
||||
CONSUME_SPACES(s, c);
|
||||
CONSUME_SPACES(char, s, c);
|
||||
GET_SIGN(s, c, d);
|
||||
GET_RADIX(s, c, base);
|
||||
if ((c = kBase36[c & 255]) && --c < base) {
|
||||
|
@ -67,7 +67,9 @@ long strtol(const char *s, char **endptr, int base) {
|
|||
} while ((c = kBase36[*++s & 255]) && --c < base);
|
||||
}
|
||||
}
|
||||
if (t && endptr) *endptr = s;
|
||||
if (t && endptr) {
|
||||
*endptr = (char *)s;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#define COSMOPOLITAN_LIBC_FMT_STRTOL_H_
|
||||
#include "libc/errno.h"
|
||||
|
||||
#define CONSUME_SPACES(s, c) \
|
||||
if (endptr) *endptr = s; \
|
||||
#define CONSUME_SPACES(t, s, c) \
|
||||
if (endptr) *endptr = (t *)(s); \
|
||||
while (c == ' ' || c == '\t') c = *++s
|
||||
|
||||
#define GET_SIGN(s, c, d) \
|
||||
|
|
|
@ -42,20 +42,24 @@ unsigned long strtoul(const char *s, char **endptr, int base) {
|
|||
char t = 0;
|
||||
int d, c = *s;
|
||||
unsigned long x = 0;
|
||||
CONSUME_SPACES(s, c);
|
||||
CONSUME_SPACES(char, s, c);
|
||||
GET_SIGN(s, c, d);
|
||||
GET_RADIX(s, c, base);
|
||||
if ((c = kBase36[c & 255]) && --c < base) {
|
||||
t |= 1;
|
||||
do {
|
||||
if (ckd_mul(&x, x, base) || ckd_add(&x, x, c)) {
|
||||
if (endptr) *endptr = s + 1;
|
||||
if (endptr) {
|
||||
*endptr = (char *)(s + 1);
|
||||
}
|
||||
errno = ERANGE;
|
||||
return ULONG_MAX;
|
||||
}
|
||||
} while ((c = kBase36[*++s & 255]) && --c < base);
|
||||
}
|
||||
if (t && endptr) *endptr = s;
|
||||
if (t && endptr) {
|
||||
*endptr = (char *)s;
|
||||
}
|
||||
return d > 0 ? x : -x;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* @param x receives number number
|
||||
* @return bytes decoded or -1 on error
|
||||
*/
|
||||
int unuleb64(char *p, size_t n, uint64_t *x) {
|
||||
int unuleb64(const char *p, size_t n, uint64_t *x) {
|
||||
int k;
|
||||
size_t i;
|
||||
uint64_t t;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue