Contents of /trunk/mkinitrd-magellan/busybox/debianutils/readlink.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (17 years ago) by niro
File MIME type: text/plain
File size: 1061 byte(s)
Sat Sep 1 22:45:15 2007 UTC (17 years ago) by niro
File MIME type: text/plain
File size: 1061 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | /* vi: set sw=4 ts=4: */ |
2 | /* |
3 | * Mini readlink implementation for busybox |
4 | * |
5 | * Copyright (C) 2000,2001 Matt Kraai <kraai@alumni.carnegiemellon.edu> |
6 | * |
7 | * Licensed under GPL v2 or later, see file LICENSE in this tarball for details. |
8 | */ |
9 | |
10 | #include "busybox.h" |
11 | #include <errno.h> |
12 | #include <unistd.h> |
13 | #include <stdlib.h> |
14 | #include <getopt.h> |
15 | |
16 | int readlink_main(int argc, char **argv) |
17 | { |
18 | char *buf; |
19 | char *fname; |
20 | |
21 | USE_FEATURE_READLINK_FOLLOW( |
22 | unsigned opt; |
23 | /* We need exactly one non-option argument. */ |
24 | opt_complementary = "=1"; |
25 | opt = getopt32(argc, argv, "f"); |
26 | fname = argv[optind]; |
27 | ) |
28 | SKIP_FEATURE_READLINK_FOLLOW( |
29 | const unsigned opt = 0; |
30 | if (argc != 2) bb_show_usage(); |
31 | fname = argv[1]; |
32 | ) |
33 | |
34 | /* compat: coreutils readlink reports errors silently via exit code */ |
35 | logmode = LOGMODE_NONE; |
36 | |
37 | if (opt) { |
38 | buf = realpath(fname, bb_common_bufsiz1); |
39 | } else { |
40 | buf = xreadlink(fname); |
41 | } |
42 | |
43 | if (!buf) |
44 | return EXIT_FAILURE; |
45 | puts(buf); |
46 | |
47 | if (ENABLE_FEATURE_CLEAN_UP && buf != bb_common_bufsiz1) |
48 | free(buf); |
49 | |
50 | fflush_stdout_and_exit(EXIT_SUCCESS); |
51 | } |