On Tue, Oct 27, 2009 at 08:54:50AM +0100, Ricard Wanderlof wrote:
>
>On Mon, 26 Oct 2009, Rob Landley wrote:
>
>>... Also, in my experience _Bool is about as real-world useful as
>>the bit field notation with the colons, and is really there to keep
>>the language pedants and the c++ guys happy without actually
>>accomplishing much. I've never seen it actually produce better
>>code.
>
>It can produce more readable, less error-prone C code though. We use
$ size libc/stdlib/realpath.o*
text data bss dec hex filename
555 0 0 555 22b libc/stdlib/realpath.os.oorig
735 0 0 735 2df libc/stdlib/realpath.os.rob
586 0 0 586 24a libc/stdlib/realpath.os
perhaps that would do as well and doesn't cost 180b (!) but about 31b..
diff --git a/include/stdlib.h b/include/stdlib.h
index e462c1c..6268995 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -659,7 +659,6 @@ extern char *canonicalize_file_name (__const char *__name)
__THROW __nonnull ((1)) __wur;
#endif
-#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
/* Return the canonical absolute name of file NAME. If RESOLVED is
null, the result is malloc'd; otherwise, if the canonical name is
PATH_MAX chars or more, returns null with `errno' set to
@@ -667,9 +666,7 @@ extern char *canonicalize_file_name (__const char *__name)
returns the name in RESOLVED. */
/* we choose to handle __resolved==NULL as crash :) */
extern char *realpath (__const char *__restrict __name,
- char *__restrict __resolved) __THROW __wur __nonnull((2));
-#endif
-
+ char *__restrict __resolved) __THROW __wur;
/* Shorthand for type of comparison functions. */
#ifndef __COMPAR_FN_T
diff --git a/libc/stdlib/realpath.c b/libc/stdlib/realpath.c
index 1a00c31..668cff6 100644
--- a/libc/stdlib/realpath.c
+++ b/libc/stdlib/realpath.c
@@ -36,13 +36,7 @@
#define MAX_READLINKS 32
-#ifdef __STDC__
char *realpath(const char *path, char got_path[])
-#else
-char *realpath(path, got_path)
-const char *path;
-char got_path[];
-#endif
{
char copy_path[PATH_MAX];
/* use user supplied buffer directly - reduces stack usage */
@@ -63,6 +57,12 @@ char got_path[];
__set_errno(ENOENT);
return NULL;
}
+ /* If got_path is NULL then we need to allocate it (SUSv4 base).
+ * Instead of guesstimating the exact length or realloc()ing
+ * to the later to be found real length we hand back a PATH_MAX
+ * buffer to the lazy. */
+ if (got_path == NULL)
+ got_path = malloc(PATH_MAX);
/* Make a copy of the source path since we may need to modify it. */
path_len = strlen(path);
if (path_len >= PATH_MAX - 2) {
_______________________________________________
uClibc mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/uclibc