summaryrefslogtreecommitdiffstats
path: root/Tests/TestsWorkingDirectory/main.c
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2010-12-17 17:28:33 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2010-12-17 17:34:20 (GMT)
commit96309fc6e2439ede2604fc18ad04e82ffc54b606 (patch)
tree68bdee31c1ec85343ccf7d452e7e58db9668b74a /Tests/TestsWorkingDirectory/main.c
parenta4a5e375685adcfe765c45be086706720a96dbea (diff)
downloadCMake-96309fc6e2439ede2604fc18ad04e82ffc54b606.zip
CMake-96309fc6e2439ede2604fc18ad04e82ffc54b606.tar.gz
CMake-96309fc6e2439ede2604fc18ad04e82ffc54b606.tar.bz2
Make TestsWorkingDirectory test a C file
Diffstat (limited to 'Tests/TestsWorkingDirectory/main.c')
-rw-r--r--Tests/TestsWorkingDirectory/main.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/Tests/TestsWorkingDirectory/main.c b/Tests/TestsWorkingDirectory/main.c
new file mode 100644
index 0000000..ad5eb30
--- /dev/null
+++ b/Tests/TestsWorkingDirectory/main.c
@@ -0,0 +1,66 @@
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__))
+
+#include <io.h>
+#include <direct.h>
+
+#if defined(__WATCOMC__)
+#include <direct.h>
+#define _getcwd getcwd
+#endif
+
+static const char* Getcwd(char* buf, unsigned int len)
+{
+ const char* ret = _getcwd(buf, len);
+ char* p = NULL;
+ if(!ret)
+ {
+ fprintf(stderr, "No current working directory.\n");
+ abort();
+ }
+ // make sure the drive letter is capital
+ if(strlen(buf) > 1 && buf[1] == ':')
+ {
+ buf[0] = toupper(buf[0]);
+ }
+ for(p = buf; *p; ++p)
+ {
+ if(*p == '\\')
+ {
+ *p = '/';
+ }
+ }
+ return ret;
+}
+
+#else
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+static const char* Getcwd(char* buf, unsigned int len)
+{
+ const char* ret = getcwd(buf, len);
+ if(!ret)
+ {
+ fprintf(stderr, "No current working directory\n");
+ abort();
+ }
+ return ret;
+}
+
+#endif
+
+int main(int argc, char *argv[])
+{
+ char buf[2048];
+ const char *cwd = Getcwd(buf, sizeof(buf));
+
+ fprintf(stdout, "Working directory: -->%s<--", cwd);
+
+ return 0;
+}