File: readlink.c

package info (click to toggle)
klibc 1.5.20-1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 5,104 kB
  • ctags: 7,234
  • sloc: ansic: 46,580; asm: 2,343; perl: 758; makefile: 170; sh: 141
file content (37 lines) | stat: -rw-r--r-- 534 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>

char *progname;

static __noreturn usage(void)
{
	fprintf(stderr, "Usage: %s link\n", progname);
	exit(1);
}

int main(int argc, char *argv[])
{
	char *name, *link_name = NULL;
	size_t max_siz = 128;

	progname = *argv++;

	name = *argv++;
	if (!name)
		usage();

	link_name = malloc(max_siz);
	if (!link_name) {
		perror("malloc");
		exit(1);
	}

	if (readlink(name, link_name, max_siz) == -1) {
		exit(1);
	}
	printf("%s\n", link_name);

	exit(0);
}