delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/01/18/05:42:52

From: Martin Str|mberg <ams AT ludd DOT luth DOT se>
Message-Id: <200301181041.h0IAfYc20680@brother.ludd.luth.se>
Subject: lseek() calling llseek()
To: djgpp-workers AT delorie DOT com (DJGPP-WORKERS)
Date: Sat, 18 Jan 2003 11:41:34 +0100 (MET)
X-Mailer: ELM [version 2.5 PL2]
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com

Hello.

You had comments on that lseek() didn't call llseek() (or they both
calling a common routine). Here's a patch making lseek() call
llseek().

Comments are welcome. In particular on my documentation changes and the 
last return statement in lseek() (which could be made safer with some more 
lines of code).


Right,

						MartinS

Index: djgpp/src/libc/fsext/fsext.txh
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/fsext/fsext.txh,v
retrieving revision 1.15
diff -p -u -r1.15 fsext.txh
--- djgpp/src/libc/fsext/fsext.txh      8 Jul 2002 12:55:42 -0000       1.15
+++ djgpp/src/libc/fsext/fsext.txh      18 Jan 2003 09:53:00 -0000
@@ -98,7 +98,10 @@ A file ioctl handler (@pxref{ioctl (Gene
 
 @item __FSEXT_lseek
 
-A file lseek handler (@pxref{lseek}).
+A file lseek handler (@pxref{lseek}).  Here for backwards
+compatibility.  Use __FSEXT_llseek instead.  If you have a
+__FSEXT_llseek handler you don't need a __FSEXT_lseek handler as lseek
+calls llseek internally.
 
 @item __FSEXT_llseek
 
Index: djgpp/src/libc/posix/unistd/lseek.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/lseek.c,v
retrieving revision 1.6
diff -p -u -r1.6 lseek.c
--- djgpp/src/libc/posix/unistd/lseek.c 14 Jun 2002 14:26:47 -0000      1.6
+++ djgpp/src/libc/posix/unistd/lseek.c 18 Jan 2003 09:53:00 -0000
@@ -1,3 +1,4 @@
+/* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
@@ -16,9 +17,8 @@
 off_t
 lseek(int handle, off_t offset, int whence)
 {
-  __dpmi_regs r;
-  int has_props;
-  
+  offset_t llseek_offset;
+
   __FSEXT_Function *func = __FSEXT_get_function(handle);
   if (func)
   {
@@ -27,39 +27,11 @@ lseek(int handle, off_t offset, int when
       return rv;
   }
 
-  has_props = __has_fd_properties(handle);
-
-  /* POSIX doesn't allow seek on a pipe.  */
-  if (has_props && (__fd_properties[handle]->flags & FILE_DESC_PIPE))
+  llseek_offset = llseek(handle, offset, whence);
+  if( offset == -1 )
   {
-    errno = ESPIPE;
-    return -1;
+    return -1; /* llseek sets errno. */
   }
 
-  r.h.ah = 0x42;
-  r.h.al = whence;
-  r.x.bx = handle;
-  r.x.cx = offset >> 16;
-  r.x.dx = offset & 0xffff;
-  __dpmi_int(0x21, &r);
-  if (r.x.flags & 1)
-  {
-    errno = __doserr_to_errno(r.x.ax);
-    return -1;
-  }  
-
-  if (!has_props ||
-      (__fd_properties[handle]->flags & FILE_DESC_DONT_FILL_EOF_GAP) == 0)
-  {
-    if (offset > 0)
-    {
-      if (!has_props)
-        has_props = (__set_fd_properties(handle, NULL, 0) == 0);
-      if (has_props)
-        __set_fd_flags(handle, FILE_DESC_ZERO_FILL_EOF_GAP);
-    }
-    else if (has_props && (whence == SEEK_SET || whence == SEEK_END))
-      __clear_fd_flags(handle, FILE_DESC_ZERO_FILL_EOF_GAP);
-  }
-  return (r.x.dx << 16) + r.x.ax;
+  return llseek_offset&0xffffffff; /* Magically works right now with
+                                     GCC (no guarantee). The problem
+                                     is when INT_MAX (2^31-1) <
+                                     llseek_offset, which invokes
+                                     implementation defined
+                                     behaviour. */
 }

- Raw text -


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