1 /*
2 Copyright (C) 2019-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5 
6 /*
7 	WARNING: This file was generated by the dkct program (see
8 	http://dktools.sourceforge.net/ for details).
9 	Changes you make here will be lost if dkct is run again!
10 	You should modify the original source and run dkct on it.
11 	Original source: dk4chdir8.ctr
12 */
13 
14 /**	@file dk4chdir8.c The dk4chdir8 module.
15 */
16 
17 
18 
19 #include "dk4conf.h"
20 #include <libdk4c/dk4chdir8.h>
21 
22 
23 #if DK4_ON_WINDOWS
24 #ifndef WINDOWS_H_INCLUDED
25 #include <windows.h>
26 #define	WINDOWS_H_INCLUDED 1
27 #endif
28 #endif
29 
30 #if DK4_HAVE_UNISTD_H
31 #ifndef UNISTD_H_INCLUDED
32 #include <unistd.h>
33 #define	UNISTD_H_INCLUDED 1
34 #endif
35 #endif
36 
37 #if DK4_HAVE_STDLIB_H
38 #ifndef STDLIB_H_INCLUDED
39 #include <stdlib.h>
40 #define	STDLIB_H_INCLUDED 1
41 #endif
42 #endif
43 
44 #if DK4_HAVE_DIRECT_H
45 #ifndef DIRECT_H_INCLUDED
46 #include <direct.h>
47 #define DIRECT_H_INCLUDED 1
48 #endif
49 #endif
50 
51 #if DK4_HAVE_ERRNO_H
52 #ifndef ERRNO_H_INCLUDED
53 #include <errno.h>
54 #define	ERRNO_H_INCLUDED 1
55 #endif
56 #endif
57 
58 #if	DK4_HAVE_ASSERT_H
59 #ifndef	ASSERT_H_INCLUDED
60 #include <assert.h>
61 #define	ASSERT_H_INCLUDED 1
62 #endif
63 #endif
64 
65 
66 
67 
68 
69 
70 
71 int
72 
dk4chdir_c8(const char * nd,dk4_er_t * erp)73 dk4chdir_c8(const char *nd, dk4_er_t *erp)
74 {
75 	int			 back	= 0;
76 #if	DK4_ON_WINDOWS && (DK4_WIN_AVOID_CRT || DK4_WIN_DENY_CRT)
77 	BOOL		 res;
78 #endif
79 
80 #if	DK4_USE_ASSERT
81   assert(NULL != nd);
82 #endif
83 	if (NULL != nd) {
84 #if	DK4_ON_WINDOWS
85 #if	DK4_WIN_AVOID_CRT || DK4_WIN_DENY_CRT
86 		res = SetCurrentDirectoryA(nd);
87 		if (res) {
88 			back = 1;
89 		}
90 		else {
91 			dk4error_set_ldetails(erp, DK4_E_SYSTEM, GetLastError());
92 		}
93 #else
94 		if (0 == _chdir(nd)) {
95 			back = 1;
96 		}
97 		else {
98 			dk4error_set_idetails(erp, DK4_E_SYSTEM, errno);
99 		}
100 #endif
101 #else
102 		if (0 == chdir(nd)) {
103 			back = 1;
104 		}
105 		else {
106 			dk4error_set_idetails(erp, DK4_E_SYSTEM, errno);
107 		}
108 #endif
109 	}
110 	else {
111 		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
112 	}
113 
114 	return back;
115 }
116 
117 
118 
119 /* vim: set ai sw=4 ts=4 : */
120