Skip to content

Commit 3e19b96

Browse files
committed
Add more POSIX function stubs
Cosmopolitan currently doesn't support threads and it doesn't do anything fancy in longjmp/setjmp so this change was simple to do - localeconv - _setjmp (same as setjmp) - _longjmp (same as longjmp) - strcoll (same as strcmp) - flockfile (does nothing) - funlockfile (does nothing) - ftrylockfile (does nothing) See #61
1 parent 1831e3c commit 3e19b96

File tree

9 files changed

+151
-2
lines changed

9 files changed

+151
-2
lines changed

libc/nexgen32e/longjmp.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ longjmp:mov %esi,%eax
4040
mov 48(%rdi),%r15
4141
jmp *56(%rdi)
4242
.endfn longjmp,globl
43-
.source __FILE__
43+
.alias longjmp,_longjmp

libc/nexgen32e/setjmp.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ setjmp: lea 8(%rsp),%rax
3939
xor %eax,%eax
4040
ret
4141
.endfn setjmp,globl
42-
.source __FILE__
42+
.alias setjmp,_setjmp

libc/runtime/runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ unsigned long getauxval(unsigned long);
3939
void *mapanon(size_t) vallocesque attributeallocsize((1));
4040
int setjmp(jmp_buf) libcesque returnstwice paramsnonnull();
4141
void longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
42+
int _setjmp(jmp_buf) libcesque returnstwice paramsnonnull();
43+
void _longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
4244
void exit(int) wontreturn;
4345
void _exit(int) libcesque wontreturn;
4446
void _Exit(int) libcesque wontreturn;

libc/stdio/flockfile.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
2+
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
3+
╞══════════════════════════════════════════════════════════════════════════════╡
4+
│ Copyright 2021 Justine Alexandra Roberts Tunney │
5+
│ │
6+
│ Permission to use, copy, modify, and/or distribute this software for │
7+
│ any purpose with or without fee is hereby granted, provided that the │
8+
│ above copyright notice and this permission notice appear in all copies. │
9+
│ │
10+
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
11+
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
12+
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
13+
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
14+
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
15+
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
16+
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
17+
│ PERFORMANCE OF THIS SOFTWARE. │
18+
╚─────────────────────────────────────────────────────────────────────────────*/
19+
#include "libc/stdio/stdio.h"
20+
21+
/**
22+
* Does nothing since Cosmopolitan currently doesn't support threads.
23+
*/
24+
void flockfile(FILE *f) {
25+
}
26+
27+
/**
28+
* Does nothing since Cosmopolitan currently doesn't support threads.
29+
*/
30+
void funlockfile(FILE *f) {
31+
}
32+
33+
/**
34+
* Does nothing since Cosmopolitan currently doesn't support threads.
35+
*/
36+
int ftrylockfile(FILE *f) {
37+
return 0;
38+
}

libc/stdio/unlocked.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#if !(__ASSEMBLER__ + __LINKER__ + 0)
55
COSMOPOLITAN_C_START_
66

7+
void flockfile(FILE *);
8+
void funlockfile(FILE *);
9+
int ftrylockfile(FILE *);
710
int getc_unlocked(FILE *) paramsnonnull();
811
int getchar_unlocked(void);
912
int putc_unlocked(int, FILE *) paramsnonnull();

libc/str/strcoll.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
2+
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
3+
╞══════════════════════════════════════════════════════════════════════════════╡
4+
│ Copyright 2021 Justine Alexandra Roberts Tunney │
5+
│ │
6+
│ Permission to use, copy, modify, and/or distribute this software for │
7+
│ any purpose with or without fee is hereby granted, provided that the │
8+
│ above copyright notice and this permission notice appear in all copies. │
9+
│ │
10+
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
11+
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
12+
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
13+
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
14+
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
15+
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
16+
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
17+
│ PERFORMANCE OF THIS SOFTWARE. │
18+
╚─────────────────────────────────────────────────────────────────────────────*/
19+
#include "libc/str/str.h"
20+
21+
/**
22+
* Compares strings in the C locale.
23+
*/
24+
int strcoll(const char *p, const char *q) {
25+
return strcmp(p, q);
26+
}

libc/unicode/localeconv.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
2+
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
3+
╞══════════════════════════════════════════════════════════════════════════════╡
4+
│ Copyright 2021 Justine Alexandra Roberts Tunney │
5+
│ │
6+
│ Permission to use, copy, modify, and/or distribute this software for │
7+
│ any purpose with or without fee is hereby granted, provided that the │
8+
│ above copyright notice and this permission notice appear in all copies. │
9+
│ │
10+
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
11+
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
12+
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
13+
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
14+
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
15+
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
16+
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
17+
│ PERFORMANCE OF THIS SOFTWARE. │
18+
╚─────────────────────────────────────────────────────────────────────────────*/
19+
#include "libc/limits.h"
20+
#include "libc/unicode/unicode.h"
21+
22+
static const struct lconv kLocaleConv = {
23+
.decimal_point = ".",
24+
.thousands_sep = "",
25+
.grouping = "",
26+
.int_curr_symbol = "",
27+
.currency_symbol = "",
28+
.mon_decimal_point = "",
29+
.mon_thousands_sep = "",
30+
.mon_grouping = "",
31+
.positive_sign = "",
32+
.negative_sign = "",
33+
.int_frac_digits = CHAR_MAX,
34+
.frac_digits = CHAR_MAX,
35+
.p_cs_precedes = CHAR_MAX,
36+
.p_sep_by_space = CHAR_MAX,
37+
.n_cs_precedes = CHAR_MAX,
38+
.n_sep_by_space = CHAR_MAX,
39+
.p_sign_posn = CHAR_MAX,
40+
.n_sign_posn = CHAR_MAX,
41+
.int_p_cs_precedes = CHAR_MAX,
42+
.int_p_sep_by_space = CHAR_MAX,
43+
.int_n_cs_precedes = CHAR_MAX,
44+
.int_n_sep_by_space = CHAR_MAX,
45+
.int_p_sign_posn = CHAR_MAX,
46+
.int_n_sign_posn = CHAR_MAX,
47+
};
48+
49+
struct lconv *localeconv(void) {
50+
return (/* unconst */ struct lconv *)&kLocaleConv;
51+
}

libc/unicode/unicode.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,41 @@
33
#if !(__ASSEMBLER__ + __LINKER__ + 0)
44
COSMOPOLITAN_C_START_
55

6+
struct lconv {
7+
char *decimal_point;
8+
char *thousands_sep;
9+
char *grouping;
10+
char *int_curr_symbol;
11+
char *currency_symbol;
12+
char *mon_decimal_point;
13+
char *mon_thousands_sep;
14+
char *mon_grouping;
15+
char *positive_sign;
16+
char *negative_sign;
17+
char int_frac_digits;
18+
char frac_digits;
19+
char p_cs_precedes;
20+
char p_sep_by_space;
21+
char n_cs_precedes;
22+
char n_sep_by_space;
23+
char p_sign_posn;
24+
char n_sign_posn;
25+
char int_p_cs_precedes;
26+
char int_n_cs_precedes;
27+
char int_p_sep_by_space;
28+
char int_n_sep_by_space;
29+
char int_p_sign_posn;
30+
char int_n_sign_posn;
31+
};
32+
633
int wcwidth(wchar_t) pureconst;
734
int wcswidth(const wchar_t *, size_t) strlenesque;
835
int wcsnwidth(const wchar_t *, size_t, size_t) strlenesque;
936
int strwidth(const char *, size_t) strlenesque;
1037
int strnwidth(const char *, size_t, size_t) strlenesque;
1138
int strwidth16(const char16_t *, size_t) strlenesque;
1239
int strnwidth16(const char16_t *, size_t, size_t) strlenesque;
40+
struct lconv *localeconv(void);
1341

1442
COSMOPOLITAN_C_END_
1543
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

tool/emacs/cosmo-c-constants.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"SIZEOF_FLOAT80"
3838
"SIZEOF_LONG_DOUBLE"
3939
"SIZEOF_INTMAX"
40+
"CHAR_MAX"
4041
"SCHAR_MAX"
4142
"SHRT_MAX"
4243
"INT_MAX"

0 commit comments

Comments
 (0)