' ########################################################################################
' Microsoft C Runtime
' File: errno.inc
' Contents: System-wide error numbers (set by system calls)
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_errno_PBI)
#DEFINE PBX_errno_PBI
%EQUATE `ERRNO_INC = 1
#INCLUDE ONCE "Legacy/Runtime/crtdefs.inc"
'/* declare reference to errno */
'#ifndef _CRT_ERRNO_DEFINED
'#define _CRT_ERRNO_DEFINED
'_CRTIMP extern int * __cdecl _errno(void);
'#define errno (*_errno())
#IF NOT %DEF(%CRT_ERRNO_DEFINED)
 %CRT_ERRNO_DEFINED = 1
' ========================================================================================
FUNCTION geterrno CDECL () AS LONG
 LOCAL hLib AS DWORD
 LOCAL perrno AS LONG PTR
 hLib = LoadLibrary($CRT_DLLNAME)
 IF hLib THEN
 perrno = GetProcAddress(hLib, "_errno")
 IF perrno THEN FUNCTION = @perrno
 FreeLibrary hLib
 END IF
END FUNCTION
' ========================================================================================
' ========================================================================================
FUNCTION seterrno CDECL (BYVAL value AS LONG) AS LONG
 LOCAL hLib AS DWORD
 LOCAL perrno AS LONG PTR
 hLib = LoadLibrary($CRT_DLLNAME)
 IF hLib THEN
 perrno = GetProcAddress(hLib, "_errno")
 IF perrno THEN @perrno = Value
 FUNCTION = @perrno
 FreeLibrary hLib
 END IF
END FUNCTION
' ========================================================================================
' ========================================================================================
' errno_t __cdecl _set_errno(_In_ int _Value);
' ========================================================================================
DECLARE FUNCTION set_errno CDECL IMPORT $CRT_DLLNAME ALIAS "_set_errno" ( BYVAL value AS LONG ' int value ) AS LONG ' errno_t
' ========================================================================================
' ========================================================================================
' errno_t __cdecl _get_errno(_Out_ int * _Value);
' ========================================================================================
DECLARE FUNCTION get_errno CDECL IMPORT $CRT_DLLNAME ALIAS "_get_errno" ( BYREF value AS LONG ' int * pValue ) AS LONG ' errno_t
' ========================================================================================
#ENDIF ' CRT_ERRNO_DEFINED
'/* Error Codes */
%EQUATE `EPERM = 1
%EQUATE `ENOENT = 2
%EQUATE `ESRCH = 3
%EQUATE `EINTR = 4
%EQUATE `EIO = 5
%EQUATE `ENXIO = 6
%EQUATE `E2BIG = 7
%EQUATE `ENOEXEC = 8
%EQUATE `EBADF = 9
%EQUATE `ECHILD = 10
%EQUATE `EAGAIN = 11
%EQUATE `ENOMEM = 12
%EQUATE `EACCES = 13
%EQUATE `EFAULT = 14
%EQUATE `EBUSY = 16
%EQUATE `EEXIST = 17
%EQUATE `EXDEV = 18
%EQUATE `ENODEV = 19
%EQUATE `ENOTDIR = 20
%EQUATE `EISDIR = 21
%EQUATE `EINVAL = 22
%EQUATE `ENFILE = 23
%EQUATE `EMFILE = 24
%EQUATE `ENOTTY = 25
%EQUATE `EFBIG = 27
%EQUATE `ENOSPC = 28
%EQUATE `ESPIPE = 29
%EQUATE `EROFS = 30
%EQUATE `EMLINK = 31
%EQUATE `EPIPE = 32
%EQUATE `EDOM = 33
%EQUATE `ERANGE = 34
%EQUATE `EDEADLK = 36
%EQUATE `ENAMETOOLONG = 38
%EQUATE `ENOLCK = 39
%EQUATE `ENOSYS = 40
%EQUATE `ENOTEMPTY = 41
'/* Error codes used in the Secure CRT functions */
'#ifndef RC_INVOKED
'#if !defined(_SECURECRT_ERRCODE_VALUES_DEFINED)
'#define _SECURECRT_ERRCODE_VALUES_DEFINED
%EQUATE `EINVAL = 22
%EQUATE `ERANGE = 34
%EQUATE `EILSEQ = 42
%EQUATE `STRUNCATE = 80
'#endif
'#endif
'/*
' * Support EDEADLOCK for compatibiity with older MS-C versions.
' */
%EQUATE `EDEADLOCK = %EDEADLK
#ENDIF
