Set version to 3.24.0-RC1
[valgrind.git] / memcheck / tests / freebsd / bug470713.cpp
blobe07dba76b5a9f9d4a06966afb5c7050e1ae61d83
1 // roughly based on the code for Firefox class BinaryPath
2 // https://searchfox.org/mozilla-central/source/xpcom/build/BinaryPath.h#185
4 #include <iostream>
5 #include <sys/types.h>
6 #include <sys/sysctl.h>
7 #include <limits.h>
8 #include <string>
9 #include <memory>
10 #include <cstring>
12 using std::cerr;
13 using std::cout;
14 using std::string;
16 int main(int argc, char **argv)
18 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
19 size_t len;
21 if (sysctl(mib, 4, NULL, &len, NULL, 0) != 0) {
22 cout << "sysctl failed to get path length: " << std::strerror(errno) << '\n';
23 return -1;
26 std::unique_ptr<char[]> aResult(new char[len]);
28 if (sysctl(mib, 4, aResult.get(), &len, NULL, 0) != 0) {
29 cout << "sysctl failed to get path: " << strerror(errno) << '\n';
30 return -1;
33 if (string(aResult.get()) == argv[1]) {
34 cout << "OK\n";
35 } else {
36 cout << "Not OK aResult " << aResult.get() << " argv[1] " << argv[1] << '\n';
39 if (sysctl(mib, 4, NULL, NULL, NULL, 0) != -1) {
40 cout << "OK syscall failed\n";
41 return -1;
42 } else {
43 cout << "sysctl succeeded when it should have failed\n";