"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_node_fs = require('../node/fs.js');
const require_smol_path = require('../smol/path.js');

//#region src/fs/access.ts
/**
* @file Synchronous file-access predicates — boolean "can this process do X to
*   this path?" checks over `fs.accessSync`. Prefer these only where the answer
*   drives a user-facing decision (e.g. "is the cache dir writable, so I can
*   pick a fallback?"). For "I'm about to write, can I?" do NOT pre-check —
*   just attempt the write and handle the error; a check-then-act gap is a
*   TOCTOU race. `canAccess` (F_OK) overlaps `existsSync`; use `existsSync` for
*   plain existence, these for permission bits.
*/
/**
* Does the process have `mode` access to `path`? Wraps `fs.accessSync`,
* returning a boolean instead of throwing. Default mode is `F_OK` (existence).
*
* @param path - Path to check.
* @param mode - `fs.constants` bit (`F_OK` / `R_OK` / `W_OK` / `X_OK`).
*
* @returns True if the access check succeeds.
*/
/*@__NO_SIDE_EFFECTS__*/
function canAccess(path, mode) {
	/* c8 ignore start - native access arm only on socket-btm smol binaries; getSmolPath() is undefined on stock Node. */
	const smolAccess = (/* @__PURE__ */ require_smol_path.getSmolPath())?.access;
	if (smolAccess) return smolAccess(path, mode);
	/* c8 ignore stop */
	const fs = /* @__PURE__ */ require_node_fs.getNodeFs();
	try {
		fs.accessSync(path, mode);
		return true;
	} catch {
		return false;
	}
}
/**
* Can the process execute `path`? (`X_OK`)
*/
/*@__NO_SIDE_EFFECTS__*/
function canExecute(path) {
	return /* @__PURE__ */ canAccess(path, (/* @__PURE__ */ require_node_fs.getNodeFs()).constants.X_OK);
}
/**
* Can the process read `path`? (`R_OK`)
*/
/*@__NO_SIDE_EFFECTS__*/
function canRead(path) {
	return /* @__PURE__ */ canAccess(path, (/* @__PURE__ */ require_node_fs.getNodeFs()).constants.R_OK);
}
/**
* Can the process write `path`? (`W_OK`)
*/
/*@__NO_SIDE_EFFECTS__*/
function canWrite(path) {
	return /* @__PURE__ */ canAccess(path, (/* @__PURE__ */ require_node_fs.getNodeFs()).constants.W_OK);
}

//#endregion
exports.canAccess = canAccess;
exports.canExecute = canExecute;
exports.canRead = canRead;
exports.canWrite = canWrite;