plat/msdos86: implement close( ) function & proper errno setting
This commit is contained in:
parent
4c678ca210
commit
aaf3ef695b
23
plat/msdos86/libsys/close.s
Normal file
23
plat/msdos86/libsys/close.s
Normal file
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
! $Source$
|
||||
! $State$
|
||||
! $Revision$
|
||||
|
||||
! Declare segments (the order is important).
|
||||
|
||||
.sect .text
|
||||
.sect .rom
|
||||
.sect .data
|
||||
.sect .bss
|
||||
|
||||
.sect .text
|
||||
|
||||
! Close a file.
|
||||
|
||||
.define _close
|
||||
_close:
|
||||
mov bx, sp
|
||||
mov bx, 2(bx)
|
||||
movb ah, 0x3E
|
||||
int 0x21
|
||||
jmp .sys_zret
|
28
plat/msdos86/libsys/errno.s
Normal file
28
plat/msdos86/libsys/errno.s
Normal file
|
@ -0,0 +1,28 @@
|
|||
#
|
||||
! $Source$
|
||||
! $State$
|
||||
! $Revision$
|
||||
|
||||
! Declare segments (the order is important).
|
||||
|
||||
.sect .text
|
||||
.sect .rom
|
||||
.sect .data
|
||||
.sect .bss
|
||||
|
||||
#define D(e) .define e; e
|
||||
|
||||
.sect .data
|
||||
|
||||
! Define various ACK error numbers. Note that these are *not* ANSI C
|
||||
! errnos, and are used for different purposes.
|
||||
|
||||
D(ERANGE) = 1
|
||||
D(ESET) = 2
|
||||
D(EIDIVZ) = 6
|
||||
D(EHEAP) = 17
|
||||
D(EILLINS) = 18
|
||||
D(EODDZ) = 19
|
||||
D(ECASE) = 20
|
||||
D(EBADMON) = 25
|
||||
|
45
plat/msdos86/libsys/sys_seterrno.c
Normal file
45
plat/msdos86/libsys/sys_seterrno.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
static const signed char err_map[] =
|
||||
{
|
||||
0, /* 0x00 no error */
|
||||
EINVAL, /* 0x01 function number invalid */
|
||||
ENOENT, /* 0x02 file not found */
|
||||
ENOENT, /* 0x03 path not found */
|
||||
EMFILE, /* 0x04 too many open files */
|
||||
EACCES, /* 0x05 access denied */
|
||||
EBADF, /* 0x06 invalid handle */
|
||||
EFAULT, /* 0x07 mem. control block destroyed */
|
||||
ENOMEM, /* 0x08 insufficient memory */
|
||||
EFAULT, /* 0x09 memory block address invalid */
|
||||
E2BIG, /* 0x0A environment invalid */
|
||||
ENOEXEC, /* 0x0B format invalid */
|
||||
EINVAL, /* 0x0C access code invalid */
|
||||
EINVAL, /* 0x0D data invalid */
|
||||
ENOEXEC, /* 0x0E (?) fixup overflow */
|
||||
ENODEV, /* 0x0F invalid drive */
|
||||
EBUSY, /* 0x10 attempt to remove curr. dir. */
|
||||
EXDEV, /* 0x11 not same device */
|
||||
ENOENT, /* 0x12 no more files */
|
||||
EIO, /* 0x13 disk write-protected */
|
||||
EIO, /* 0x14 unknown unit */
|
||||
ENXIO, /* 0x15 drive not ready */
|
||||
};
|
||||
|
||||
/*
|
||||
* Map an MS-DOS 2+ system error code to an `errno' value and store that in
|
||||
* `errno'. Return -1.
|
||||
*/
|
||||
int _sys_seterrno(unsigned dos_err)
|
||||
{
|
||||
if (dos_err < sizeof(err_map) / sizeof(err_map[0]))
|
||||
errno = err_map[dos_err];
|
||||
else
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
35
plat/msdos86/libsys/sys_xret.s
Normal file
35
plat/msdos86/libsys/sys_xret.s
Normal file
|
@ -0,0 +1,35 @@
|
|||
#
|
||||
! $Source$
|
||||
! $State$
|
||||
! $Revision$
|
||||
|
||||
! Declare segments (the order is important).
|
||||
|
||||
.sect .text
|
||||
.sect .rom
|
||||
.sect .data
|
||||
.sect .bss
|
||||
|
||||
.sect .text
|
||||
|
||||
! .sys_zret: if the carry flag is set, then set `errno' from the DOS error
|
||||
! code in ax, and return -1. If the carry flag is clear, just return zero.
|
||||
!
|
||||
! .sys_axret: if the carry flag is set, then set `errno' from the DOS error
|
||||
! code in ax, and return -1. If the carry flag is clear, just return ax as
|
||||
! a return value.
|
||||
|
||||
.extern .sys_zret
|
||||
.extern .sys_axret
|
||||
.sys_zret:
|
||||
jc error
|
||||
xor ax, ax
|
||||
no_error:
|
||||
ret
|
||||
.sys_axret:
|
||||
jnc no_error
|
||||
error:
|
||||
push ax
|
||||
call __sys_seterrno
|
||||
pop cx
|
||||
ret
|
Loading…
Reference in a new issue