Replace COSMO define with _COSMO_SOURCE

This change might cause ABI breakages for /opt/cosmos. It's needed to
help us better conform to header declaration practices.
This commit is contained in:
Justine Tunney 2023-08-13 20:31:27 -07:00
parent a033b65a33
commit c776a32f75
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
238 changed files with 858 additions and 1069 deletions

View file

@ -1,48 +0,0 @@
/*-*- 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
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
/**
* Replaces tilde in path w/ user home folder.
*
* @param path is NULL propagating
* @return must be free()'d
*/
char *replaceuser(const char *path) {
char *res, *p;
const char *home;
size_t pathlen, homelen;
res = NULL;
if (path && *path++ == '~' && !isempty((home = getenv("HOME")))) {
while (*path == '/') path++;
pathlen = strlen(path);
homelen = strlen(home);
while (homelen && home[homelen - 1] == '/') homelen--;
if ((p = res = malloc(pathlen + 1 + homelen + 1))) {
p = mempcpy(p, home, homelen);
*p++ = '/';
memcpy(p, path, pathlen + 1);
}
}
return res;
}

View file

@ -76,7 +76,7 @@ char *utf16to8(const char16_t *p, size_t n, size_t *z) {
if (x < 0200) {
*q++ = x;
} else {
w = _tpenc(x);
w = tpenc(x);
WRITE64LE(q, w);
q += _bsr(w) >> 3;
q += 1;

View file

@ -37,7 +37,7 @@ char *utf32to8(const wchar_t *p, size_t n, size_t *z) {
if ((q = r = malloc(n * 6 + 1))) {
for (i = 0; i < n; ++i) {
x = p[i];
w = _tpenc(x);
w = tpenc(x);
do {
*q++ = w;
} while ((w >>= 8));

View file

@ -1,9 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_X_H_
#define COSMOPOLITAN_LIBC_X_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#ifdef COSMO
#ifdef _COSMO_SOURCE
#define xwrite __xwrite
#define xdie __xdie
#define xmalloc __xmalloc
@ -34,6 +32,11 @@ COSMOPOLITAN_C_START_
#define xfixpath __xfixpath
#define xslurp __xslurp
#define xbarf __xbarf
#endif /* _COSMO_SOURCE */
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
int xwrite(int, const void *, uint64_t);
void xdie(void) wontreturn;
@ -94,7 +97,7 @@ void *xslurp(const char *, size_t *)
returnsaligned((4096)) dontdiscard;
int xbarf(const char *, const void *, size_t);
#endif /* COSMO */
COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_X_H_ */

View file

@ -23,10 +23,10 @@
/**
* Reads line from stream.
*
* @return allocated line that needs free() and usually _chomp() too,
* @return allocated line that needs free() and usually chomp() too,
* or NULL on ferror() or feof()
* @see getdelim() for a more difficult api
* @see _chomp()
* @see chomp()
*/
char *xgetline(FILE *f) {
char *p;

View file

@ -40,7 +40,7 @@ char *xjoinpaths(const char *path, const char *other) {
return xstrdup(other);
} else if (_isabspath(other) || !strcmp(path, ".")) {
return xstrdup(other);
} else if (_endswith(path, "/")) {
} else if (endswith(path, "/")) {
return xstrcat(path, other);
} else {
return xstrcat(path, (uintptr_t)'/', other);