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