From 5a86f58aaffc57ac9b797e6a9300761085fcb5ee Mon Sep 17 00:00:00 2001 From: janbodnar Date: Sun, 31 Jan 2016 13:55:17 +0100 Subject: [PATCH] Create current_directory.c --- system/current_directory.c | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 system/current_directory.c diff --git a/system/current_directory.c b/system/current_directory.c new file mode 100644 index 0000000..aa04bba --- /dev/null +++ b/system/current_directory.c @@ -0,0 +1,41 @@ +#include +#include + +#define BUFSIZE MAX_PATH + +int wmain(int argc, wchar_t **argv) { + + wchar_t buf[BUFSIZE]; + + if(argc != 2) { + + wprintf(L"Usage: %ls \n", argv[0]); + return 1; + } + + DWORD dwRet = SetCurrentDirectoryW(argv[1]); + + if (dwRet == 0) { + + wprintf(L"SetCurrentDirectoryW() failed (%ld)\n", GetLastError()); + return 1; + } + + dwRet = GetCurrentDirectoryW(BUFSIZE, buf); + + if (dwRet == 0) { + + wprintf(L"GetCurrentDirectoryW() failed (%ld)\n", GetLastError()); + return 1; + } + + if (dwRet > BUFSIZE) { + + wprintf(L"Buffer too small; needs %d characters\n", dwRet); + return 1; + } + + wprintf(L"Current directory is: %ls\n", buf); + + return 0; +}