import win32.*;

alias STD_INPUT_HANDLE  = wrapCast(DWORD, -10);
alias STD_OUTPUT_HANDLE = wrapCast(DWORD, -11);
alias STD_ERROR_HANDLE  = wrapCast(DWORD, -12);

alias INVALID_HANDLE_VALUE = HANDLE(-1);

alias GENERIC_READ    = 0x80000000u;
alias GENERIC_WRITE   = 0x40000000u;
alias GENERIC_EXECUTE = 0x20000000u;
alias GENERIC_ALL     = 0x10000000u;

alias FILE_LIST_DIRECTORY       = 0x00000001u;
alias FILE_READ_DATA            = 0x00000001u;
alias FILE_ADD_FILE             = 0x00000002u;
alias FILE_WRITE_DATA           = 0x00000002u;
alias FILE_ADD_SUBDIRECTORY     = 0x00000004u;
alias FILE_APPEND_DATA          = 0x00000004u;
alias FILE_CREATE_PIPE_INSTANCE = 0x00000004u;
alias FILE_READ_EA              = 0x00000008u;
alias FILE_READ_PROPERTIES      = 0x00000008u;
alias FILE_WRITE_EA             = 0x00000010u;
alias FILE_WRITE_PROPERTIES     = 0x00000010u;
alias FILE_EXECUTE              = 0x00000020u;
alias FILE_TRAVERSE             = 0x00000020u;
alias FILE_DELETE_CHILD         = 0x00000040u;
alias FILE_READ_ATTRIBUTES      = 0x00000080u;
alias FILE_WRITE_ATTRIBUTES     = 0x00000100u;

alias FILE_SHARE_READ        = 1u;
alias FILE_SHARE_WRITE       = 2u;
alias FILE_SHARE_DELETE      = 4u;
alias FILE_SHARE_VALID_FLAGS = 7u;

alias CREATE_NEW        = 1u;
alias CREATE_ALWAYS     = 2u;
alias OPEN_EXISTING     = 3u;
alias OPEN_ALWAYS       = 4u;
alias TRUNCATE_EXISTING = 5u;

alias INVALID_FILE_ATTRIBUTES = Greatest(DWORD);

alias FILE_ATTRIBUTE_READONLY            = 0x00000001u;
alias FILE_ATTRIBUTE_HIDDEN              = 0x00000002u;
alias FILE_ATTRIBUTE_SYSTEM              = 0x00000004u;
alias FILE_ATTRIBUTE_DIRECTORY           = 0x00000010u;
alias FILE_ATTRIBUTE_ARCHIVE             = 0x00000020u;
alias FILE_ATTRIBUTE_DEVICE              = 0x00000040u;
alias FILE_ATTRIBUTE_NORMAL              = 0x00000080u;
alias FILE_ATTRIBUTE_TEMPORARY           = 0x00000100u;
alias FILE_ATTRIBUTE_SPARSE_FILE         = 0x00000200u;
alias FILE_ATTRIBUTE_REPARSE_POINT       = 0x00000400u;
alias FILE_ATTRIBUTE_COMPRESSED          = 0x00000800u;
alias FILE_ATTRIBUTE_OFFLINE             = 0x00001000u;
alias FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000u;
alias FILE_ATTRIBUTE_ENCRYPTED           = 0x00004000u;
alias FILE_ATTRIBUTE_VALID_FLAGS         = 0x00007fb7u;
alias FILE_ATTRIBUTE_VALID_SET_FLAGS     = 0x000031a7u;

alias FILE_FLAG_WRITE_THROUGH      = 0x80000000u;
alias FILE_FLAG_OVERLAPPED         = 1073741824u;
alias FILE_FLAG_NO_BUFFERING       = 536870912u;
alias FILE_FLAG_RANDOM_ACCESS      = 268435456u;
alias FILE_FLAG_SEQUENTIAL_SCAN    = 134217728u;
alias FILE_FLAG_DELETE_ON_CLOSE    = 67108864u;
alias FILE_FLAG_BACKUP_SEMANTICS   = 33554432u;
alias FILE_FLAG_POSIX_SEMANTICS    = 16777216u;
alias FILE_FLAG_OPEN_REPARSE_POINT = 2097152u;
alias FILE_FLAG_OPEN_NO_RECALL     = 1048576u;

alias FILE_BEGIN   = 0u;
alias FILE_CURRENT = 1u;
alias FILE_END     = 2u;

alias PAGE_NOACCESS          = 0x0001u;
alias PAGE_READONLY          = 0x0002u;
alias PAGE_READWRITE         = 0x0004u;
alias PAGE_WRITECOPY         = 0x0008u;
alias PAGE_EXECUTE           = 0x0010u;
alias PAGE_EXECUTE_READ      = 0x0020u;
alias PAGE_EXECUTE_READWRITE = 0x0040u;
alias PAGE_EXECUTE_WRITECOPY = 0x0080u;
alias PAGE_GUARD             = 0x0100u;
alias PAGE_NOCACHE           = 0x0200u;

alias SEC_BASED     = 0x00200000u;
alias SEC_NO_CHANGE = 0x00400000u;
alias SEC_FILE      = 0x00800000u;
alias SEC_IMAGE     = 0x01000000u;
alias SEC_VLM       = 0x02000000u;
alias SEC_RESERVE   = 0x04000000u;
alias SEC_COMMIT    = 0x08000000u;
alias SEC_NOCACHE   = 0x10000000u;

alias FILE_MAP_ALL_ACCESS = 0xf001fu;
alias FILE_MAP_READ       = 4u;
alias FILE_MAP_WRITE      = 2u;
alias FILE_MAP_COPY       = 1u;



//
// socket protocol families
//
alias AF_UNSPEC = 0uss;
alias AF_INET = 2uss;
alias AF_INET6 = 30uss;



//
// socket protocol families
//
alias PF_UNSPEC = AF_UNSPEC;
alias PF_INET = AF_INET;
alias PF_INET6 = AF_INET6;



//
// socket types
//
alias SOCK_STREAM = 1;
alias SOCK_DGRAM = 2;
alias SOCK_RAW = 3;



//
// special IPv4 addresses
//
alias INADDR_ANY       = 0x00_00_00_00u;
alias INADDR_BROADCAST = 0xFF_FF_FF_FFu;
alias INADDR_LOOPBACK  = 0x7F_00_00_01u;
alias INADDR_NONE      = 0xFF_FF_FF_FFu;
alias INADDR_UNSPEC_GROUP    = 0xE0_00_00_00u;
alias INADDR_ALLHOSTS_GROUP  = 0xE0_00_00_01u;
alias INADDR_ALLRTRS_GROUP   = 0xE0_00_00_02u;
alias INADDR_MAX_LOCAL_GROUP = 0xE0_00_00_FFu;



//
// getsockopt/setsockopt constants
//
alias SOL_SOCKET = 0xffff;

alias SO_REUSEADDR = 4;



//
// socket error
//
alias SOCKET_ERROR = Greatest(SOCKET);
