Watcom C Library : halloc, _harderr, _hardresume, _hdopen
Watcom C Reference/G - H - I 2021. 6. 30. 16:26
Watcom C Library Reference : halloc, _harderr, _hardresume, _hdopen
halloc
Synopsis : #include <malloc.h>
void __huge *halloc( long int numb, size_t size );
Description : The halloc function allocates space for an array of numb objects of size bytes each and initializes each object to 0. When the size of the array is greater than 64K bytes, then the size of an array element must be a power of 2 since an object could straddle a segment boundary.
Returns : The halloc function returns a far pointer (of type void huge *) to the start of the allocated memory. The NULL value is returned if there is insufficient memory available. The NULL value is also returned if the size of the array is greater than 64K bytes and the size of an array element is not a power of 2.
See Also : calloc Functions, _expand Functions, free Functions, hfree, malloc Functions, _msize Functions, realloc Functions, sbrk
Example :
#include <stdio.h>
#include <malloc.h>
void main( )
{
long int __huge *big_buffer;
big_buffer = ( long int __huge * ) halloc( 1024L, sizeof( long ) );
if( big_buffer == NULL ) {
printf( "Unable to allocate memory\n" );
} else {
/* rest of code goes here */
hfree ( big_buffer ); /* deallocate */
}
}
Classification : WATCOM
Systems : DOS/16, Win/16, QNX/16, OS/2 1.x(all)
_harderr, _hardresume
Synopsis : #include <dos.h>
void _harderr( int ( __far *funcptr ) ( ) );
void _hardresume( int action );
Description : The _harderr routine installs a critical error handler (for INT 0x24) to handle hardware errors. This critical error handler will call the function specified by funcptr when a critical error occurs (for example, attempting to open a file on a floppy disk when the drive door is open). The parameters to this function are as follows:
int handler( unsigned deverror, unsigned errcode, unsigned __far *devhdr );
The low-order byte of errcode can be one of the following values:
Value | Meaning |
0x00 | Attempt to write to a write-protected disk |
0x01 | Unknown unit |
0x02 | Drive not ready |
0x03 | Unknown command |
0x04 | CRC error in data |
0x05 | Bad drive-request structure length |
0x06 | Seek error |
0x07 | Unknown media type |
0x08 | Sector not found |
0x09 | Printer out of paper |
0x0A | Write fault |
0x0B | Read fault |
0x0C | General failure |
The devhdr argument points to a device header control-block that contains information about the device on which the error occurred. Your error handler may inspect the information in this control-block but must not change it.
If the error occurred on a disk device, bit 15 of the deverror argument will be 0 and the deverror argument will indicate the following:
Bit | Meaning |
bit 15 | 0 indicates disk error |
bit 14 | not used |
bit 13 | 0 indicates "Ignore" response not allowed |
bit 12 | 0 indicates "Retry" response not allowed |
bit 11 | 0 indicates "Fail" response not allowed |
bit 9,10 | location of error |
bit 8 | Value Meaning 00 MS-DOS 01 File Allocation Table (FAT) 10 Directory 11 Data area O indicates read error, 1 indicates write error |
The low-order byte of deverror indicates the drive where the error occurred; (0 = drive A, 1 = drive B, etc.).
The handler is very restricted in the type of system calls that it can perform. System calls 0x01 through 0x0C, and 0x59 are the only system calls allowed to be issued by the handler. Therefore, many of the standard C run-time functions such as stream I/O and low-level I/O cannot be used by the handler. Console I/O is allowed (eg. cprintf, cputs).
The handler must indicate what action to take by returning one of the following values or calling _hardresume with one of the following values:
Value | Meaning |
_HARDERR_IGNORE | Ignore the error |
_HARDERR_RETRY | Retry the operation |
_HARDERR_ABORT | Abort the program issuing INT 0x23 |
_HARDERR_FAIL | Fail the system call that is in progress (DOS 3.0 or higher) |
See The MS-DOS Encyclopedia for more detailed information on determining the type of error that has occurred.
Returns : The _harderr routine does not return a value.
See Also : _chain_intr, _dos_getvect, _dos_setvect
Example :
#include <stdio.h>
#include <conio.h>
#include <dos.h>
int __far critical_error_handler( unsigned deverr, unsigned errcode, unsigned far *devhdr )
{
cprintf( "Critical error: " );
cprintf( "deverr=%4.4x errcode=%d\r\n", deverr, errcode );
cprintf( "devhdr = %Fp\r\n", devhdr ) ;
return( _HARDERR_IGNORE );
}
void main( )
{
FILE *fp;
_harderr( critical_error_handler );
fp = fopen( "a:tmp.tmp", "r" );
printf( "fp = %p\n", fp );
}
produces the following :
Critical error: deverr=1A00 errcode=2
devhdr = 0070:01b6
fp = 0000
Classification : DOS
Systems : _harderr - DOS
_hardresume - DOS
_hdopen
Synopsis : #include <io.h>
int _hdopen( int os_handle, int mode );
Description : The _hdopen function takes a previously opened operating system file handle specified by os_handle and opened with access and sharing specified by mode, and creates a POSIX-style file handle.
Returns : The _hdopen function returns the new POSIX-style file handle if successful. Otherwise, it returns -1.
See Also : close, fdopen, open, _os_handle
Example :
#include <stdio.h>
#include <dos.h>
#include <fcntl.h>
#include <io.h>
void main( )
{
int dos_handle;
int handle;
if( _dos_open( "file", O_RDONLY, &dos_handle ) != 0 ) {
printf( "Unable to open file\n" );
} else {
handle = _hdopen( dos_handle, O_RDONLY );
if( handle != -1 ) {
write( handle, "hello\n", 6);
close( handle );
}
}
}
Classification : WATCOM
Systems : All
This manual describes the WATCOM C library for DOS, Windows, and OS/2, It includes the Standard C Library (as defined in the ANSI C Standard).
WATCOM C Language Reference manual describes the ANSI C Programming language and extensions to it which are supported by WATCOM C/C++ (32bit)