Files
nt-lite/code/posix/posix.h
T

99 lines
2.9 KiB
C

#pragma once
// posix.h - POSIX type and constant definitions for posix.dll
// Covers just what open/read/write/close/lseek/spawn/pthread/chdir need.
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
// ---------------------------------------------------------------------------
// errno
// ---------------------------------------------------------------------------
#ifdef errno
#undef errno
#endif
#ifdef EAGAIN
#undef EAGAIN
#endif
#ifdef ENOSYS
#undef ENOSYS
#endif
extern int errno; // defined in posix_fd.c; single global in v1
#define EPERM 1
#define ENOENT 2
#define ESRCH 3
#define EINTR 4
#define EIO 5
#define EBADF 9
#define ENOMEM 12
#define EACCES 13
#define EEXIST 17
#define ENODEV 19
#define ENOTDIR 20
#define EINVAL 22
#define EMFILE 24
#define ENOSPC 28
#define ERANGE 34
#define EAGAIN 35
#define ENOSYS 38
// ---------------------------------------------------------------------------
// open() flags
// ---------------------------------------------------------------------------
#define O_RDONLY 0x0000
#define O_WRONLY 0x0001
#define O_RDWR 0x0002
#define O_CREAT 0x0040
#define O_TRUNC 0x0200
#define O_APPEND 0x0400
// ---------------------------------------------------------------------------
// lseek() whence
// ---------------------------------------------------------------------------
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
// ---------------------------------------------------------------------------
// Scalar types
// ---------------------------------------------------------------------------
typedef int32_t pid_t;
typedef int32_t off_t;
typedef uint32_t mode_t;
typedef int64_t ssize_t;
// ---------------------------------------------------------------------------
// pthread types
// ---------------------------------------------------------------------------
typedef struct { uint32_t Tid; } pthread_t;
typedef struct { uint32_t Handle; } pthread_mutex_t;
typedef void* pthread_attr_t; // unused in v1
typedef void* pthread_mutexattr_t;
// ---------------------------------------------------------------------------
// posix_spawn types (file_actions and attrp both ignored in v1)
// ---------------------------------------------------------------------------
typedef void* posix_spawn_file_actions_t;
typedef void* posix_spawnattr_t;
// ---------------------------------------------------------------------------
// dirent (used by posix_dir.c)
// ---------------------------------------------------------------------------
#define NAME_MAX 259
typedef struct dirent {
char d_name[NAME_MAX + 1];
unsigned char d_type; // DT_REG or DT_DIR
} dirent;
#define DT_UNKNOWN 0
#define DT_REG 8
#define DT_DIR 4
typedef struct DIR {
uint32_t KHandle; // kernel DIR_OBJECT handle
dirent Current;
bool Valid;
} DIR;