delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/12/03/08:47:20

Message-Id: <3.0.1.32.19971203133613.007d1470@yacker.xiotech.com>
Date: Wed, 03 Dec 1997 13:36:13 -0600
To: DJ Delorie <dj AT delorie DOT com>
From: Randy Maas <randym AT acm DOT org>
Subject: Re: patch for fsext.h
Cc: djgpp-workers AT delorie DOT com
In-Reply-To: <199712030022.TAA02585@delorie.com>
References: <3 DOT 0 DOT 1 DOT 32 DOT 19971202130439 DOT 007ae100 AT yacker DOT xiotech DOT com>
Mime-Version: 1.0

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

At 07:22 PM 12/2/97 -0500, you wrote:
>Better yet, drop the fd member and make an array[256] of them (use fd
>as the index).  256 fds = 512*4 bytes = 2048, well within a page size.
>Worst case would be four pages (table spans two pages, lookup
>functions span two pages) but that's worst case already.

The patch (relative to alpha 971114) is attached.
--=====================_881199373==_
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	Wed Dec  3 07:32:58 1997
***************
*** 1,3 ****
--- 1,11 ----
  /* 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.  
+ 
+         This instance data is recovered via __FSEXT_get_data and set with
+         __FSEXT_set_data()
+ */
+ 
  #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
--- 16,30 ----
  #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* data;             /* The handlers instance data */
! } __FSEXT_func_rec;
! 
! static __FSEXT_func_rec *func_list;
  
  static void
***************
*** 58,70 ****
    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;
  }
--- 74,85 ----
    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;
    return 0;
  }
***************
*** 75,79 ****
    init();
    if (_fd < 0 || _fd >= num_fds)
!     return 0;
!   return func_list[_fd];
  }
--- 90,115 ----
    init();
    if (_fd < 0 || _fd >= num_fds)
!    return NULL;
!   return func_list[_fd].func;
! }
! 
! void*
! __FSEXT_set_data(int _fd, void *data)
! {
!   /*
!       Sets the data field to data;
!       Returns NULL on error; data otherwise
!    */
! 
!   if (num_fds <= _fd)
!    return NULL;
! 
!   return func_list[_fd].data = data;
! }
! 
! void*
! __FSEXT_get_data(int _fd)
! {
!    /* NULL on error, otherwise the data */
!    return (num_fds <= _fd) ? NULL : func_list[_fd].data;
  }

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



--=====================_881199373==_--

- Raw text -


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