summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-01-01 22:16:11 +0000
committerEric Andersen <andersen@codepoet.org>2001-01-01 22:16:11 +0000
commit8c29d069db1898b519c6c610a91a25b5ffb8c9d0 (patch)
treee2c90d09cd3329d33b26b53f0a2491e6a81a2025 /libc
parent67d0b8edf6c8c19366c4507d8453216d007397cd (diff)
A bunch of updates, part from Manuel Novoa III (such as more long long
support), and other updates by me (better cross platform, cross-compiler, etc, support. Now compiles with 2.0.x kernels for armnommu.
Diffstat (limited to 'libc')
-rw-r--r--libc/stdlib/Makefile9
-rw-r--r--libc/stdlib/abort.c2
-rw-r--r--libc/stdlib/malloc/alloc.c4
-rw-r--r--libc/stdlib/malloc/malloc.c4
-rw-r--r--libc/stdlib/strto_l.c4
-rw-r--r--libc/stdlib/strto_ll.c192
-rw-r--r--libc/sysdeps/linux/Makefile2
-rw-r--r--libc/sysdeps/linux/common/statfix.h4
-rw-r--r--libc/sysdeps/linux/common/syscalls.c14
9 files changed, 224 insertions, 11 deletions
diff --git a/libc/stdlib/Makefile b/libc/stdlib/Makefile
index 4d16a8585..e4b28979c 100644
--- a/libc/stdlib/Makefile
+++ b/libc/stdlib/Makefile
@@ -29,6 +29,9 @@ DIRS = $(MALLOC)
MSRC=strto_l.c
MOBJ=strtol.o strtoul.o strto_l.o
+MSRC1=strto_ll.c
+MOBJ1=strtoll.o strtoull.o strto_ll.o
+
MSRC2=atexit.c
MOBJ2=on_exit.o atexit.o __do_exit.o exit.o
@@ -38,7 +41,7 @@ CSRC = abort.c getenv.c mktemp.c qsort.c realpath.c strtod.c \
COBJS=$(patsubst %.c,%.o, $(CSRC))
-OBJS=$(MOBJ) $(MOBJ2) $(COBJS)
+OBJS=$(MOBJ) $(MOBJ1) $(MOBJ2) $(COBJS)
all: $(OBJS) $(LIBC)
@@ -51,6 +54,10 @@ $(MOBJ): $(MSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(STRIPTOOL) -x -R .note -R .comment $*.o
+$(MOBJ1): $(MSRC1)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(STRIPTOOL) -x -R .note -R .comment $*.o
+
$(MOBJ2): $(MSRC2)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(STRIPTOOL) -x -R .note -R .comment $*.o
diff --git a/libc/stdlib/abort.c b/libc/stdlib/abort.c
index 6806a8b55..23510e913 100644
--- a/libc/stdlib/abort.c
+++ b/libc/stdlib/abort.c
@@ -32,13 +32,11 @@ extern void _exit __P((int __status)) __attribute__ ((__noreturn__));
/* Cause an abnormal program termination with core-dump. */
void abort(void)
{
-#if FIXME
sigset_t sigset;
if (sigemptyset(&sigset) == 0 && sigaddset(&sigset, SIGABRT) == 0) {
sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *) NULL);
}
-#endif
if (__cleanup)
__cleanup();
diff --git a/libc/stdlib/malloc/alloc.c b/libc/stdlib/malloc/alloc.c
index b782f6dcf..22d508ca1 100644
--- a/libc/stdlib/malloc/alloc.c
+++ b/libc/stdlib/malloc/alloc.c
@@ -12,7 +12,7 @@ void *
calloc_dbg(size_t num, size_t size, char * function, char * file, int line)
{
void * ptr;
- fprintf(stderr, "calloc of %d bytes at %s @%s:%d = ", num*size, function, file, line);
+ fprintf(stderr, "calloc of %ld bytes at %s @%s:%d = ", (long)(num*size), function, file, line);
ptr = calloc(num,size);
fprintf(stderr, "%p\n", ptr);
return ptr;
@@ -26,7 +26,7 @@ void *
malloc_dbg(size_t len, char * function, char * file, int line)
{
void * result;
- fprintf(stderr, "malloc of %d bytes at %s @%s:%d = ", len, function, file, line);
+ fprintf(stderr, "malloc of %ld bytes at %s @%s:%d = ", (long)len, function, file, line);
result = malloc(len);
fprintf(stderr, "%p\n", result);
return result;
diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c
index d7df5d243..a3f50fb3b 100644
--- a/libc/stdlib/malloc/malloc.c
+++ b/libc/stdlib/malloc/malloc.c
@@ -296,8 +296,8 @@ struct Block_s /* 32-bytes long control structure (if 4-byte aligned) */
/* packed 4-byte attributes */
/* { */
- char bal_free_mem : 8; /* balance of <free_mem> subtree */
- char bal_ptrs : 8; /* balance of <ptrs> subtree */
+ signed char bal_free_mem : 8; /* balance of <free_mem> subtree */
+ signed char bal_ptrs : 8; /* balance of <ptrs> subtree */
unsigned int used : 1; /* used/free state of the block */
unsigned int broken : 1; /* 1 if previous block can't be merged with it */
/* } */
diff --git a/libc/stdlib/strto_l.c b/libc/stdlib/strto_l.c
index a83cf4095..16b29f5d6 100644
--- a/libc/stdlib/strto_l.c
+++ b/libc/stdlib/strto_l.c
@@ -15,7 +15,7 @@
/* OPTIONS */
/*****************************************************************************/
-/* Set if we want strtod to set errno appropriately. */
+/* Set if we want errno set appropriately. */
/* NOTE: Implies _STRTO_ENDPTR below */
#define _STRTO_ERRNO 0
@@ -107,8 +107,8 @@ unsigned long _strto_l(const char *str, char **endptr, int base, int uflag)
goto DONE;
}
+ cutoff_digit = ULONG_MAX % base;
cutoff = ULONG_MAX / base;
- cutoff_digit = ULONG_MAX - cutoff * base;
while (1) {
digit = 40;
diff --git a/libc/stdlib/strto_ll.c b/libc/stdlib/strto_ll.c
new file mode 100644
index 000000000..4b2854b8e
--- /dev/null
+++ b/libc/stdlib/strto_ll.c
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2000 Manuel Novoa III
+ *
+ * Notes:
+ *
+ * The primary objective of this implementation was minimal size.
+ *
+ * Note: Assumes char layout 0-9.*A-Z.*a-z for ordinals values.
+ *
+ * There are a couple of compile-time options below.
+ *
+ */
+
+/*****************************************************************************/
+/* OPTIONS */
+/*****************************************************************************/
+
+/* Set if we want errno set appropriately. */
+/* NOTE: Implies _STRTO_ENDPTR below */
+#define _STRTO_ERRNO 0
+
+/* Set if we want support for the endptr arg. */
+/* Implied by _STRTO_ERRNO. */
+#define _STRTO_ENDPTR 1
+
+/*****************************************************************************/
+/* Don't change anything that follows. */
+/*****************************************************************************/
+
+#if _STRTO_ERRNO
+#undef _STRTO_ENDPTR
+#define _STRTO_ENDPTR 1
+#endif
+
+/*****************************************************************************/
+
+/* Are there actually any machines where this might fail? */
+#if 'A' > 'a'
+#error ordering assumption violated : 'A' > 'a'
+#endif
+
+#include <stdlib.h>
+#include <limits.h>
+#include <ctype.h>
+
+#if _STRTO_ERRNO
+#include <errno.h>
+#endif
+
+unsigned long long _strto_ll(const char *str, char **endptr, int base, int uflag);
+
+#if L_strto_ll
+
+/*
+ * This is the main work fuction which handles both strtol (uflag = 0) and
+ * strtoul (uflag = 1).
+ */
+
+unsigned long long _strto_ll(const char *str, char **endptr, int base, int uflag)
+{
+ unsigned long long number = 0;
+ unsigned long long cutoff;
+ char *pos = (char *) str;
+#if _STRTO_ENDPTR
+ char *fail_char = (char *) str;
+#endif
+ int digit, cutoff_digit;
+ int negative;
+
+ while (isspace(*pos)) { /* skip leading whitespace */
+ ++pos;
+ }
+
+ /* handle optional sign */
+ negative = 0;
+ switch(*pos) {
+ case '-': negative = 1; /* fall through to increment pos */
+ case '+': ++pos;
+ }
+
+ if ((base == 16) && (*pos == '0')) { /* handle option prefix */
+ ++pos;
+#if _STRTO_ENDPTR
+ fail_char = pos;
+#endif
+ if ((*pos == 'x') || (*pos == 'X')) {
+ ++pos;
+ }
+ }
+
+ if (base == 0) { /* dynamic base */
+ base = 10; /* default is 10 */
+ if (*pos == '0') {
+ ++pos;
+ base -= 2; /* now base is 8 (or 16) */
+#if _STRTO_ENDPTR
+ fail_char = pos;
+#endif
+ if ((*pos == 'x') || (*pos == 'X')) {
+ base += 8; /* base is 16 */
+ ++pos;
+ }
+ }
+ }
+
+ if ((base < 2) || (base > 36)) { /* illegal base */
+ goto DONE;
+ }
+
+ cutoff_digit = ULONG_LONG_MAX % base;
+ cutoff = ULONG_LONG_MAX / base;
+
+ while (1) {
+ digit = 40;
+ if ((*pos >= '0') && (*pos <= '9')) {
+ digit = (*pos - '0');
+ } else if (*pos >= 'a') {
+ digit = (*pos - 'a' + 10);
+ } else if (*pos >= 'A') {
+ digit = (*pos - 'A' + 10);
+ } else break;
+
+ if (digit >= base) {
+ break;
+ }
+
+ ++pos;
+#if _STRTO_ENDPTR
+ fail_char = pos;
+#endif
+
+ /* adjust number, with overflow check */
+ if ((number > cutoff)
+ || ((number == cutoff) && (digit > cutoff_digit))) {
+ number = ULONG_LONG_MAX;
+ if (uflag) {
+ negative = 0; /* since unsigned returns ULONG_LONG_MAX */
+ }
+#if _STRTO_ERRNO
+ errno = ERANGE;
+#endif
+ } else {
+ number = number * base + digit;
+ }
+
+ }
+
+ DONE:
+#if _STRTO_ENDPTR
+ if (endptr) {
+ *endptr = fail_char;
+ }
+#endif
+
+ if (negative) {
+ if (!uflag && (number > ((unsigned long long)(-(1+LONG_LONG_MIN)))+1)) {
+#if _STRTO_ERRNO
+ errno = ERANGE;
+#endif
+ return (unsigned long long) LONG_LONG_MIN;
+ }
+ return (unsigned long long)(-((long long)number));
+ } else {
+ if (!uflag && (number > (unsigned long long) LONG_LONG_MAX)) {
+#if _STRTO_ERRNO
+ errno = ERANGE;
+#endif
+ return LONG_LONG_MAX;
+ }
+ return number;
+ }
+}
+
+#endif
+
+#if L_strtoull
+
+unsigned long long strtoull(const char *str, char **endptr, int base)
+{
+ return _strto_ll(str, endptr, base, 1);
+}
+
+#endif
+
+#if L_strtoll
+
+long long strtoll(const char *str, char **endptr, int base)
+{
+ return _strto_ll(str, endptr, base, 0);
+}
+
+#endif
diff --git a/libc/sysdeps/linux/Makefile b/libc/sysdeps/linux/Makefile
index 2451e6383..fb7808913 100644
--- a/libc/sysdeps/linux/Makefile
+++ b/libc/sysdeps/linux/Makefile
@@ -23,7 +23,7 @@
TOPDIR=../../
include $(TOPDIR)Rules.mak
-DIRS = $(ARCH) common
+DIRS = $(TARGET_ARCH) common
all: libc.a
diff --git a/libc/sysdeps/linux/common/statfix.h b/libc/sysdeps/linux/common/statfix.h
index 21a776c92..df85d84d4 100644
--- a/libc/sysdeps/linux/common/statfix.h
+++ b/libc/sysdeps/linux/common/statfix.h
@@ -3,9 +3,11 @@
/* Pull in whatever this particular arch's kernel thinks the kernel version of
* struct stat should look like. It turn out that each arch has a different
- * opinion on the subject... */
+ * opinion on the subject, and different kernel revs use different names... */
#define stat kernel_stat
+#define new_stat kernel_stat
#include <asm/stat.h>
+#undef new_stat
#undef stat
/* Now pull in libc's version of stat */
diff --git a/libc/sysdeps/linux/common/syscalls.c b/libc/sysdeps/linux/common/syscalls.c
index c0630e1fd..a0bad06be 100644
--- a/libc/sysdeps/linux/common/syscalls.c
+++ b/libc/sysdeps/linux/common/syscalls.c
@@ -135,11 +135,19 @@ _syscall3(int, mknod, const char *, pathname, mode_t, mode, dev_t, dev);
_syscall2(int, chmod, const char *, path, mode_t, mode);
#endif
+/* Old kernels don't have lchown -- do chown instead. This
+ * is sick and wrong, but at least things will compile.
+ * They may not follow links when they should though... */
+#ifndef __NR_lchown
+#define __NR_lchown __NR_chown
+#endif
+
//#define __NR_lchown 16
#ifdef L_lchown
#include <unistd.h>
_syscall3(int, lchown, const char *, path, uid_t, owner, gid_t, group);
#endif
+#endif
//#define __NR_break 17
@@ -325,11 +333,13 @@ gid_t getegid(void)
//#define __NR_acct 51
+#ifdef __NR_umount2 /* Old kernels don't have umount2 */
//#define __NR_umount2 52
#ifdef L_umount2
#include <sys/mount.h>
_syscall2(int, umount2, const char *, special_file, int, flags);
#endif
+#endif
//#define __NR_lock 53
@@ -639,6 +649,7 @@ _syscall2(int, statfs, const char *, path, struct statfs *, buf);
_syscall2(int, fstatfs, int, fd, struct statfs *, buf);
#endif
+#ifndef __HAS_NO_MMU__
//#define __NR_ioperm 101
#ifdef L_ioperm
#include <sys/io.h>
@@ -646,6 +657,7 @@ syscall3(int, ioperm, unsigned, long, from, unsigned long, num, int,
turn_on);
#endif
+#endif
//#define __NR_socketcall 102
#ifdef L_socketcall
@@ -737,11 +749,13 @@ int fstat(int fd, struct libc_stat *cstat)
//#define __NR_olduname 109
+#ifndef __HAS_NO_MMU__
//#define __NR_iopl 110
#ifdef L_iopl
#include <sys/io.h>
_syscall1(int, iopl, int, level);
#endif
+#endif
//#define __NR_vhangup 111
#ifdef L_vhangup