summaryrefslogtreecommitdiff
path: root/support/dktools/dk4getcwdw.ctr
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/dktools/dk4getcwdw.ctr
Initial commit
Diffstat (limited to 'support/dktools/dk4getcwdw.ctr')
-rw-r--r--support/dktools/dk4getcwdw.ctr140
1 files changed, 140 insertions, 0 deletions
diff --git a/support/dktools/dk4getcwdw.ctr b/support/dktools/dk4getcwdw.ctr
new file mode 100644
index 0000000000..1cce43f1e7
--- /dev/null
+++ b/support/dktools/dk4getcwdw.ctr
@@ -0,0 +1,140 @@
+%% options
+
+copyright owner = Dirk Krause
+copyright year = 2015-xxxx
+license = bsd
+
+
+
+%% header
+
+/** @file dk4getcwdw.h Get working directroy in wchar_t.
+*/
+
+
+#ifndef DK4ERROR_H_INCLUDED
+#include "dk4error.h"
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/** Find current working directory.
+ @param dptr Destination buffer pointer.
+ @param sz Buffer size (Number of wchar_t).
+ @param erp Error report, may be NULL.
+ @return 1 on success, 0 on error.
+*/
+int
+dk4getcwd_wc(wchar_t *dptr, size_t sz, dk4_er_t *erp);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+%% module
+
+#include "dk4getcwd8.h"
+
+#if DK4_ON_WINDOWS
+#ifndef WINDOWS_H_INCLUDED
+#include <windows.h>
+#define WINDOWS_H_INCLUDED 1
+#endif
+#endif
+
+#if DK4_HAVE_UNISTD_H
+#ifndef UNISTD_H_INCLUDED
+#include <unistd.h>
+#define UNISTD_H_INCLUDED 1
+#endif
+#endif
+
+#if DK4_HAVE_STDLIB_H
+#ifndef STDLIB_H_INCLUDED
+#include <stdlib.h>
+#define STDLIB_H_INCLUDED 1
+#endif
+#endif
+
+#if DK4_HAVE_ERRNO_H
+#ifndef ERRNO_H_INCLUDED
+#include <errno.h>
+#define ERRNO_H_INCLUDED 1
+#endif
+#endif
+
+#if DK4_HAVE_DIRECT_H
+#ifndef DIRECT_H_INCLUDED
+#include <direct.h>
+#define DIRECT_H_INCLUDED 1
+#endif
+#endif
+
+
+
+$!trace-include
+
+
+int
+dk4getcwd_wc(wchar_t *dptr, size_t sz, dk4_er_t *erp)
+{
+ int back = 0;
+ if ((NULL != dptr) && (0 < sz)) {
+#if DK4_ON_WINDOWS
+#if DK4_WIN_AVOID_CRT || DK4_WIN_DENY_CRT
+ DWORD dwSz;
+ DWORD dwRes;
+ dwSz = (DWORD)sz;
+ if ((dk4_um_t)sz > (dk4_um_t)0xFFFFFFUL) { dwSz = (DWORD)0xFFFFFFFFUL; }
+ dwRes = GetCurrentDirectoryW(dwSz, dptr);
+ if (0 < dwRes) {
+ if (dwRes < dwSz) {
+ back = 1;
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_BUFFER_TOO_SMALL);
+ }
+ } else {
+ dk4error_set_ldetails(erp, DK4_E_SYSTEM, GetLastError());
+ }
+#else
+#if DK4_HAVE__WGETCWD
+ int isz;
+ errno = 0;
+ isz = (int)sz;
+ if ((dk4_um_t)sz > (dk4_um_t)(INT_MAX)) { isz = INT_MAX; }
+ if (NULL != _wgetcwd(dptr, isz)) {
+ back = 1;
+ } else {
+ dk4error_set_idetails(erp, DK4_E_SYSTEM, errno);
+ }
+#else
+ DWORD dwSz;
+ DWORD dwRes;
+ dwSz = (DWORD)sz;
+ if ((dk4_um_t)sz > (dk4_um_t)0xFFFFFFUL) { dwSz = (DWORD)0xFFFFFFFFUL; }
+ dwRes = GetCurrentDirectoryW(dwSz, dptr);
+ if (0 < dwRes) {
+ if (dwRes < dwSz) {
+ back = 1;
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_BUFFER_TOO_SMALL);
+ }
+ } else {
+ dk4error_set_ldetails(erp, DK4_E_SYSTEM, GetLastError());
+ }
+#endif
+#endif
+#else
+ dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED);
+#endif
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
+ }
+ return back;
+}
+