Skip to content

Commit

Permalink
Merge pull request #2243 from ghaerr/strictansi
Browse files Browse the repository at this point in the history
[libc] Update libc headers to allow compilation with -std=c99
  • Loading branch information
ghaerr authored Feb 26, 2025
2 parents 6ba245c + 821ad59 commit d22d424
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 15 deletions.
1 change: 0 additions & 1 deletion elks/include/arch/cdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

#ifdef __C86__
#define __HAS_NO_FLOATS__ 1
#define __far
#define noreturn
#define stdcall
#define restrict
Expand Down
3 changes: 3 additions & 0 deletions elks/include/linuxmt/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ typedef unsigned long sigset_t; /* at least 32 bits */

/* Type of a signal handler within userland. */
typedef void (*sighandler_t)(int);

#ifndef __STRICT_ANSI__
/* Type of a signal handler which interfaces with the kernel. This is always
a far function that uses the `stdcall' calling convention, even for a
user program that is being compiled for a different calling convention. */
Expand All @@ -194,6 +196,7 @@ typedef void stdcall (__far *__kern_sighandler_t)(int);
#ifdef __C86__
typedef void (*__kern_sighandler_t)(int); /* CS passed separately to _signal */
#endif
#endif /* !__STRICT_ANSI__ */

/*
* Because this stuff can get pretty confusing:
Expand Down
8 changes: 5 additions & 3 deletions libc/include/malloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void *_drealloc(void *, size_t);
void _dfree(void *);
size_t _dmalloc_usable_size(void *);

#ifndef __STRICT_ANSI__
/* _fmalloc (single arena 64k far heap) */
void __far *_fmalloc(size_t);
int _fmalloc_add_heap(char __far *start, size_t size);
Expand All @@ -24,15 +25,16 @@ size_t _fmalloc_usable_size(void __far *);
extern unsigned int malloc_arena_size; /* mem.c wrapper function */
extern unsigned int malloc_arena_thresh; /* mem.c wrapper function */

/* usable with all mallocs */
void *calloc(size_t elm, size_t sz);

/* alloc/free from main memory */
void __far *fmemalloc(unsigned long size);
int fmemfree(void __far *ptr);

int _fmemalloc(int paras, unsigned short *pseg); /* syscall */
int _fmemfree(unsigned short seg); /* syscall */
#endif

/* usable with all mallocs */
void *calloc(size_t elm, size_t sz);

/* debug output */
int __dprintf(const char *fmt, ...);
Expand Down
4 changes: 2 additions & 2 deletions libc/include/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
sighandler_t signal(int number, sighandler_t pointer);

#ifdef __C86__
int _signal(int __sig, __kern_sighandler_t __cbfunc, unsigned int cs); /* syscall */
#else
int _signal(int __sig, sighandler_t __cbfunc, unsigned int cs); /* syscall */
#elif !defined(__STRICT_ANSI__)
int _signal(int __sig, __kern_sighandler_t __cbfunc); /* syscall */
#endif

Expand Down
3 changes: 1 addition & 2 deletions libc/include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void qsort(void *base, size_t nel, size_t width,
int (*compar)(/*const void *, const void * */));
char *devname(dev_t dev, mode_t type);

#ifndef __STRICT_ANSI__
/* non-standard routines */
int (bsr)(int x);
char *itoa(int val);
char *uitoa(unsigned int val);
Expand All @@ -74,6 +74,5 @@ char *ltostr(long val, int radix);
char *lltostr(long long val, int radix);
char *ultostr(unsigned long val, int radix);
char *ulltostr(unsigned long long val, int radix);
#endif

#endif /* __STDLIB_H */
2 changes: 2 additions & 0 deletions libc/include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ void * memset(void*, int, size_t);
int memcmp(const void*, const void*, size_t);
void * memmove(void*, const void*, size_t);

#ifndef __STRICT_ANSI__
void __far *fmemset(void __far *buf, int c, size_t l);
int fmemcmp(void __far *s1, void __far *s2, size_t n); /* Watcom C only, in ASM */
#endif

/* Error messages */
char * strerror(int);
Expand Down
5 changes: 2 additions & 3 deletions libc/malloc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,21 @@ OBJS = \
calloc.o \
brk.o \
sbrk.o \
fmemalloc.o \
dprintf.o \

# default and debug mallocs for all compilers
OBJS += $(DEFAULT_MALLOC_OBJS) $(DEBUG_MALLOC_OBJS)

# far malloc works with OWC only for now
ifeq "$(COMPILER)" "watcom"
OBJS += $(FAR_MALLOC_OBJS)
OBJS += $(FAR_MALLOC_OBJS) fmemalloc.o
endif

IA16OBJS = \
stackcheck.o \

ifeq "$(COMPILER)" "ia16"
OBJS += $(IA16OBJS)
OBJS += $(IA16OBJS) fmemalloc.o
endif

.PHONY: all
Expand Down
2 changes: 0 additions & 2 deletions libc/malloc/fmemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
#include <sys/sysctl.h>
/* fmemalloc/fmemfree - allocate/free from main memory */

#ifndef __C86__
#define DEBUG 1 /* =1 use sysctl, =2 debug output */
#endif

#if DEBUG
#define debug(...) do { if (debug_level > 1) __dprintf(__VA_ARGS__); } while (0)
Expand Down
2 changes: 2 additions & 0 deletions libc/string/fmemset-c.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <string.h>
#include <asm/config.h>

#ifndef __C86__
#ifndef LIBC_ASM_FMEMSET

void __far *fmemset(void __far *str, int c, size_t l)
Expand All @@ -13,3 +14,4 @@ void __far *fmemset(void __far *str, int c, size_t l)
}

#endif
#endif
4 changes: 2 additions & 2 deletions libc/system/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ sighandler_t signal(int number, sighandler_t pointer)

#ifdef __C86__
if (pointer == SIG_DFL || pointer == SIG_IGN)
rv = _signal(number, (__kern_sighandler_t) pointer, 0);
rv = _signal(number, pointer, 0);
else
rv = _signal(number, (__kern_sighandler_t) _signal_cbhandler, _CS());
rv = _signal(number, _signal_cbhandler, _CS());
#else
if (pointer == SIG_DFL || pointer == SIG_IGN)
rv = _signal(number, (__kern_sighandler_t) (unsigned long)pointer);
Expand Down

0 comments on commit d22d424

Please sign in to comment.