Another update from Larry:
[oweals/busybox.git] / readlink.c
index c82f64027c292e82662c4745c67d1ab59d980bb9..226649544c1e6b0fe28a0c7e46b5fe3d56043567 100644 (file)
  *
  */
 
-#include "busybox.h"
 #include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include "busybox.h"
 
 int readlink_main(int argc, char **argv)
 {
        char *buf = NULL;
-       int bufsize = 128, size = 128;
+
+       /* no options, no getopt */
 
        if (argc != 2)
                show_usage();
 
-       while (bufsize < size + 1) {
-               bufsize *= 2;
-               buf = xrealloc(buf, bufsize);
-               size = readlink(argv[1], buf, bufsize);
-               if (size == -1)
-                       perror_msg_and_die("%s", argv[1]);
-       }
-
-       buf[size] = '\0';
+       buf = xreadlink(argv[1]);
        puts(buf);
+#ifdef BB_FEATURE_CLEAN_UP
+       free(buf);
+#endif
 
        return EXIT_SUCCESS;
 }