File: realpath.c

package info (click to toggle)
dwww 1.4.3.4-0.2
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 360 kB
  • ctags: 171
  • sloc: sh: 939; ansic: 879; perl: 617; makefile: 93
file content (34 lines) | stat: -rw-r--r-- 529 bytes parent folder | download | duplicates (2)
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
/*
 * realpath.c -- output the real path of a filename.
 * Lars Wirzenius.
 */
 
#include <sys/param.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char **argv) {
	char buf[10240];
	int i;

	if (argc != 2) {
		fprintf(stderr, "usage: %s filename ...\n", argv[0]);
		return 1;
	}

	for (i = 1; i < argc; ++i) {	
		if (realpath(argv[i], buf) == NULL) {
			perror("realpath");
			return 1;
		}
		
		printf("%s\n", buf);
		fflush(stdout);
		if (ferror(stdout)) {
			perror("stdout");
			return 1;
		}
	}

	return 0;
}