-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrealpath.cpp
More file actions
90 lines (70 loc) · 1.88 KB
/
Copy pathrealpath.cpp
File metadata and controls
90 lines (70 loc) · 1.88 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stlsoft/stlsoft.h>
#if _STLSOFT_VER < 0x010b0184
# error requires STLSoft v1.11.1-b4 or later
#endif
#if __cplusplus < 201702L
# error requires C++17 or later
#endif
#include <platformstl/filesystem/path_functions.h>
#include <winstl/error/error_desc.hpp>
#include <winstl/filesystem/absolute_path.hpp>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define REALPATH_VER_MAJOR 0
#define REALPATH_VER_MINOR 0
#define REALPATH_VER_PATCH 3
int main(int argc, char* argv[])
{
auto const program_name = platformstl::get_executable_name_from_path(argv[0]);
switch (argc)
{
case 2:
if (0 == std::strcmp("--help", argv[1]))
{
std::cout
<< "USAGE: "
<< program_name
<< " <relative-path>"
<< std::endl;
return EXIT_SUCCESS;
}
else
{
winstl::absolute_path abs_path(argv[1]);
if (0 == abs_path.length())
{
winstl::error_desc ed;
std::cerr
<< program_name
<< ": failed to obtain absolute path for '"
<< argv[1]
<< "': "
<< ed
<< std::endl;
return EXIT_FAILURE;
}
else
{
std::cout
<< abs_path
<< std::endl;
return EXIT_SUCCESS;
}
}
break;
case 1:
std::cerr
<< program_name
<< ": no name specified; use --help for usage"
<< std::endl;
return EXIT_FAILURE;
default:
std::cerr
<< program_name
<< ": too many arguments; use --help for usage"
<< std::endl;
return EXIT_FAILURE;
}
}