/*
 * unistd.h — POSIX-style file descriptor I/O for Sprinter ESTEX.
 *
 * Each call maps to a single ESTEX RST 10h function:
 *   read   → $13  write  → $14
 *   close  → $12  unlink → $0E
 *
 * On error every call returns -1 (the ESTEX error code is not exposed yet;
 * a future errno mechanism will surface it).
 */

#ifndef UNISTD_H
#define UNISTD_H

#include <stddef.h>      /* size_t */
#include <stdint.h>      /* uint16_t */

/* lseek whence values (POSIX). */
#define SEEK_SET  0
#define SEEK_CUR  1
#define SEEK_END  2

int   read (int fd, void *buf, size_t n);
int   write(int fd, const void *buf, size_t n);
int   close(int fd);
int   unlink(const char *path);
long  lseek(int fd, long offset, int whence);

/* Block the calling task for `seconds` seconds (calibrated busy-wait). */
void  sleep(unsigned int seconds);

/* Block the calling task for `ms` milliseconds (calibrated busy-wait,
 * same engine as sleep() — see libc/time/_sleep_calib.c). */
void  delayms(uint16_t ms);

/* 1, если fd — консоль (наши псевдо-fd 0/-1/-2), 0 — файл (любой
 * положительный манипулятор DSS; из командной строки они идут с 1).
 * inline без static — см. memory/sdcc_inline_codegen_findings. */
inline int isatty(int fd) { return fd <= 0; }

/* Directory operations (ESTEX $1B-$1E).  All return 0 on success and -1
 * with errno set on failure; getcwd returns the buffer on success or NULL.
 * size is ignored — ESTEX always wants a 256-byte buffer. */
int   mkdir (const char *path);
int   rmdir (const char *path);
int   chdir (const char *path);
char *getcwd(char *buf, size_t size);

#endif
