Changed gz_open to ruturn a stream
[oweals/busybox.git] / readlink.c
index 98f1dea4fe28c2f14ac1c1a16145707d7b96f8e6..c46ebd108198be9514dee6ee32da5756630dd0dd 100644 (file)
@@ -3,7 +3,7 @@
  * Mini readlink implementation for busybox
  *
  *
- * Copyright (C) 2000 by Lineo, inc.
+ * Copyright (C) 1999,2000,2001 by Lineo, inc.
  * Written by Matt Kraai <kraai@alumni.carnegiemellon.edu>
  *
  * This program is free software; you can redistribute it and/or modify
  *
  */
 
-#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;
 
-       if (argc != 2)
-               usage(readlink_usage);
+       /* no options, no getopt */
 
-       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]);
-       }
+       if (argc != 2)
+               show_usage();
 
-       buf[size] = '\0';
+       buf = xreadlink(argv[1]);
+       if (!buf)
+               return EXIT_FAILURE;
        puts(buf);
+#ifdef BB_FEATURE_CLEAN_UP
+       free(buf);
+#endif
 
        return EXIT_SUCCESS;
 }