|
@ -37,6 +37,19 @@ var EventEmitter = require('events').EventEmitter; |
|
|
var kMinPoolSpace = 128; |
|
|
var kMinPoolSpace = 128; |
|
|
var kPoolSize = 40 * 1024; |
|
|
var kPoolSize = 40 * 1024; |
|
|
|
|
|
|
|
|
|
|
|
var O_APPEND = constants.O_APPEND || 0; |
|
|
|
|
|
var O_CREAT = constants.O_CREAT || 0; |
|
|
|
|
|
var O_DIRECTORY = constants.O_DIRECTORY || 0; |
|
|
|
|
|
var O_EXCL = constants.O_EXCL || 0; |
|
|
|
|
|
var O_NOCTTY = constants.O_NOCTTY || 0; |
|
|
|
|
|
var O_NOFOLLOW = constants.O_NOFOLLOW || 0; |
|
|
|
|
|
var O_RDONLY = constants.O_RDONLY || 0; |
|
|
|
|
|
var O_RDWR = constants.O_RDWR || 0; |
|
|
|
|
|
var O_SYMLINK = constants.O_SYMLINK || 0; |
|
|
|
|
|
var O_SYNC = constants.O_SYNC || 0; |
|
|
|
|
|
var O_TRUNC = constants.O_TRUNC || 0; |
|
|
|
|
|
var O_WRONLY = constants.O_WRONLY || 0; |
|
|
|
|
|
|
|
|
fs.Stats = binding.Stats; |
|
|
fs.Stats = binding.Stats; |
|
|
|
|
|
|
|
|
fs.Stats.prototype._checkModeProperty = function(property) { |
|
|
fs.Stats.prototype._checkModeProperty = function(property) { |
|
@ -178,28 +191,35 @@ function stringToFlags(flag) { |
|
|
if (typeof flag !== 'string') { |
|
|
if (typeof flag !== 'string') { |
|
|
return flag; |
|
|
return flag; |
|
|
} |
|
|
} |
|
|
switch (flag) { |
|
|
|
|
|
case 'r': |
|
|
|
|
|
return constants.O_RDONLY; |
|
|
|
|
|
|
|
|
|
|
|
case 'r+': |
|
|
// O_EXCL is mandated by POSIX, Windows supports it too.
|
|
|
return constants.O_RDWR; |
|
|
// Let's add a check anyway, just in case.
|
|
|
|
|
|
if (!O_EXCL && ~flag.indexOf('x')) { |
|
|
|
|
|
throw errnoException('ENOSYS', 'fs.open(O_EXCL)'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (flag) { |
|
|
|
|
|
case 'r' : return O_RDONLY; |
|
|
|
|
|
case 'r+' : return O_RDWR; |
|
|
|
|
|
|
|
|
case 'w': |
|
|
case 'w' : return O_TRUNC | O_CREAT | O_WRONLY; |
|
|
return constants.O_CREAT | constants.O_TRUNC | constants.O_WRONLY; |
|
|
case 'wx' : // fall through
|
|
|
|
|
|
case 'xw' : return O_TRUNC | O_CREAT | O_WRONLY | O_EXCL; |
|
|
|
|
|
|
|
|
case 'w+': |
|
|
case 'w+' : return O_TRUNC | O_CREAT | O_RDWR; |
|
|
return constants.O_CREAT | constants.O_TRUNC | constants.O_RDWR; |
|
|
case 'wx+': // fall through
|
|
|
|
|
|
case 'xw+': return O_TRUNC | O_CREAT | O_RDWR | O_EXCL; |
|
|
|
|
|
|
|
|
case 'a': |
|
|
case 'a' : return O_APPEND | O_CREAT | O_WRONLY; |
|
|
return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY; |
|
|
case 'ax' : // fall through
|
|
|
|
|
|
case 'xa' : return O_APPEND | O_CREAT | O_WRONLY | O_EXCL; |
|
|
|
|
|
|
|
|
case 'a+': |
|
|
case 'a+' : return O_APPEND | O_CREAT | O_RDWR; |
|
|
return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR; |
|
|
case 'ax+': // fall through
|
|
|
|
|
|
case 'xa+': return O_APPEND | O_CREAT | O_RDWR | O_EXCL; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
throw new Error('Unknown file open flag: ' + flag); |
|
|
throw new Error('Unknown file open flag: ' + flag); |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// exported but hidden, only used by test/simple/test-fs-open-flags.js
|
|
|
// exported but hidden, only used by test/simple/test-fs-open-flags.js
|
|
|