Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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