www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/12/01/08:55:41

Message-Id: <3.0.1.32.19971201075824.007df720@yacker.xiotech.com>
Date: Mon, 01 Dec 1997 07:58:24 -0600
To: djgpp-workers AT delorie DOT com
From: Randy Maas <randym AT acm DOT org>
Subject: patch for fsext.c
Mime-Version: 1.0

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

See my previous message for details.
Randy Maas
randym AT acm DOT org
--=====================_881006304==_
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 Dec  1 07:49:10 1997
***************
*** 1,3 ****
--- 1,13 ----
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+ /*
+    Modified 1997, Randall Maas -- some changes to allow a "state" to be
+         associated with FSEXT, to help them out a bit.
+ 
+    Note: __FSEXT_get_function and __FSEXT_set_function do not have the same
+          parameters as version 2.01.  These now support an additional state
+          pointer for use by the fsext.  The state pointer can be unique to
+          each file descriptor and handler pair.
+ */
+ 
  #include <stdio.h>
  #include <stdlib.h>
***************
*** 8,14 ****
  #include <libc/bss.h>
  #include <libc/dosio.h>
  
  static int num_fds;
! static __FSEXT_Function **func_list;
  
  static void
--- 18,32 ----
  #include <libc/bss.h>
  #include <libc/dosio.h>
+ #include <io.h>
+ #include <string.h>
  
  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
***************
*** 24,28 ****
  
  int
! __FSEXT_alloc_fd(__FSEXT_Function *_function)
  {
    int fd;
--- 42,46 ----
  
  int
! __FSEXT_alloc_fd(__FSEXT_Function *_function, void* state)
  {
    int fd;
***************
*** 44,53 ****
  
    fd = r.x.ax;
!   __FSEXT_set_function(fd, _function);
    return fd;
  }
  
  int
! __FSEXT_set_function(int _fd, __FSEXT_Function *_function)
  {
    init();
--- 62,71 ----
  
    fd = r.x.ax;
!   __FSEXT_set_function(fd, _function, state);
    return fd;
  }
  
  int
! __FSEXT_set_function(int _fd, __FSEXT_Function *_function, void* state)
  {
    init();
***************
*** 58,79 ****
    if (num_fds <= _fd)
    {
!     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;
!     for (i=old_fds; i<num_fds; i++)
!       func_list[i] = 0;
    }
!   func_list[_fd] = _function;
    return 0;
  }
  
! __FSEXT_Function *
! __FSEXT_get_function(int _fd)
  {
    init();
    if (_fd < 0 || _fd >= num_fds)
!     return 0;
!   return func_list[_fd];
  }
--- 76,105 ----
    if (num_fds <= _fd)
    {
!     int old_fds = num_fds;
      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;
!     memset(&func_list[old_fds], 0, sizeof(func_list[old_fds])*(num_fds-old_fds));
    }
!   func_list[_fd].func = _function;
!   func_list[_fd].state_ptr = state;
    return 0;
  }
  
! int
! __FSEXT_get_function(int _fd, __FSEXT_Function** func, void** state)
  {
    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;
  }

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



--=====================_881006304==_--

- Raw text -


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