File tree 2 files changed +27
-11
lines changed
2 files changed +27
-11
lines changed Original file line number Diff line number Diff line change 47
47
#include < unistd.h> /* setuid, getuid */
48
48
#else
49
49
#include < direct.h>
50
- #define chdir _chdir
51
- #define getcwd _getcwd
52
50
#include < process.h>
53
51
#define getpid _getpid
54
52
#include < io.h>
@@ -1231,10 +1229,10 @@ static Handle<Value> Chdir(const Arguments& args) {
1231
1229
1232
1230
String::Utf8Value path (args[0 ]->ToString ());
1233
1231
1234
- int r = chdir (*path);
1232
+ uv_err_t r = uv_chdir (*path);
1235
1233
1236
- if (r != 0 ) {
1237
- return ThrowException (Exception::Error ( String::New ( strerror (errno)) ));
1234
+ if (r. code != UV_OK ) {
1235
+ return ThrowException (UVException (r. code , " uv_chdir " ));
1238
1236
}
1239
1237
1240
1238
return Undefined ();
@@ -1243,18 +1241,25 @@ static Handle<Value> Chdir(const Arguments& args) {
1243
1241
1244
1242
static Handle <Value> Cwd (const Arguments& args) {
1245
1243
HandleScope scope;
1244
+ #ifdef _WIN32
1245
+ /* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
1246
+ char buf[MAX_PATH * 4 + 1 ];
1247
+ #else
1248
+ char buf[PATH_MAX + 1 ];
1249
+ #endif
1246
1250
1247
- char * r = getcwd (getbuf , ARRAY_SIZE (getbuf ) - 1 );
1248
- if (r == NULL ) {
1249
- return ThrowException (Exception::Error ( String::New ( strerror (errno)) ));
1251
+ uv_err_t r = uv_cwd (buf , ARRAY_SIZE (buf ) - 1 );
1252
+ if (r. code != UV_OK ) {
1253
+ return ThrowException (UVException (r. code , " uv_cwd " ));
1250
1254
}
1251
1255
1252
- getbuf [ARRAY_SIZE (getbuf ) - 1 ] = ' \0 ' ;
1253
- Local<String> cwd = String::New (r );
1256
+ buf [ARRAY_SIZE (buf ) - 1 ] = ' \0 ' ;
1257
+ Local<String> cwd = String::New (buf );
1254
1258
1255
1259
return scope.Close (cwd);
1256
1260
}
1257
1261
1262
+
1258
1263
#ifdef _WIN32
1259
1264
static Handle <Value> CwdForDrive (const Arguments& args) {
1260
1265
HandleScope scope;
Original file line number Diff line number Diff line change 21
21
22
22
var common = require ( '../common' ) ;
23
23
var assert = require ( 'assert' ) ;
24
+ var fs = require ( 'fs' ) ;
25
+ var path = require ( 'path' ) ;
24
26
25
27
assert . equal ( true , process . cwd ( ) !== __dirname ) ;
26
28
27
29
process . chdir ( __dirname ) ;
28
-
29
30
assert . equal ( true , process . cwd ( ) === __dirname ) ;
31
+
32
+ var dir = path . resolve ( common . fixturesDir ,
33
+ 'weird \uc3a4\uc3ab\uc3af characters \u00e1\u00e2\u00e3' ) ;
34
+ fs . mkdirSync ( dir ) ;
35
+ process . chdir ( dir ) ;
36
+ assert ( process . cwd ( ) == dir ) ;
37
+
38
+ process . chdir ( '..' ) ;
39
+ assert ( process . cwd ( ) == path . resolve ( common . fixturesDir ) ) ;
40
+ fs . rmdirSync ( dir ) ;
You can’t perform that action at this time.
0 commit comments