File tree 3 files changed +27
-0
lines changed
3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,10 @@ def cwd() -> str:
53
53
free(path);
54
54
return value"""
55
55
56
+ @nativedefine("yk__change_current_dir_path")
57
+ def chdir(path: str) -> bool:
58
+ # Change current working directory
59
+ pass
56
60
57
61
@nativedefine("struct yk__process_result*")
58
62
class ProcessResult:
Original file line number Diff line number Diff line change @@ -132,9 +132,11 @@ void yk__printlnstr(const char *str) {
132
132
#if defined(_WIN32 ) || defined(_WIN64 )
133
133
#include <direct.h>
134
134
#define GetCurrentDir _wgetcwd
135
+ #define ChangeDirectory _wchdir
135
136
#else
136
137
#include <unistd.h>
137
138
#define GetCurrentDir getcwd
139
+ #define ChangeDirectory chdir
138
140
#endif
139
141
char * yk__get_current_dir_path () {
140
142
#if defined(_WIN32 ) || defined(_WIN64 )
@@ -157,6 +159,26 @@ char *yk__get_current_dir_path() {
157
159
return buff ;
158
160
#endif
159
161
}
162
+ bool yk__change_current_dir_path (yk__sds path ) {
163
+ if (path == NULL || !yk__sdslen (path )) {
164
+ yk__sdsfree (path );
165
+ return false;
166
+ }
167
+ #if defined(_WIN32 ) || defined(_WIN64 )
168
+ wchar_t * wpath = yk__utf8_to_utf16_null_terminated (path );
169
+ if (wpath == NULL ) {
170
+ return false;
171
+ }
172
+ int result = ChangeDirectory (wpath );
173
+ yk__sdsfree (path );
174
+ free (wpath );
175
+ return result == 0 ;
176
+ #else
177
+ int result = ChangeDirectory (path );
178
+ yk__sdsfree (path );
179
+ return result == 0 ;
180
+ #endif
181
+ }
160
182
////// File stuff ///////////
161
183
bool yk__exists (yk__sds path ) {
162
184
if (path == NULL || !yk__sdslen (path )) {
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ void yk__printlnuint(uintmax_t to_print);
21
21
void yk__printdbl (double to_print );
22
22
void yk__printlndbl (double to_print );
23
23
char * yk__get_current_dir_path ();
24
+ bool yk__change_current_dir_path (yk__sds path );
24
25
bool yk__exists (yk__sds path );
25
26
bool yk__readable (yk__sds path );
26
27
bool yk__writable (yk__sds path );
You can’t perform that action at this time.
0 commit comments