/*
 * errno.h — ESTEX error codes + global errno + strerror / perror.
 *
 * ESTEX functions report errors by setting CF=1 and returning the error
 * code in A.  Our libc wrappers stash that code into `errno` and return
 * -1 (or 0 / NULL where the C type calls for it).
 *
 * Error numbers match ESTEX (so they round-trip through OS/BIOS calls
 * untouched).  Where the meaning lines up cleanly with POSIX we also
 * expose the POSIX-style name as an alias.
 */

#ifndef ERRNO_H
#define ERRNO_H

/* Process-wide error state.  Reset to 0 only by user code — libc never
 * clears it. */
extern int errno;

/* Error numbers — direct ESTEX codes. */
#define EOK         0       /* No error */
#define EINVFN      1       /* Invalid function */
#define ENODRV      2       /* Invalid drive number */
#define ENOENT      3       /* File not found        — POSIX */
#define ENOPATH     4       /* Path not found */
#define EBADF       5       /* Invalid handle        — POSIX */
#define EMFILE      6       /* Too many open files   — POSIX */
#define EEXIST      7       /* File already exists   — POSIX */
#define EROFS       8       /* File is read-only     — POSIX */
#define EROOTFULL   9       /* Root directory overflow */
#define ENOSPC      10      /* No free space         — POSIX */
#define ENOTEMPTY   11      /* Directory not empty   — POSIX */
#define EBUSY       12      /* Can't delete current directory  — POSIX-ish */
#define EMEDIA      13      /* Invalid media */
#define EUNKOP      14      /* Unknown operation */
#define EISDIR      15      /* Directory exists      — POSIX */
#define EINAME      16      /* Invalid filename */
#define EINVEXE     17      /* Invalid EXE file */
#define ENOEXEC     18      /* Not supported EXE     — POSIX */
#define EACCES      19      /* Permission denied     — POSIX */
#define ENOTREADY   20      /* Device not ready */
#define ESEEK       21      /* Seek error            — POSIX (ESPIPE) */
#define ENOSECT     22      /* Sector not found */
#define ECRC        23      /* CRC error */
#define EWRPROT     24      /* Write protect */
#define EREAD       25      /* Read error */
#define EWRITE      26      /* Write error */
#define EDRVFAIL    27      /* Drive failure */
#define ENOMEM      30      /* Out of memory         — POSIX */
#define EINVMEM     31      /* Invalid memory block */
#define EUNKERR     32      /* Unknown error */


/* POSIX aliases for codes ESTEX doesn't have a direct equivalent for.
 * Folded onto the closest existing code so error strings stay sane. */
#define EINVAL      EUNKOP  /* "Invalid argument" → "Unknown operation" */

/* ---- Solid-C aliases (ERRNO.H из Solid-C v2004) -------------------
 * Те же числовые коды DSS, только имена другие — портируемые
 * программы работают без правок. */
#define EZERO       EOK
#define EINVFNC     EINVFN
#define EINVDRV     ENODRV
#define ENOFILE     ENOENT
#define EINVHND     EBADF
#define EROFILE     EROFS
#define EROOT       EROOTFULL
#define ENOSPACE    ENOSPC
#define ENOEMPTY    ENOTEMPTY
#define ECURDIR     EBUSY
#define EINVMED     EMEDIA
#define EOPER       EUNKOP
#define EEXISDIR    EISDIR
#define EINVFNAM    EINAME
#define ENSUPEXE    ENOEXEC
#define ENORDY      ENOTREADY
#define EWRTPRT     EWRPROT

/* C99 perror / strerror surface. */
const char *strerror(int err);
void        perror  (const char *prefix);

#endif
