
/**
 * Implementation of errno. This is a #define :/
 * On Linux, it's a global variable with the symbol `errno`,
 * On Darwin it's a method execution called `__error`.
 * On Windows it's a method execution called `_errno`.
 */

var ffi = require('./ffi')
  , ref = require('ref')
  , errnoPtr = null
  , int = ref.types.int
  , intPtr = ref.refType(int)

if (process.platform == 'darwin' || process.platform == 'mac') {
  var __error = ffi.DynamicLibrary().get('__error')
  errnoPtr = ffi.ForeignFunction(__error, intPtr, [])
} else if (process.platform == 'win32') {
  var _errno = ffi.DynamicLibrary('msvcrt.dll').get('_errno')
  errnoPtr = ffi.ForeignFunction(_errno, intPtr, [])
} else {  // linux, sunos, etc.
  var errnoGlobal = new ffi.DynamicLibrary().get('errno');
  errnoPtr = function () { return errnoGlobal }
  // set the errno type
  errnoGlobal.type = int
}


function errno () {
  return errnoPtr().deref()
}
module.exports = errno

@@ -733,12 +733,8 @@
 al =
- new
  ffi
@@ -767,9 +767,30 @@
 no')
-;
+.reinterpret(int.size)
 %0A  e

use the `reinterpret()` function to ensure the 'errno' buffer is big enough to read from on Linux