aboutsummaryrefslogtreecommitdiff
path: root/scripts/realpath.c
blob: 15504a06c9f9cbfe736691edc3c3405edbe1a283 (plain) (blame)
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
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

/**
 * Apple loves being different. There's no `realpath` program on MacOS
 * @param argc
 * @param argv
 * @return
 */
int main(int argc, char *argv[]) {
    char *path;

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

    path = realpath(argv[1], NULL);
    if (path) {
        puts(path);
        free(path);
    } else {
        perror(argv[1]);
    }

    return errno;
}