|
| 1 | +// Copyright (C) 2018 Google Inc. |
| 2 | +// |
| 3 | +// This program is free software; you can redistribute it and/or modify |
| 4 | +// it under the terms of the GNU General Public License as published by |
| 5 | +// the Free Software Foundation; either version 2 of the License, or |
| 6 | +// (at your option) any later version. |
| 7 | +// |
| 8 | +// This program is distributed in the hope that it will be useful, |
| 9 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +// GNU General Public License for more details. |
| 12 | +// |
| 13 | +// You should have received a copy of the GNU General Public License along |
| 14 | +// with this program; if not, write to the Free Software Foundation, Inc., |
| 15 | +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | +// |
| 17 | +//////////////////////////////////////////////////////////////////////////////// |
| 18 | +// |
| 19 | +// A minimal driver for Posix realpath(). Not every Posix system supplies such |
| 20 | +// a driver, and even on those that do it might require a separate installation |
| 21 | +// step. This implements the equivalent of "realpath -e" on Linux. |
| 22 | + |
| 23 | +#include <errno.h> |
| 24 | +#include <stdio.h> |
| 25 | +#include <stdlib.h> |
| 26 | +#include <string.h> |
| 27 | + |
| 28 | +int main(int argc, char* argv[]) { |
| 29 | + int num_errors = 0; |
| 30 | + errno = 0; |
| 31 | + |
| 32 | + for (int i = 1; i < argc; ++i) { |
| 33 | + char* p = realpath(argv[i], NULL); |
| 34 | + if (p == NULL) { |
| 35 | + fprintf(stderr, "Error resolving path '%s', error was: '%s'\n", |
| 36 | + argv[i], strerror(errno)); |
| 37 | + errno = 0; |
| 38 | + ++num_errors; |
| 39 | + } else { |
| 40 | + fprintf(stdout, "%s\n", p); |
| 41 | + free(p); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + return num_errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE; |
| 46 | +} |
0 commit comments