summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/getdents.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2010-07-27 01:48:22 -0400
committerMike Frysinger <vapier@gentoo.org>2010-07-27 14:33:42 -0400
commitfd826c72f8362d054c2d0064bff2b0830d2f29d1 (patch)
treef8f866fadc5cf38cc1883c348e8bdc1cad4b0691 /libc/sysdeps/linux/common/getdents.c
parent4e38c284bc8b3bff95543f246f3e0d3ee5a045ab (diff)
new helper funcs for alloca/malloc with mmu/nommu
The rpc rcmd code has some ugly ifdef mazes to handle mmu/nommu differences just to select alloca or malloc. Unify those with some helper macros in a new header, and then convert the rcmd code over to it. This is all geared towards fixing the getdents helper functions which only use alloca() atm. Now that we have helper functions, convert the getdents functions over too. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Reviewed-by: Steven J. Magnani <steve@digidescorp.com>
Diffstat (limited to 'libc/sysdeps/linux/common/getdents.c')
-rw-r--r--libc/sysdeps/linux/common/getdents.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/libc/sysdeps/linux/common/getdents.c b/libc/sysdeps/linux/common/getdents.c
index 5dda190a8..46f7b8e16 100644
--- a/libc/sysdeps/linux/common/getdents.c
+++ b/libc/sysdeps/linux/common/getdents.c
@@ -4,7 +4,6 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include <alloca.h>
#include <assert.h>
#include <errno.h>
#include <dirent.h>
@@ -17,6 +16,7 @@
#include <sys/syscall.h>
#include <bits/kernel_types.h>
#include <bits/kernel-features.h>
+#include <bits/uClibc_alloc.h>
#if !(defined __UCLIBC_HAS_LFS__ && defined __NR_getdents64 && __WORDSIZE == 64)
/* If the condition above is met, __getdents is defined as an alias
@@ -93,11 +93,13 @@ ssize_t __getdents (int fd, char *buf, size_t nbytes)
nbytes - size_diff);
dp = (struct dirent *) buf;
- skdp = kdp = alloca (red_nbytes);
+ skdp = kdp = stack_heap_alloc(red_nbytes);
retval = __syscall_getdents(fd, (unsigned char *)kdp, red_nbytes);
- if (retval == -1)
+ if (retval == -1) {
+ stack_heap_free(skdp);
return -1;
+ }
while ((char *) kdp < (char *) skdp + retval) {
const size_t alignment = __alignof__ (struct dirent);
@@ -114,6 +116,7 @@ ssize_t __getdents (int fd, char *buf, size_t nbytes)
if ((char *) dp == buf) {
/* The buffer the user passed in is too small to hold even
one entry. */
+ stack_heap_free(skdp);
__set_errno (EINVAL);
return -1;
}
@@ -130,6 +133,7 @@ ssize_t __getdents (int fd, char *buf, size_t nbytes)
dp = (struct dirent *) ((char *) dp + new_reclen);
kdp = (struct kernel_dirent *) (((char *) kdp) + kdp->d_reclen);
}
+ stack_heap_free(skdp);
return (char *) dp - buf;
}