Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1122 - (show annotations) (download)
Wed Aug 18 21:11:40 2010 UTC (13 years, 8 months ago) by niro
File MIME type: text/plain
File size: 534 byte(s)
-updated to klibc-1.5.19
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_name = NULL;
17 size_t max_siz = 128;
18
19 progname = *argv++;
20
21 name = *argv++;
22 if (!name)
23 usage();
24
25 link_name = malloc(max_siz);
26 if (!link_name) {
27 perror("malloc");
28 exit(1);
29 }
30
31 if (readlink(name, link_name, max_siz) == -1) {
32 exit(1);
33 }
34 printf("%s\n", link_name);
35
36 exit(0);
37 }