File: readlink.c

package info (click to toggle)
care 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch, trixie
  • size: 1,716 kB
  • sloc: ansic: 15,436; sh: 1,195; makefile: 6
file content (27 lines) | stat: -rw-r--r-- 550 bytes parent folder | download | duplicates (4)
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
#include <unistd.h> /* syscall(2), */
#include <stdio.h>  /* perror(3), fprintf(3), */
#include <limits.h> /* PATH_MAX, */
#include <stdlib.h> /* exit(3), */
#include <sys/syscall.h> /* SYS_readlink, */

int main(int argc, char *argv[])
{
	char path[PATH_MAX];
	int status;

	if (argc != 2) {
		fprintf(stderr, "usage: readlink FILE\n");
		exit(EXIT_FAILURE);
	}

	status = syscall(SYS_readlink, argv[1], path, PATH_MAX);
	if (status < 0) {
		perror("readlink()");
		exit(EXIT_FAILURE);
	}
	path[status] = '\0';

	puts(path);

	exit(EXIT_SUCCESS);
}