Message-Id: <3.0.1.32.19971126103218.007e6100@yacker.xiotech.com> Date: Wed, 26 Nov 1997 10:32:18 -0600 To: djgpp-workers AT delorie DOT com From: Randy Maas Subject: patch for fsext.c Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=====================_880583538==_" Precedence: bulk --=====================_880583538==_ Content-Type: text/plain; charset="us-ascii" --=====================_880583538==_ 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 Nov 26 09:45:06 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 #include *************** *** 8,14 **** #include #include static int num_fds; ! static __FSEXT_Function **func_list; static void --- 18,32 ---- #include #include + #include + #include 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 *************** *** 49,53 **** int ! __FSEXT_set_function(int _fd, __FSEXT_Function *_function) { init(); --- 67,71 ---- 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) ! 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; } --=====================_880583538==_ Content-Type: text/plain; charset="us-ascii" --=====================_880583538==_--