delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/01/14/08:27:46

Message-ID: <387F1F1A.A2A4778B@softhome.net>
Date: Fri, 14 Jan 2000 15:05:30 +0200
From: Laurynas Biveinis <lauras AT softhome DOT net>
X-Mailer: Mozilla 4.7 [en] (Win98; I)
X-Accept-Language: en
MIME-Version: 1.0
To: DJGPP Workers <djgpp-workers AT delorie DOT com>
Subject: Library cleanups for _get_dev_info()
Reply-To: djgpp-workers AT delorie DOT com

This patch makes two library functions use _get_dev_info()
instead of their own code, which does the same.

Laurynas Biveinis
------------
diff -u -r fcntl.cvs/src/libc/dos/io/setmode.c fcntl/src/libc/dos/io/setmode.c
--- fcntl.cvs/src/libc/dos/io/setmode.c	Thu Jun  3 20:27:36 1999
+++ fcntl/src/libc/dos/io/setmode.c	Fri Jan 14 14:54:40 2000
@@ -1,3 +1,4 @@
+/* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
@@ -19,16 +20,9 @@
   __dpmi_regs regs;
   int oldmode, newmode;
 
-  regs.x.ax = 0x4400;
-  regs.x.bx = handle;
-  regs.x.dx = 0;		/* Clear upper e-word for return */
-  __dpmi_int(0x21, &regs);
-  if (regs.x.flags & 1)
-  {
-    errno = __doserr_to_errno(regs.x.ax);
-    return -1;
-  }
-  oldmode = newmode = regs.x.dx;
+  oldmode = newmode = _get_dev_info(handle);
+  if (oldmode == -1)
+     return -1;
 
   if (mode & O_BINARY)
     newmode |= 0x20;
diff -u -r fcntl.cvs/src/libc/posix/fcntl/fcntl.c fcntl/src/libc/posix/fcntl/fcntl.c
--- fcntl.cvs/src/libc/posix/fcntl/fcntl.c	Thu Jun  3 20:27:38 1999
+++ fcntl/src/libc/posix/fcntl/fcntl.c	Fri Jan 14 14:48:54 2000
@@ -1,3 +1,4 @@
+/* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
@@ -7,26 +8,14 @@
 #include <stdarg.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <io.h>
 #include <sys/fsext.h>
 
-static int
-is_used_fd(int fd)
-{
-  __dpmi_regs regs;
-
-  regs.x.ax = 0x4400;
-  regs.x.bx = fd;
-  __dpmi_int(0x21, &regs);
-  if (regs.x.flags & 1)
-    return 0;
-
-  return 1;
-}
-
 int
 fcntl(int fd, int cmd, ...)
 {
   int tofd, open_max;
+  int old_errno;
   va_list ap;
   __FSEXT_Function *func = __FSEXT_get_function(fd);
   if (func)
@@ -49,12 +38,14 @@
       errno = EINVAL;
       return -1;
     }
+    old_errno = errno;
     while (tofd < open_max)
     {
-      if (! is_used_fd(tofd))
+      if (_get_dev_info(tofd) == -1)
 	break;
       tofd++;
     }
+    errno = old_errno;
 
     if (tofd >= open_max)
     {

- Raw text -


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