diff options
author | Carmelo Amoroso <carmelo.amoroso@st.com> | 2007-11-20 10:09:16 +0000 |
---|---|---|
committer | Carmelo Amoroso <carmelo.amoroso@st.com> | 2007-11-20 10:09:16 +0000 |
commit | 244539cd0852bbcf8f21507d7ff866d8e7fcff18 (patch) | |
tree | 5a04e6a195814b645007e4ccecb128d8c7b31ee7 /libc/stdlib | |
parent | 1cac0350028cc4a47715f63e61379d3318b0c965 (diff) | |
download | uClibc-alpine-244539cd0852bbcf8f21507d7ff866d8e7fcff18.tar.bz2 uClibc-alpine-244539cd0852bbcf8f21507d7ff866d8e7fcff18.tar.xz |
Fix Makefile.in and synch them with trunk. Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'libc/stdlib')
-rw-r--r-- | libc/stdlib/Makefile.in | 8 | ||||
-rw-r--r-- | libc/stdlib/_atexit.c | 1 | ||||
-rw-r--r-- | libc/stdlib/malloc-simple/alloc.c | 6 | ||||
-rw-r--r-- | libc/stdlib/malloc-standard/Makefile.in | 2 | ||||
-rw-r--r-- | libc/stdlib/malloc-standard/malloc.c | 7 | ||||
-rw-r--r-- | libc/stdlib/malloc/heap_debug.c | 10 | ||||
-rw-r--r-- | libc/stdlib/malloc/malloc.c | 4 | ||||
-rw-r--r-- | libc/stdlib/malloc/realloc.c | 7 | ||||
-rw-r--r-- | libc/stdlib/mkdtemp.c | 5 | ||||
-rw-r--r-- | libc/stdlib/random.c | 1 | ||||
-rw-r--r-- | libc/stdlib/realpath.c | 15 | ||||
-rw-r--r-- | libc/stdlib/setenv.c | 1 | ||||
-rw-r--r-- | libc/stdlib/system.c | 8 |
13 files changed, 48 insertions, 27 deletions
diff --git a/libc/stdlib/Makefile.in b/libc/stdlib/Makefile.in index f08e24795..2914d4ba6 100644 --- a/libc/stdlib/Makefile.in +++ b/libc/stdlib/Makefile.in @@ -11,7 +11,7 @@ include $(top_srcdir)libc/stdlib/malloc-standard/Makefile.in CSRC := \ abort.c getenv.c mkdtemp.c mktemp.c realpath.c mkstemp.c \ - rand.c random.c random_r.c setenv.c system.c div.c ldiv.c lldiv.c \ + rand.c random.c random_r.c setenv.c div.c ldiv.c lldiv.c \ getpt.c ptsname.c grantpt.c unlockpt.c drand48-iter.c jrand48.c \ jrand48_r.c lrand48.c lrand48_r.c mrand48.c mrand48_r.c nrand48.c \ nrand48_r.c rand_r.c srand48.c srand48_r.c seed48.c seed48_r.c \ @@ -80,9 +80,9 @@ STDLIB_SRC := $(patsubst %.c,$(STDLIB_DIR)/%.c,$(CSRC)) STDLIB_OBJ := $(patsubst %.c,$(STDLIB_OUT)/%.o,$(CSRC)) libc-y += $(STDLIB_OBJ) -libc-a-y += $(STDLIB_OBJ) -libc-so-y += $(STDLIB_OBJ:.o=.os) -libc-static-y += $(STDLIB_OUT)/atexit.o +libc-static-y += $(STDLIB_OUT)/atexit.o $(STDLIB_OUT)/system.o +libc-shared-y += $(STDLIB_OUT)/system.oS + # this should always be the PIC version, because it could be used in shared libs libc-nonshared-y += $(STDLIB_OUT)/atexit.os diff --git a/libc/stdlib/_atexit.c b/libc/stdlib/_atexit.c index 236156001..75fe41fa2 100644 --- a/libc/stdlib/_atexit.c +++ b/libc/stdlib/_atexit.c @@ -48,6 +48,7 @@ libc_hidden_proto(_exit) #ifdef __UCLIBC_HAS_THREADS__ # include <pthread.h> +# include <pthreadP.h> extern pthread_mutex_t mylock; #endif #define LOCK __pthread_mutex_lock(&mylock) diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c index e382cee55..a1c7b93c9 100644 --- a/libc/stdlib/malloc-simple/alloc.c +++ b/libc/stdlib/malloc-simple/alloc.c @@ -32,7 +32,8 @@ void *malloc(size_t size) size++; #else /* Some programs will call malloc (0). Lets be strict and return NULL */ - return 0; + __set_errno(ENOMEM); + return NULL; #endif } @@ -90,7 +91,8 @@ void *realloc(void *ptr, size_t size) newptr = malloc(size); if (newptr) { - memcpy(newptr, ptr, *((size_t *) (ptr - sizeof(size_t)))); + size_t old_size = *((size_t *) (ptr - sizeof(size_t))); + memcpy(newptr, ptr, (old_size < size ? old_size : size)); free(ptr); } return newptr; diff --git a/libc/stdlib/malloc-standard/Makefile.in b/libc/stdlib/malloc-standard/Makefile.in index e3ae73715..3bbe93e08 100644 --- a/libc/stdlib/malloc-standard/Makefile.in +++ b/libc/stdlib/malloc-standard/Makefile.in @@ -16,8 +16,6 @@ STDLIB_MALLOC_STANDARD_SRC := $(patsubst %.c,$(STDLIB_MALLOC_STANDARD_DIR)/%.c,$ STDLIB_MALLOC_STANDARD_OBJ := $(patsubst %.c,$(STDLIB_MALLOC_STANDARD_OUT)/%.o,$(CSRC)) libc-$(MALLOC_STANDARD) += $(STDLIB_MALLOC_STANDARD_OBJ) -libc-a-$(MALLOC_STANDARD) += $(STDLIB_MALLOC_STANDARD_OBJ) -libc-so-$(MALLOC_STANDARD) += $(STDLIB_MALLOC_STANDARD_OBJ:.o=.os) objclean-y += stdlib_malloc_standard_objclean diff --git a/libc/stdlib/malloc-standard/malloc.c b/libc/stdlib/malloc-standard/malloc.c index b4b1216ed..0dc208fb6 100644 --- a/libc/stdlib/malloc-standard/malloc.c +++ b/libc/stdlib/malloc-standard/malloc.c @@ -827,7 +827,10 @@ void* malloc(size_t bytes) void * sysmem; #if !defined(__MALLOC_GLIBC_COMPAT__) - if (!bytes) return NULL; + if (!bytes) { + __set_errno(ENOMEM); + return NULL; + } #endif LOCK; @@ -902,7 +905,7 @@ void* malloc(size_t bytes) else { idx = __malloc_largebin_index(nb); - if (have_fastchunks(av)) + if (have_fastchunks(av)) __malloc_consolidate(av); } diff --git a/libc/stdlib/malloc/heap_debug.c b/libc/stdlib/malloc/heap_debug.c index 9e5b61c43..e83831d3a 100644 --- a/libc/stdlib/malloc/heap_debug.c +++ b/libc/stdlib/malloc/heap_debug.c @@ -7,7 +7,7 @@ * This file is subject to the terms and conditions of the GNU Lesser * General Public License. See the file COPYING.LIB in the main * directory of this archive for more details. - * + * * Written by Miles Bader <miles@gnu.org> */ @@ -15,9 +15,11 @@ #include <stdio.h> #include <stdarg.h> #include <string.h> +#include <unistd.h> libc_hidden_proto(vfprintf) libc_hidden_proto(fprintf) +libc_hidden_proto(_exit) #include "malloc.h" #include "heap.h" @@ -66,7 +68,7 @@ __heap_dump (struct heap *heap, const char *str) /* Output an error message to stderr, and exit. STR is printed with the failure message. */ -static void +static void attribute_noreturn __heap_check_failure (struct heap *heap, struct heap_free_area *fa, const char *str, char *fmt, ...) { @@ -81,13 +83,13 @@ __heap_check_failure (struct heap *heap, struct heap_free_area *fa, vfprintf (stderr, fmt, val); va_end (val); - __putc ('\n', stderr); + fprintf (stderr, "\n"); __malloc_debug_set_indent (0); __malloc_debug_printf (1, "heap dump:"); __heap_dump_freelist (heap); - __exit (22); + _exit (22); } /* Do some consistency checks on HEAP. If they fail, output an error diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c index 2ec8b07da..770d7aea3 100644 --- a/libc/stdlib/malloc/malloc.c +++ b/libc/stdlib/malloc/malloc.c @@ -7,7 +7,7 @@ * This file is subject to the terms and conditions of the GNU Lesser * General Public License. See the file COPYING.LIB in the main * directory of this archive for more details. - * + * * Written by Miles Bader <miles@gnu.org> */ @@ -200,7 +200,7 @@ malloc (size_t size) #else /* Some programs will call malloc (0). Lets be strict and return NULL */ if (unlikely (size == 0)) - return 0; + goto oom; #endif /* Check if they are doing something dumb like malloc(-1) */ diff --git a/libc/stdlib/malloc/realloc.c b/libc/stdlib/malloc/realloc.c index 4d56565aa..ec57b874e 100644 --- a/libc/stdlib/malloc/realloc.c +++ b/libc/stdlib/malloc/realloc.c @@ -7,7 +7,7 @@ * This file is subject to the terms and conditions of the GNU Lesser * General Public License. See the file COPYING.LIB in the main * directory of this archive for more details. - * + * * Written by Miles Bader <miles@gnu.org> */ @@ -46,6 +46,11 @@ realloc (void *mem, size_t new_size) allocation unit (SIZE is already guaranteed to be so).*/ new_size = HEAP_ADJUST_SIZE (new_size + MALLOC_HEADER_SIZE); + if (new_size < sizeof (struct heap_free_area)) + /* Because we sometimes must use a freed block to hold a free-area node, + we must make sure that every allocated block can hold one. */ + new_size = HEAP_ADJUST_SIZE (sizeof (struct heap_free_area)); + MALLOC_DEBUG (1, "realloc: 0x%lx, %d (base = 0x%lx, total_size = %d)", (long)mem, new_size, (long)base_mem, size); diff --git a/libc/stdlib/mkdtemp.c b/libc/stdlib/mkdtemp.c index 20a2e16bc..6773a5bb3 100644 --- a/libc/stdlib/mkdtemp.c +++ b/libc/stdlib/mkdtemp.c @@ -30,9 +30,8 @@ char * mkdtemp (char *template) { if (__gen_tempname (template, __GT_DIR)) - /* We return the null string if we can't find a unique file name. */ - template[0] = '\0'; - + return NULL; + else return template; } #endif diff --git a/libc/stdlib/random.c b/libc/stdlib/random.c index 9f1977ee3..80df7890b 100644 --- a/libc/stdlib/random.c +++ b/libc/stdlib/random.c @@ -34,6 +34,7 @@ libc_hidden_proto(initstate_r) #ifdef __UCLIBC_HAS_THREADS__ # include <pthread.h> +# include <pthreadP.h> /* POSIX.1c requires that there is mutual exclusion for the `rand' and `srand' functions to prevent concurrent calls from modifying common data. */ diff --git a/libc/stdlib/realpath.c b/libc/stdlib/realpath.c index c3cc517de..aae8580a5 100644 --- a/libc/stdlib/realpath.c +++ b/libc/stdlib/realpath.c @@ -58,6 +58,14 @@ char resolved_path[]; int readlinks = 0; int n; + if (path == NULL) { + __set_errno(EINVAL); + return NULL; + } + if (*path == '\0') { + __set_errno(ENOENT); + return NULL; + } /* Make a copy of the source path since we may need to modify it. */ if (strlen(path) >= PATH_MAX - 2) { __set_errno(ENAMETOOLONG); @@ -66,15 +74,10 @@ char resolved_path[]; strcpy(copy_path, path); path = copy_path; max_path = copy_path + PATH_MAX - 2; - /* If it's a relative pathname use getwd for starters. */ + /* If it's a relative pathname use getcwd for starters. */ if (*path != '/') { /* Ohoo... */ -#define HAVE_GETCWD -#ifdef HAVE_GETCWD getcwd(new_path, PATH_MAX - 1); -#else - getwd(new_path); -#endif new_path += strlen(new_path); if (new_path[-1] != '/') *new_path++ = '/'; diff --git a/libc/stdlib/setenv.c b/libc/stdlib/setenv.c index fa61675fb..b2d807b50 100644 --- a/libc/stdlib/setenv.c +++ b/libc/stdlib/setenv.c @@ -34,6 +34,7 @@ libc_hidden_proto(unsetenv) #ifdef __UCLIBC_HAS_THREADS__ # include <pthread.h> +# include <pthreadP.h> static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; #endif #define LOCK __pthread_mutex_lock(&mylock) diff --git a/libc/stdlib/system.c b/libc/stdlib/system.c index 147ff5242..d1ff50f51 100644 --- a/libc/stdlib/system.c +++ b/libc/stdlib/system.c @@ -15,8 +15,8 @@ #ifdef __UCLIBC_HAS_THREADS_NATIVE__ #include <sched.h> #include <errno.h> -#include <sysdep-cancel.h> #include <bits/libc-lock.h> +#include <sysdep-cancel.h> #endif libc_hidden_proto(_exit) @@ -85,6 +85,10 @@ int __libc_system(const char *command) return. It might still be in the kernel when the cancellation request comes. Therefore we have to use the clone() calls ability to have the kernel write the PID into the user-level variable. */ + +libc_hidden_proto(sigaction) +libc_hidden_proto(waitpid) + #if defined __ia64__ # define FORK() \ INLINE_SYSCALL (clone2, 6, CLONE_PARENT_SETTID | SIGCHLD, NULL, 0, \ @@ -264,4 +268,6 @@ cancel_handler (void *arg) DO_UNLOCK (); } #endif +#ifdef IS_IN_libc weak_alias(__libc_system,system) +#endif |