Magellan Linux

Contents of /trunk/mkinitrd-magellan/klibc/usr/utils/readlink.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 531 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 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <sys/stat.h>
5
6 char *progname;
7
8 static __noreturn usage(void)
9 {
10 fprintf(stderr, "Usage: %s link\n", progname);
11 exit(1);
12 }
13
14 int main(int argc, char *argv[])
15 {
16 char *name, *link = NULL;
17 size_t max_siz = 128;
18
19 progname = *argv++;
20
21 name = *argv++;
22 if (!name)
23 usage();
24
25 link = malloc(max_siz);
26 if (!link) {
27 perror("malloc");
28 exit(1);
29 }
30
31 if (readlink(name, link, max_siz) == -1) {
32 perror("readlink");
33 exit(1);
34 }
35 printf("%s\n", link);
36
37 exit(0);
38 }