delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/11/24/15:49:54

Message-Id: <3.0.1.32.19971124144947.007bed80@yacker.xiotech.com>
Date: Mon, 24 Nov 1997 14:49:47 -0600
To: djgpp-workers AT delorie DOT com
From: Randy Maas <randym AT acm DOT org>
Subject: some proposed fsext changes
Mime-Version: 1.0

--=====================_880426187==_
Content-Type: text/plain; charset="us-ascii"

Hello all,

This is a newer set of diff's for extending the file system extensions.
Hopefully I've got it nailed down this time 8-)

Here is a break down of what I am trying to achieve:
1. File system extension support for more io calls: lseek, dup2
2. File system extension support for more named calls: link, remove, unlink
3. Minimize redundancy: the __FSEXT_get_handler and __FSEXT_set_handler
calls are similar to __FSEXT_set_function and __FSEXT_get_function.  But
the former associate a state pointer to the file descriptor as well as a
function to call.  This is help reduce the need for most extensions to
implement their own look-up table.

I have an ulterior motive for most of those: dup2 is required for a pipe
emulator I wrote; lseek, link, unlink, etc. are need for a RAM disk
emulator I am tinkering with.

Here is a map of what io or filename procedures call what (in the set of
diffs attached):
procedure	calls
_close	DOS or FSEXT
_write	DOS or FSEXT
_read	DOS or FSEXT
lseek	_lseek
_lseek	DOS or FSEXT
link	_link
_link	FSEXT or _copy
_copy	FSEXT or does a whole copy
remove	_unlink
unlink	_unlink
_unlink	DOS or FSEXT

To be easier on the mail daemons, I'm breaking this down into 4 parts:
1: the diffs for libc c-files
2. the diffs for libc txh files
3. the "new" files: _copy, _lseek, _dup2, _unlink, _link
4. the txh files for those

Randy
randym AT acm DOT org
--=====================_880426187==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="_close.dif"

*** src/libc/dos/io/_close.c~1	Sat Nov 25 18:47:06 1995
--- src/libc/dos/io/_close.c	Mon Nov 24 12:00:00 1997
***************
*** 1,2
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <unistd.h>

--- 1,3 -----
+ /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  /* Modified 1997, Randall Maas to pass a state variable */
***************
*** 1,3
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <unistd.h>
  #include <errno.h>

--- 1,5 -----
  /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+ /* Modified 1997, Randall Maas to pass a state variable */
  #include <unistd.h>
  #include <errno.h>
***************
*** 14,19
    __dpmi_regs r;
  
!   __FSEXT_Function *func = __FSEXT_get_function(handle);
!   if (func)
    {
      int rv;

--- 16,22 -----
    __dpmi_regs r;
  
!   __FSEXT_Function *func;
!   void* state;
!   if (__FSEXT_get_handler(handle, &func, &state) && func)
    {
      int rv;
***************
*** 18,22
    {
      int rv;
!     if (func(__FSEXT_close, &rv, &handle))
        return rv;
    }

--- 21,25 -----
    {
      int rv;
!     if (func(__FSEXT_close, &rv, &handle, state))
        return rv;
    }

--=====================_880426187==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="_read.dif"

*** src/libc/dos/io/_read.c~1	Sat Nov 25 16:48:30 1995
--- src/libc/dos/io/_read.c	Mon Nov 24 11:59:44 1997
***************
*** 1,2
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <libc/stubs.h>

--- 1,3 -----
+ /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  /* Modified 1997, Randall Maas: passes state variable to extension.*/
***************
*** 1,3
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <libc/stubs.h>
  #include <unistd.h>

--- 1,5 -----
  /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+ /* Modified 1997, Randall Maas: passes state variable to extension.*/
  #include <libc/stubs.h>
  #include <unistd.h>
***************
*** 19,24
    __dpmi_regs r;
  
!   __FSEXT_Function *func = __FSEXT_get_function(handle);
!   if (func)
    {
      int rv;

--- 21,27 -----
    __dpmi_regs r;
  
!   __FSEXT_Function *func;
!   void* state;
!   if (__FSEXT_get_handler(handle, &func, &state) && func)
    {
      int rv;
***************
*** 23,27
    {
      int rv;
!     if (func(__FSEXT_read, &rv, &handle))
        return rv;
    }

--- 26,30 -----
    {
      int rv;
!     if (func(__FSEXT_read, &rv, &handle, state))
        return rv;
    }

--=====================_880426187==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="_write.dif"

*** src/libc/dos/io/_write.c~1	Thu Oct 24 22:26:26 1996
--- src/libc/dos/io/_write.c	Mon Nov 24 12:00:10 1997
***************
*** 19,24
    __dpmi_regs r;
  
!   __FSEXT_Function *func = __FSEXT_get_function(handle);
!   if (func)
    {
      int rv;

--- 19,25 -----
    __dpmi_regs r;
  
!   __FSEXT_Function *func;
!   void* state;
!   if (__FSEXT_get_handler(handle, &func, &state) && func)
    {
      int rv;
***************
*** 23,27
    {
      int rv;
!     if (func(__FSEXT_write, &rv, &handle))
        return rv;
    }

--- 24,28 -----
    {
      int rv;
!     if (func(__FSEXT_write, &rv, &handle, state))
        return rv;
    }

--=====================_880426187==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="dup2.dif"

*** src/libc/posix/unistd/dup2.c~1	Sun Sep 29 09:20:56 1996
--- src/libc/posix/unistd/dup2.c	Mon Nov 24 12:04:04 1997
***************
*** 1,5
! /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
! #include <libc/stubs.h>
! #include <unistd.h>
  #include <fcntl.h>
  #include <dpmi.h>

--- 1,7 -----
! /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details
!    Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details
!    Modified: 1997, Randall Maas: carved it to pieces.  Now reflects the call
!    to _dup2()
!   */
  #include <fcntl.h>
  #include <io.h>
***************
*** 3,8
  #include <unistd.h>
  #include <fcntl.h>
- #include <dpmi.h>
- #include <errno.h>
  #include <io.h>
  #include <libc/dosio.h>

--- 5,8 -----
    */
  #include <fcntl.h>
  #include <io.h>
  #include <unistd.h>
***************
*** 6,10
  #include <errno.h>
  #include <io.h>
! #include <libc/dosio.h>
  
  int

--- 6,10 -----
  #include <fcntl.h>
  #include <io.h>
! #include <unistd.h>
  
  int
***************
*** 9,13
  
  int
! dup2(int fd, int newfd)
  {
    __dpmi_regs r;

--- 9,13 -----
  
  int
! dup2(int existing_handle, int new_handle)
  {
    if (existing_handle == new_handle)
***************
*** 11,28
  dup2(int fd, int newfd)
  {
!   __dpmi_regs r;
!   if (fd == newfd)
!     return newfd;
!   __file_handle_set(newfd, __file_handle_modes[fd] ^ (O_BINARY|O_TEXT));
!   r.h.ah = 0x46;
!   r.x.bx = fd;
!   r.x.cx = newfd;
!   __dpmi_int(0x21, &r);
!   if (r.x.flags & 1)
!   {
!     errno = __doserr_to_errno(r.x.ax);
!     return -1;
!   }
!   setmode(newfd, __file_handle_modes[fd]);
!   return newfd;
  }

--- 11,16 -----
  dup2(int existing_handle, int new_handle)
  {
!   if (existing_handle == new_handle)
!     return new_handle;
!   return _dup2(existing_handle, new_handle);
  }

--=====================_880426187==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="fse_open.dif"

*** src/libc/fsext/fse_open.c~1	Sat Nov 25 18:49:58 1995
--- src/libc/fsext/fse_open.c	Mon Nov 24 11:27:52 1997
***************
*** 1,3
! /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <stdlib.h>
  #include <sys/fsext.h>

--- 1,8 -----
! /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details
!    Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details
!    Modified, 1997 Randall Maas -- uses local fsext.h on non-DJGPP platforms,
!         and sends a "NULL" state variable to the open handlers.
!  */
! 
  #include <stdlib.h>
  #if defined(__DJGPP__)
***************
*** 1,4
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <stdlib.h>
  #include <sys/fsext.h>
  

--- 6,10 -----
  
  #include <stdlib.h>
+ #if defined(__DJGPP__)
  #include <sys/fsext.h>
  #else
***************
*** 2,5
  #include <stdlib.h>
  #include <sys/fsext.h>
  
  typedef struct FuncList {

--- 8,15 -----
  #if defined(__DJGPP__)
  #include <sys/fsext.h>
+ #else
+ #include "fsext.h"
+ #endif
+ #include <errno.h>
  
  typedef struct FuncList {
***************
*** 24,28
  int
  __FSEXT_call_open_handlers(__FSEXT_Fnumber _function_number,
! 			   int *rv, va_list _args)
  {
    FuncList *f;

--- 34,38 -----
  int
  __FSEXT_call_open_handlers(__FSEXT_Fnumber _function_number,
!                          int *rv, va_list _args)
  {
    FuncList *f;
***************
*** 28,32
    FuncList *f;
    for (f=func_list; f; f=f->next)
!     if (f->function(_function_number, rv, _args))
        return 1;
    return 0;

--- 38,42 -----
    FuncList *f;
    for (f=func_list; f; f=f->next)
!     if (f->function(_function_number, rv, _args, NULL))
        return 1;
  
***************
*** 30,33
      if (f->function(_function_number, rv, _args))
        return 1;
    return 0;
  }

--- 40,44 -----
      if (f->function(_function_number, rv, _args, NULL))
        return 1;
+ 
    return 0;
  }

--=====================_880426187==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="fsext.dif"

*** src/libc/fsext/fsext.c~1	Sat Nov 25 17:48:12 1995
--- src/libc/fsext/fsext.c	Mon Nov 24 11:41:10 1997
***************
*** 1,3
! /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <stdio.h>
  #include <stdlib.h>

--- 1,11 -----
! /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details
!    Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details
!    Modified 1997, Randall Maas -- some cpp checks for non-DJGPP environments
! 
!    Note: __FSEXT_get_function and __FSEXT_set_function have the same
!          parameters and semantics as version 2.01.  __FSEXT_get_handler will
!          provide both the function pointer  and the state pointer.
! */
! 
  #include <stdio.h>
  #include <stdlib.h>
***************
*** 2,5
  #include <stdio.h>
  #include <stdlib.h>
  #include <go32.h>
  #include <dpmi.h>

--- 10,14 -----
  #include <stdio.h>
  #include <stdlib.h>
+ #ifdef __DJGPP__
  #include <go32.h>
  #include <dpmi.h>
***************
*** 4,8
  #include <go32.h>
  #include <dpmi.h>
- #include <errno.h>
  #include <sys/fsext.h>
  #include <libc/bss.h>

--- 13,16 -----
  #include <go32.h>
  #include <dpmi.h>
  #include <sys/fsext.h>
  #include <libc/bss.h>
***************
*** 8,11
  #include <libc/bss.h>
  #include <libc/dosio.h>
  
  static int num_fds;

--- 16,26 -----
  #include <libc/bss.h>
  #include <libc/dosio.h>
+ #else
+ #include "fsext.h"
+ #endif
+ #include <fcntl.h>
+ #include <errno.h>
+ #include <io.h>
+ #include <string.h>
  
  #if defined(WIN32)
***************
*** 9,12
  #include <libc/dosio.h>
  
  static int num_fds;
  static __FSEXT_Function **func_list;

--- 24,31 -----
  #include <string.h>
  
+ #if defined(WIN32)
+ #define bzero(a,b) memset(a, 0, b)
+ #endif
+ 
  static int num_fds;
  
***************
*** 10,14
  
  static int num_fds;
- static __FSEXT_Function **func_list;
  
  static void

--- 29,32 -----
  
  static int num_fds;
  
  typedef struct {
***************
*** 12,15
  static __FSEXT_Function **func_list;
  
  static void
  init(void)

--- 30,40 -----
  static int num_fds;
  
+ typedef struct {
+    __FSEXT_Function* func; /* The handler for the descriptor */
+    void* state_ptr; /* The handlers instance data */
+ } __FSEXT_func_rec;
+ 
+ static __FSEXT_func_rec *func_list;
+ 
  static void
  init(void)
***************
*** 31,34
    init();
  
    _put_path("nul");
    r.x.ax = 0x3d82;	/* open, no inherit, read/write */

--- 56,60 -----
    init();
  
+ #ifdef __DJGPP__
    _put_path("nul");
    r.x.ax = 0x3d82;	/* open, no inherit, read/write */
***************
*** 44,47
  
    fd = r.x.ax;
    __FSEXT_set_function(fd, _function);
    return fd;

--- 70,78 -----
  
    fd = r.x.ax;
+ #else
+   /* This is for non-DJGPP environments */
+   fd= open("/dev/null", O_RDWR|O_CREAT);
+ #endif
+ 
    __FSEXT_set_function(fd, _function);
    return fd;
***************
*** 51,54
  __FSEXT_set_function(int _fd, __FSEXT_Function *_function)
  {
    init();
  

--- 82,91 -----
  __FSEXT_set_function(int _fd, __FSEXT_Function *_function)
  {
+   return __FSEXT_set_handler(_fd, _function, NULL);
+ }
+ 
+ __FSEXT_Function *
+ __FSEXT_get_function(int _fd)
+ {
    init();
    if (_fd < 0 || _fd >= num_fds) return 0;
***************
*** 52,55
  {
    init();
  
    if (_fd < 0)

--- 89,95 -----
  {
    init();
+   if (_fd < 0 || _fd >= num_fds) return 0;
+   return func_list[_fd].func;
+ }
  
  int
***************
*** 53,56
    init();
  
    if (_fd < 0)
      return 1;

--- 93,101 -----
  }
  
+ int
+ __FSEXT_set_handler(int _fd, __FSEXT_Function *_function, void* state)
+ {
+   init();
+ 
    if (_fd < 0)
      return 1;
***************
*** 60,64
      int old_fds = num_fds, i;
      num_fds = (_fd+256) & ~255;
!     func_list = (__FSEXT_Function **)realloc(func_list, num_fds * sizeof(__FSEXT_Function *));
      if (func_list == 0)
        return 1;

--- 105,109 -----
      int old_fds = num_fds, i;
      num_fds = (_fd+256) & ~255;
!     func_list = (__FSEXT_func_rec*)realloc(func_list, num_fds * sizeof(__FSEXT_func_rec));
      if (func_list == 0)
        return 1;
***************
*** 64,68
        return 1;
      for (i=old_fds; i<num_fds; i++)
!       func_list[i] = 0;
    }
    func_list[_fd] = _function;

--- 109,113 -----
        return 1;
      for (i=old_fds; i<num_fds; i++)
!       bzero(&func_list[i], sizeof(func_list[i]));
    }
    func_list[_fd].func = _function;
***************
*** 66,70
        func_list[i] = 0;
    }
!   func_list[_fd] = _function;
    return 0;
  }

--- 111,116 -----
        bzero(&func_list[i], sizeof(func_list[i]));
    }
!   func_list[_fd].func = _function;
!   func_list[_fd].state_ptr = state;
    return 0;
  }
***************
*** 70,75
  }
  
! __FSEXT_Function *
! __FSEXT_get_function(int _fd)
  {
    init();

--- 116,121 -----
  }
  
! int
! __FSEXT_get_handler(int _fd, __FSEXT_Function** func, void** state)
  {
    init();
***************
*** 75,79
    init();
    if (_fd < 0 || _fd >= num_fds)
!     return 0;
!   return func_list[_fd];
  }

--- 121,134 -----
    init();
    if (_fd < 0 || _fd >= num_fds)
!     {
!        /* Clear out func just in case */
!        if (func) *func = NULL;
!        return 0;
!     }
! 
!   /* Return the parameters */
!   if (func) *func = func_list[_fd].func;
!   if (state) *state = func_list[_fd].state_ptr;
!   return 1;
  }
  
***************
*** 78,79
    return func_list[_fd];
  }

--- 132,145 -----
    return 1;
  }
+ 
+ void
+ __FSEXT_close_all (void)
+ {
+   int I;
+ 
+   if (!func_list) return;
+   for (I = 0; I < num_fds; I++)
+    if (func_list[I].func)
+      _close(I);
+ }
+ 

--=====================_880426187==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="fsext-h.dif"

*** include/sys/fsext.h~1	Mon Aug 12 23:18:10 1996
--- include/sys/fsext.h	Mon Nov 24 11:42:24 1997
***************
*** 25,28
    __FSEXT_fcntl,
    __FSEXT_ioctl,
  } __FSEXT_Fnumber;
  

--- 25,33 -----
    __FSEXT_fcntl,
    __FSEXT_ioctl,
+   __FSEXT_lseek,
+   __FSEXT_link,
+   __FSEXT_unlink,
+   __FSEXT_copy,
+   __FSEXT_dup2
  } __FSEXT_Fnumber;
  
***************
*** 36,40
     caller's functionality. */
  typedef int (__FSEXT_Function)(__FSEXT_Fnumber _function_number,
! 			       int *_rv, va_list _args);
  
  int               __FSEXT_alloc_fd(__FSEXT_Function *_function);

--- 41,45 -----
     caller's functionality. */
  typedef int (__FSEXT_Function)(__FSEXT_Fnumber _function_number,
!                                int *_rv, va_list _args, void* state);
  
  int               __FSEXT_alloc_fd(__FSEXT_Function *_function);
***************
*** 41,45
  int               __FSEXT_set_function(int _fd, __FSEXT_Function *_function);
  __FSEXT_Function *__FSEXT_get_function(int _fd);
! 
  int               __FSEXT_add_open_handler(__FSEXT_Function *_function);
  int               __FSEXT_call_open_handlers(__FSEXT_Fnumber _function_number,

--- 46,54 -----
  int               __FSEXT_set_function(int _fd, __FSEXT_Function *_function);
  __FSEXT_Function *__FSEXT_get_function(int _fd);
! int               __FSEXT_set_handler(int _fd, __FSEXT_Function *_function,
!                                        void* state);
! int               __FSEXT_get_handler(int _fd, __FSEXT_Function** func,
!                                          void** state);
  int               __FSEXT_add_open_handler(__FSEXT_Function *_function);
  int               __FSEXT_call_open_handlers(__FSEXT_Fnumber _function_number,

--=====================_880426187==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="link.dif"

*** src/libc/posix/unistd/link.c~1	Wed May 10 02:13:46 1995
--- src/libc/posix/unistd/link.c	Mon Nov 24 12:07:16 1997
***************
*** 1,3
! /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <libc/stubs.h>
  #include <sys/stat.h>		/* For stat() */

--- 1,6 -----
! /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details
!    Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details
!    Modified 1997, Randall Maas to be a wrapper to _link.
! */
  #include <libc/stubs.h>
  #include <sys/stat.h>		/* For stat() */
***************
*** 3,7
  #include <sys/stat.h>		/* For stat() */
  #include <fcntl.h>		/* For O_RDONLY, etc. */
- #include <unistd.h>		/* For read(), write(), etc. */
  #include <limits.h>		/* For PATH_MAX */
  #include <utime.h>		/* For utime() */

--- 6,9 -----
  #include <sys/stat.h>		/* For stat() */
  #include <fcntl.h>		/* For O_RDONLY, etc. */
  #include <limits.h>		/* For PATH_MAX */
  #include <utime.h>		/* For utime() */
***************
*** 7,10
  #include <utime.h>		/* For utime() */
  #include <errno.h>		/* For errno */
  
  /* Of course, DOS can't really do a link.  We just do a copy instead,

--- 9,13 -----
  #include <utime.h>		/* For utime() */
  #include <errno.h>		/* For errno */
+ #include <unistd.h>             /*// For read(), write(), etc. */
  
  int
***************
*** 8,14
  #include <errno.h>		/* For errno */
  
- /* Of course, DOS can't really do a link.  We just do a copy instead,
-    which is as close as DOS gets.  Alternatively, we could always fail
-    and return -1.  I think this is slightly better. */
  int
  link(const char *path1, const char *path2)

--- 11,14 -----
  #include <unistd.h>             /*// For read(), write(), etc. */
  
  int
  link(const char *exists, const char *new)
***************
*** 12,16
     and return -1.  I think this is slightly better. */
  int
! link(const char *path1, const char *path2)
  {
    struct stat statbuf1, statbuf2;

--- 12,16 -----
  
  int
! link(const char *exists, const char *new)
  {
     return _link(exists, new);
***************
*** 14,95
  link(const char *path1, const char *path2)
  {
!   struct stat statbuf1, statbuf2;
!   struct utimbuf times;
!   char buf[16384];
!   int fd1, fd2, nbyte, status1, status2;
! 
!   /* Fail if either path is null */
!   if (path1 == NULL || path2 == NULL)
!   {
!     errno = EFAULT;
!     return -1;
!   }
!   if (*path1 == '\0' || *path2 == '\0')
!   {
!     errno = ENOENT;
!     return -1;
!   }
! 
!   /* Fail if path1 does not exist - stat() will set errno */
!   if (stat(path1, &statbuf1) < 0) return -1;
! 
!   /* Fail if path1 is not a regular file */
!   if (!S_ISREG(statbuf1.st_mode))
!   {
!     errno = EPERM;
!     return -1;
!   }
! 
!   /* Fail if unable to open path1 - open() will set errno */
!   fd1 = open(path1, O_RDONLY | O_BINARY);
!   if (fd1 < 0) return -1;
! 
!   /* Fail if unable to create path2 - open() will set errno */
!   fd2 = open(path2, O_WRONLY | O_BINARY | O_CREAT | O_EXCL, 0600);
!   if (fd2 < 0)
!   {
!     (void) close(fd1);
!     return -1;
!   }
! 
!   /* Fail if path1 and path2 are on different devices */
!   if (fstat(fd2, &statbuf2) < 0) return -1;
!   if (statbuf1.st_dev != statbuf2.st_dev)
!   {
!     (void)close(fd1);
!     (void)close(fd2);
!     (void)unlink(path2);
!     errno = EXDEV;
!     return -1;
!   }
! 
!   /* Copy path1 to path2 */
!   do
!   {
!     nbyte = read(fd1, buf, sizeof buf);
!     if (nbyte <= 0) break;
!     if (write(fd2, buf, nbyte) != nbyte) nbyte = -1;
!   }
!   while (nbyte > 0);
! 
!   /* Fail if the copy failed or we can't clean up */
!   status1 = close(fd1);
!   status2 = close(fd2);
!   if (nbyte < 0 || status1 < 0 || status2 < 0)
!   {
!     (void) unlink(path2);
!     return -1;
!   }
! 
!   /* Success! */
! 
!   /* Set the mode to match the original, ignoring errors */
!   (void) chmod(path2, statbuf1.st_mode);
! 
!   /* Set the file time to match the original, ignoring errors */
!   times.actime = statbuf1.st_atime;
!   times.modtime = statbuf1.st_mtime;
!   (void) utime(path2, &times);
! 
!   return 0;
  }

--- 14,18 -----
  link(const char *exists, const char *new)
  {
!    return _link(exists, new);
  }
  
***************
*** 94,95
    return 0;
  }

--- 16,18 -----
     return _link(exists, new);
  }
+ 

--=====================_880426187==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="lseek.dif"

*** src/libc/posix/unistd/lseek.c~1	Sun Feb 26 19:43:10 1995
--- src/libc/posix/unistd/lseek.c	Mon Nov 24 12:08:48 1997
***************
*** 1,3
! /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <libc/stubs.h>
  #include <unistd.h>

--- 1,6 -----
! /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details
!    Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details
!    Modified 1997, Randall Maas. Converted to a wrapper to _lseek
! */
  #include <libc/stubs.h>
  #include <errno.h>
***************
*** 1,5
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <libc/stubs.h>
- #include <unistd.h>
  #include <errno.h>
  #include <go32.h>

--- 4,7 -----
  */
  #include <libc/stubs.h>
  #include <errno.h>
  #include <go32.h>
***************
*** 5,9
  #include <go32.h>
  #include <dpmi.h>
- 
  #include <libc/dosio.h>
  

--- 7,10 -----
  #include <go32.h>
  #include <dpmi.h>
  #include <libc/dosio.h>
  #include <unistd.h>
***************
*** 7,10
  
  #include <libc/dosio.h>
  
  off_t

--- 8,12 -----
  #include <dpmi.h>
  #include <libc/dosio.h>
+ #include <unistd.h>
  
  off_t
***************
*** 9,13
  
  off_t
! lseek(int handle, off_t offset, int whence)
  {
    __dpmi_regs r;

--- 11,15 -----
  
  off_t
! lseek(int fd, off_t offset, int whence)
  {
    return _lseek(fd, offset, whence);
***************
*** 11,26
  lseek(int handle, off_t offset, int whence)
  {
!   __dpmi_regs r;
!   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;
!   }
!   return (r.x.dx << 16) + r.x.ax;
  }

--- 13,17 -----
  lseek(int fd, off_t offset, int whence)
  {
!   return _lseek(fd, offset, whence);
  }
  
***************
*** 25,26
    return (r.x.dx << 16) + r.x.ax;
  }

--- 15,17 -----
    return _lseek(fd, offset, whence);
  }
+ 

--=====================_880426187==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="remove.dif"

*** src/libc/ansi/stdio/remove.c~1	Sat Aug 31 21:09:32 1996
--- src/libc/ansi/stdio/remove.c	Mon Nov 24 12:10:28 1997
***************
*** 1,5
! /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
! #include <libc/stubs.h>
! #include <io.h>
  #include <stdio.h>
  #include <fcntl.h>

--- 1,8 -----
! /*
!    removes a named file
!    Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details
!    Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details
!    Modified: 1997, Randall Maas: Made into a wrapper for _remove
!     */
  #include <stdio.h>
  
***************
*** 3,12
  #include <io.h>
  #include <stdio.h>
! #include <fcntl.h>
! #include <errno.h>
! #include <dpmi.h>
! #include <go32.h>
! #include <libc/dosio.h>
!  
  int
  remove(const char *fn)

--- 6,10 -----
      */
  #include <stdio.h>
! 
  int
  remove(const char *file_name)
***************
*** 10,14
   
  int
! remove(const char *fn)
  {
    __dpmi_regs r;

--- 8,12 -----
  
  int
! remove(const char *file_name)
  {
    return _unlink(file_name);
***************
*** 12,50
  remove(const char *fn)
  {
!   __dpmi_regs r;
!   unsigned attr;
!   int directory_p;
!   int use_lfn = _USE_LFN;
!  
!   /* Get the file attribute byte.  */
!   attr = _chmod(fn, 0);
!   directory_p = attr & 0x10;
!  
!   /* Now, make the file writable.  We must reset Vol, Dir, Sys and Hidden bits 
!      in addition to the Read-Only bit, or else 214301 will fail.  */
!   _chmod(fn, 1, attr & 0xffe0);
! 
!   /* Now delete it.  Note, _chmod leaves dir name in tranfer buffer. */
!   if (directory_p)
!     r.h.ah = 0x3a;		/* DOS Remove Directory function */
!   else
!     r.h.ah = 0x41;		/* DOS Remove File function */
!   if(use_lfn) {
!     r.h.al = r.h.ah;
!     r.h.ah = 0x71;
!     r.x.si = 0;			/* No Wildcards */
!   }
!   r.x.dx = __tb_offset;
!   r.x.ds = __tb_segment;
!   __dpmi_int(0x21, &r);
!   if(r.x.flags & 1)
!   {
!     /* We failed.  Leave the things as we've found them.  */
!     int e = __doserr_to_errno(r.x.ax);
!  
!     _chmod(fn, 1, attr & 0xffe7);
!     errno = e;
!     return -1;
!   }
!   return 0;
  }

--- 10,13 -----
  remove(const char *file_name)
  {
!   return _unlink(file_name);
  }

--=====================_880426187==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="unlink.dif"

*** src/libc/posix/unistd/unlink.S~1	Thu May 25 02:21:26 1995
--- src/libc/posix/unistd/unlink.S	Mon Nov 24 13:13:24 1997
***************
*** 1,3
! /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  	.global	_unlink
  _unlink:

--- 1,5 -----
! /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
! /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details
!    Modified 1997, Randall Maas to call _unlink() instead of remove */
  	.global	_unlink
  _unlink:
***************
*** 2,4
  	.global	_unlink
  _unlink:
! 	jmp	_remove

--- 4,6 -----
  	.global	_unlink
  _unlink:
!         jmp     __unlink

--=====================_880426187==_
Content-Type: text/plain; charset="us-ascii"



--=====================_880426187==_--

- Raw text -


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