source: branches/2.2.2/mindi-busybox/debianutils/readlink.c @ 1247

Last change on this file since 1247 was 821, checked in by Bruno Cornec, 14 years ago

Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)

File size: 903 bytes
Line 
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, 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#define READLINK_FLAG_f (1 << 0)
17
18int readlink_main(int argc, char **argv)
19{
20    char *buf;
21    unsigned long opt = ENABLE_FEATURE_READLINK_FOLLOW ?
22                            bb_getopt_ulflags(argc, argv, "f") : 0;
23
24    if (argc != (ENABLE_FEATURE_READLINK_FOLLOW ? optind + 1 : 2))
25            bb_show_usage();
26
27    if (opt & READLINK_FLAG_f)
28        buf = realpath(argv[optind], bb_common_bufsiz1);
29    else
30        buf = xreadlink(argv[ENABLE_FEATURE_READLINK_FOLLOW ? optind : 1]);
31
32    if (!buf)
33        return EXIT_FAILURE;
34    puts(buf);
35
36    if (ENABLE_FEATURE_CLEAN_UP && buf != bb_common_bufsiz1)
37        free(buf);
38
39    return EXIT_SUCCESS;
40}
Note: See TracBrowser for help on using the repository browser.