File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ #include <limits.h>
12#include <stddef.h>
3+ #include <stdlib.h>
24#include <sys/stat.h>
35#include <sys/types.h>
46#include <string.h>
@@ -44,3 +46,43 @@ int stdlib_remove_directory(const char* path){
4446
4547 return (!code ) ? 0 : errno ;
4648}
49+
50+ char * stdlib_get_cwd (size_t * len , int * stat ){
51+ * stat = 0 ;
52+ #ifdef _WIN32
53+ char * buffer ;
54+ buffer = _getcwd (NULL , 0 );
55+
56+ if (buffer == NULL ) {
57+ * stat = errno ;
58+ return NULL ;
59+ }
60+
61+ * len = strlen (buffer )
62+ return buffer ;
63+ #else
64+ char buffer [PATH_MAX + 1 ];
65+ if (!getcwd (buffer , sizeof (buffer ))) {
66+ * stat = errno ;
67+ }
68+
69+ * len = strlen (buffer );
70+
71+ char * res = malloc (* len );
72+ strncpy (res , buffer , * len );
73+
74+ return res ;
75+ #endif /* ifdef _WIN32 */
76+ }
77+
78+ int stdlib_set_cwd (char * path ) {
79+ int code ;
80+ #ifdef _WIN32
81+ code = _chdir (path );
82+ #else
83+ code = chdir (path );
84+ #endif /* ifdef _WIN32 */
85+
86+ if (code == -1 ) return errno ;
87+ return 0 ;
88+ }
You can’t perform that action at this time.
0 commit comments