delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/05/24/13:27:56

Date: Sun, 24 May 1998 20:27:42 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: DJ Delorie <dj AT delorie DOT com>
cc: djgpp-workers AT delorie DOT com
Subject: Introducing _doserrno
Message-ID: <Pine.SUN.3.91.980524202209.12971c-100000@is>
MIME-Version: 1.0

Remember that discussion of yore when everybody agreed that having 
_doserrno is a good idea?  Well, since we were overwhelmed by 
contributions that add it, I thought I'd throw in mine as well.

So how about the following simple implementation?  (While at that, I also 
updated the translation table from DOS error code to errno.)

*** /dev/null	Sat May 23 20:55:46 1998
--- src/libc/dos/errno/doserrno.c	Sat May 23 20:50:26 1998
***************
*** 0 ****
--- 1,3 ----
+ #include <errno.h>
+ 
+ int _doserrno;
*** src/libc/dos/errno/doserr2e.c~0	Wed Aug 23 07:55:54 1995
--- src/libc/dos/errno/doserr2e.c	Sat May 23 20:47:50 1998
***************
*** 3,27 ****
  #include <libc/dosio.h>
  
  static unsigned char map[] = {
!   /* 00-07 */ 0, EINVAL, ENOENT, ENOENT, ENFILE, EACCES, EBADF, EFAULT,
    /* 08-0f */ ENOMEM, EFAULT, EFAULT, EINVAL, EINVAL, EINVAL, EINVAL, ENODEV,
!   /* 10-17 */ EBUSY, EXDEV, ENMFILE, EROFS, ENXIO, ENODEV, EINVAL, EINVAL,
!   /* 18-1f */ EINVAL, EIO, EIO, EIO, EIO, EIO, EIO, EPERM,
!   /* 20-27 */ EACCES, EACCES, ENXIO, EBADF, ENOLCK, EINVAL, EIO, ENOSPC,
    /* 28-2f */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
!   /* 30-37 */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EBUSY, ENXIO,
    /* 38-3f */ EINVAL, EIO, EIO, EIO, EIO, EAGAIN, EINVAL, ENOSPC,
!   /* 40-47 */ EINVAL, EACCES, ENXIO, EINVAL, EINVAL, EINVAL, EBUSY, ENXIO,
!   /* 48-4f */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
!   /* 50-57 */ EEXIST, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
!   /* 57-5f */ EINVAL, ENOSYS, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
!   /* 60-67 */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, ENODEV, EINVAL, EINVAL,
!   /* 68-6f */ ENODEV, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL
  	    };
  
  int
  __doserr_to_errno(int doserr)
  {
    if (doserr >= 0 && doserr < sizeof(map)/sizeof(map[0]))
      return map[doserr];
    return EINVAL;
--- 3,46 ----
  #include <libc/dosio.h>
  
  static unsigned char map[] = {
!   /* 00-07 */ 0, EINVAL, ENOENT, ENOENT, EMFILE, EACCES, EBADF, EFAULT,
    /* 08-0f */ ENOMEM, EFAULT, EFAULT, EINVAL, EINVAL, EINVAL, EINVAL, ENODEV,
!   /* 10-17 */ EBUSY, EXDEV, ENFILE, EROFS, ENXIO, ENXIO, EINVAL, EIO,
!   /* 18-1f */ EINVAL, EIO, EIO, EIO, EIO, EIO, EIO, EIO,
!   /* 20-27 */ EPERM, EPERM, ENXIO, EBADF, ENOLCK, EINVAL, EIO, ENOSPC,
    /* 28-2f */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
!   /* 30-37 */ EINVAL, EINVAL, ENOSYS, EIO, EINVAL, EINVAL, EBUSY, ENXIO,
    /* 38-3f */ EINVAL, EIO, EIO, EIO, EIO, EAGAIN, EINVAL, ENOSPC,
!   /* 40-47 */ EINVAL, EPERM, ENXIO, EINVAL, EINVAL, EINVAL, EBUSY, ENXIO,
!   /* 48-4f */ EINVAL, ENOSYS, ENXIO, EPERM, EPERM, ENOSPC, EPERM, EINVAL,
!   /* 50-57 */ EEXIST, EINVAL, EPERM, EINTR, EPERM, EPERM, EINVAL, EINVAL,
!   /* 58-5f */ EIO, ENOSYS, ENOSYS, ENXIO, ENXIO, EINVAL, EINVAL, ENXIO,
!   /* 60-67 */ EINVAL, EINVAL, EINVAL, EINVAL, EPERM, ENXIO, ENOMEM, EINVAL,
!   /* 68-6f */ ENODEV, ESRCH, EPERM, ENODEV, EBUSY, EPIPE, ENOENT, ENOSPC,
!   /* 70-77 */ ENOSPC, ENFILE, EBADF, EFAULT, EIO, ENOTTY, EINVAL, ENOSYS,
!   /* 78-7f */ EINVAL, EIO, EINVAL, EFAULT, ENOSYS, ENOENT, EINVAL, EINVAL,
!   /* 80-87 */ ECHILD, EAGAIN, EINVAL, ESPIPE, ESPIPE, EXDEV, EXDEV, EXDEV,
!   /* 88-8f */ ENODEV, ENODEV, EXDEV, EXDEV, EXDEV, EXDEV, EBUSY, EEXIST,
!   /* 90-97 */ EACCES, ENOTEMPTY, EBUSY, EBUSY, EBUSY, EXDEV, EIO, EIO,
!   /* 98-9f */ EPERM, EINVAL, ENAMETOOLONG, EAGAIN, EPERM, EINVAL, EINVAL, EFAULT,
!   /* a0-a7 */ EFAULT, EINVAL, EPERM, EIO, EAGAIN, EIO, EINVAL, EINVAL,
!   /* a8-af */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
!   /* b0-b7 */ ENXIO, ENXIO, ENODEV, EINVAL, ENOLCK, EIO, EINVAL, ENOMEM,
!   /* b8-bf */ ECHILD, EAGAIN, EINVAL, EINVAL, ENOEXEC, ENOEXEC, ENOEXEC, ENOEXEC,
!   /* c0-c7 */ ENOEXEC, ENOEXEC, ENOEXEC, ENOEXEC, EPERM, EPERM, ENOEXEC, ENOEXEC,
!   /* c8-cf */ ENOEXEC, ENOEXEC, ENOEXEC, EINVAL, EINVAL, ENXIO, ENAMETOOLONG, EBUSY,
!   /* d0-d7 */ ENAMETOOLONG, EINVAL, EINVAL, ENOSYS, EACCES, EINVAL, EAGAIN, EINVAL,
!   /* d8-df */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
!   /* e0-e7 */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, ENXIO, EBUSY,
!   /* e8-ef */ EAGAIN, EPIPE, EIO, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
!   /* f0-f7 */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
!   /* f8-ff */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, ENXIO
  	    };
  
  int
  __doserr_to_errno(int doserr)
  {
+   _doserrno = doserr;
    if (doserr >= 0 && doserr < sizeof(map)/sizeof(map[0]))
      return map[doserr];
    return EINVAL;
*** src/libc/dos/errno/makefile.~0	Sun Apr  2 03:49:16 1995
--- src/libc/dos/errno/makefile	Sat May 23 20:50:56 1998
***************
*** 2,6 ****
--- 2,7 ----
  TOP=../..
  
  SRC += doserr2e.c
+ SRC += doserrno.c
  
  include $(TOP)/../makefile.inc
*** include/errno.h~	Sun Oct  1 17:20:52 1995
--- include/errno.h	Sat May 23 20:49:00 1998
***************
*** 59,64 ****
--- 59,65 ----
  extern int		sys_nerr;
  extern const char *	__sys_errlist[];
  extern int		__sys_nerr;
+ extern int		_doserrno;
  
  #endif /* !_POSIX_SOURCE */
  #endif /* !__STRICT_ANSI__ */
*** include/dos.h~	Thu Jan  1 22:24:54 1998
--- include/dos.h	Sat May 23 20:53:38 1998
***************
*** 125,130 ****
--- 125,131 ----
  
  extern unsigned short   _osmajor, _osminor;
  extern const    char  * _os_flavor;
+ extern int		_doserrno;
  
  unsigned short _get_dos_version(int);
  
*** /dev/null	Sat May 23 21:07:11 1998
--- src/libc/dos/errno/doserrno.txh	Sat May 23 21:06:14 1998
***************
*** 0 ****
--- 1,24 ----
+ @node _doserrno, dos
+ @subheading Syntax
+  
+ @example
+ #include <errno.h>
+  
+ extern int _doserrno;
+ @end example
+  
+ @subheading Description
+ 
+ Whenever a DOS call returns a failure indication, this variable is
+ assigned the value of the error code returned by the failed DOS call.
+ 
+ To interpret the error codes, please refer to your DOS reference.
+ 
+ @subheading Example
+ 
+ @example
+  _doserrno = 0;
+  fprintf (stdprn, "Hello, world!\r\n\f");
+  if (_doserrno == 0x1c)
+    fprintf (stderr, "The printer is out of paper!\n");
+ @end example
*** src/docs/kb/wc202.~11	Sat May 23 21:09:36 1998
--- src/docs/kb/wc202.txi	Sat May 23 21:08:28 1998
***************
*** 386,388 ****
--- 386,393 ----
  makes detection of stack overflows and other stack-related atrocities
  much easier.
  @cindex stack dump, when aborted or crashed
+ 
+ The @code{_doserrno} global variable is now provided.  Whenever a DOS
+ call fails, this variable gets assigned the value of the error code
+ returned by the failed DOS function.
+ @vindex _doserrno


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019