11cb0ef41Sopenharmony_cimodule.exports = isexe
21cb0ef41Sopenharmony_ciisexe.sync = sync
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_civar fs = require('fs')
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_cifunction isexe (path, options, cb) {
71cb0ef41Sopenharmony_ci  fs.stat(path, function (er, stat) {
81cb0ef41Sopenharmony_ci    cb(er, er ? false : checkStat(stat, options))
91cb0ef41Sopenharmony_ci  })
101cb0ef41Sopenharmony_ci}
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cifunction sync (path, options) {
131cb0ef41Sopenharmony_ci  return checkStat(fs.statSync(path), options)
141cb0ef41Sopenharmony_ci}
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cifunction checkStat (stat, options) {
171cb0ef41Sopenharmony_ci  return stat.isFile() && checkMode(stat, options)
181cb0ef41Sopenharmony_ci}
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_cifunction checkMode (stat, options) {
211cb0ef41Sopenharmony_ci  var mod = stat.mode
221cb0ef41Sopenharmony_ci  var uid = stat.uid
231cb0ef41Sopenharmony_ci  var gid = stat.gid
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  var myUid = options.uid !== undefined ?
261cb0ef41Sopenharmony_ci    options.uid : process.getuid && process.getuid()
271cb0ef41Sopenharmony_ci  var myGid = options.gid !== undefined ?
281cb0ef41Sopenharmony_ci    options.gid : process.getgid && process.getgid()
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci  var u = parseInt('100', 8)
311cb0ef41Sopenharmony_ci  var g = parseInt('010', 8)
321cb0ef41Sopenharmony_ci  var o = parseInt('001', 8)
331cb0ef41Sopenharmony_ci  var ug = u | g
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  var ret = (mod & o) ||
361cb0ef41Sopenharmony_ci    (mod & g) && gid === myGid ||
371cb0ef41Sopenharmony_ci    (mod & u) && uid === myUid ||
381cb0ef41Sopenharmony_ci    (mod & ug) && myUid === 0
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  return ret
411cb0ef41Sopenharmony_ci}
42