mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- Added functions which modify the callback function and the userdata pointer
stored in a low level unbuffered file/socket data structure. These function perform the proper locking and are thus safe to use in a thread-safe environment. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15166 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: GNUmakefile.68k,v 1.98 2006-11-13 09:25:28 obarthel Exp $
|
||||
# $Id: GNUmakefile.68k,v 1.99 2006-11-15 09:17:04 obarthel Exp $
|
||||
#
|
||||
# :ts=8
|
||||
#
|
||||
@ -189,6 +189,8 @@ C_LIB = \
|
||||
stat_stat.o \
|
||||
stat_umask.o \
|
||||
stdio_asprintf.o \
|
||||
stdio_change_fd_action.o \
|
||||
stdio_change_fd_user_data.o \
|
||||
stdio_clearerr.o \
|
||||
stdio_dropiobreadbuffer.o \
|
||||
stdio_duplicate_fd.o \
|
||||
@ -228,6 +230,7 @@ C_LIB = \
|
||||
stdio_getchar.o \
|
||||
stdio_getchar_unlocked.o \
|
||||
stdio_gets.o \
|
||||
stdio_get_fd.o \
|
||||
stdio_get_file_descriptor.o \
|
||||
stdio_growfdtable.o \
|
||||
stdio_growiobtable.o \
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
- Added functions which modify the callback function and the userdata pointer
|
||||
stored in a low level unbuffered file/socket data structure. These function
|
||||
perform the proper locking and are thus safe to use in a thread-safe environment.
|
||||
|
||||
- The low level unbuffered file/socket now has a public equivalent, which
|
||||
is defined (along with the typedefs and flags) in <sys/clib2_io.h>. Functions
|
||||
for tinkering with it are still to come.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: clib2_io.h,v 1.1 2006-11-15 08:51:07 obarthel Exp $
|
||||
* $Id: clib2_io.h,v 1.2 2006-11-15 09:17:04 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -153,6 +153,27 @@ struct _fd
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* Obtain a pointer to the _fd data structure associated with a file
|
||||
descriptor number. Note that this does not perform any locking, which
|
||||
means that you have to be absolutely certain that the file will not be
|
||||
closed while you are still looking at it. This function can return
|
||||
NULL if the file descriptor you provided is not valid. */
|
||||
extern struct _fd * __get_fd(int file_descriptor);
|
||||
|
||||
/* Replaces the action callback function and (optionally) returns the old
|
||||
function pointer; returns 0 for success and -1 for failure if you
|
||||
provided an invalid file descriptor. This function performs proper locking
|
||||
and is thus safe to use in a thread-safe environment. */
|
||||
extern int __change_fd_action(int file_descriptor,_file_action_fd_t new_action,_file_action_fd_t * old_action_ptr);
|
||||
|
||||
/* Replaces the user data pointer and (optionally) returns the old user
|
||||
data pointer; returns 0 for success and -1 for failure if you
|
||||
provided an invalid file descriptor. This function performs proper locking
|
||||
and is thus safe to use in a thread-safe environment. */
|
||||
extern int __change_fd_user_data(int file_descriptor,void * new_user_data,void ** old_user_data_ptr);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: libc.gmk,v 1.2 2006-11-13 09:25:28 obarthel Exp $
|
||||
# $Id: libc.gmk,v 1.3 2006-11-15 09:17:04 obarthel Exp $
|
||||
#
|
||||
# :ts=8
|
||||
#
|
||||
@ -90,6 +90,8 @@ C_LIB := \
|
||||
stat_stat.o \
|
||||
stat_umask.o \
|
||||
stdio_asprintf.o \
|
||||
stdio_change_fd_action.o \
|
||||
stdio_change_fd_user_data.o \
|
||||
stdio_clearerr.o \
|
||||
stdio_dropiobreadbuffer.o \
|
||||
stdio_duplicate_fd.o \
|
||||
@ -129,6 +131,7 @@ C_LIB := \
|
||||
stdio_getchar.o \
|
||||
stdio_getchar_unlocked.o \
|
||||
stdio_gets.o \
|
||||
stdio_get_fd.o \
|
||||
stdio_get_file_descriptor.o \
|
||||
stdio_growfdtable.o \
|
||||
stdio_growiobtable.o \
|
||||
|
||||
72
library/stdio_change_fd_action.c
Normal file
72
library/stdio_change_fd_action.c
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* $Id: stdio_change_fd_action.c,v 1.1 2006-11-15 09:17:04 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
* Portable ISO 'C' (1994) runtime library for the Amiga computer
|
||||
* Copyright (c) 2002-2006 by Olaf Barthel <olsen (at) sourcery.han.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Neither the name of Olaf Barthel nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _STDIO_HEADERS_H
|
||||
#include "stdio_headers.h"
|
||||
#endif /* _STDIO_HEADERS_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
int
|
||||
__change_fd_action(
|
||||
int file_descriptor,
|
||||
_file_action_fd_t new_action,
|
||||
_file_action_fd_t * old_action_ptr)
|
||||
{
|
||||
int result = -1;
|
||||
struct fd * fd;
|
||||
|
||||
if(old_action_ptr != NULL)
|
||||
(*old_action_ptr) = NULL;
|
||||
|
||||
__stdio_lock();
|
||||
|
||||
fd = __get_file_descriptor(file_descriptor);
|
||||
if(fd != NULL)
|
||||
{
|
||||
__fd_lock(fd);
|
||||
|
||||
if(old_action_ptr != NULL)
|
||||
(*old_action_ptr) = (_file_action_fd_t)fd->fd_Action;
|
||||
|
||||
fd->fd_Action = (file_action_fd_t)new_action;
|
||||
|
||||
__fd_unlock(fd);
|
||||
|
||||
result = 0;
|
||||
}
|
||||
|
||||
__stdio_unlock();
|
||||
|
||||
return(result);
|
||||
}
|
||||
72
library/stdio_change_fd_user_data.c
Normal file
72
library/stdio_change_fd_user_data.c
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* $Id: stdio_change_fd_user_data.c,v 1.1 2006-11-15 09:17:04 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
* Portable ISO 'C' (1994) runtime library for the Amiga computer
|
||||
* Copyright (c) 2002-2006 by Olaf Barthel <olsen (at) sourcery.han.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Neither the name of Olaf Barthel nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _STDIO_HEADERS_H
|
||||
#include "stdio_headers.h"
|
||||
#endif /* _STDIO_HEADERS_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
int
|
||||
__change_fd_user_data(
|
||||
int file_descriptor,
|
||||
void * new_user_data,
|
||||
void ** old_user_data_ptr)
|
||||
{
|
||||
int result = -1;
|
||||
struct fd * fd;
|
||||
|
||||
if(old_user_data_ptr != NULL)
|
||||
(*old_user_data_ptr) = NULL;
|
||||
|
||||
__stdio_lock();
|
||||
|
||||
fd = __get_file_descriptor(file_descriptor);
|
||||
if(fd != NULL)
|
||||
{
|
||||
__fd_lock(fd);
|
||||
|
||||
if(old_user_data_ptr != NULL)
|
||||
(*old_user_data_ptr) = fd->fd_UserData;
|
||||
|
||||
fd->fd_UserData = new_user_data;
|
||||
|
||||
__fd_unlock(fd);
|
||||
|
||||
result = 0;
|
||||
}
|
||||
|
||||
__stdio_unlock();
|
||||
|
||||
return(result);
|
||||
}
|
||||
48
library/stdio_get_fd.c
Normal file
48
library/stdio_get_fd.c
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* $Id: stdio_get_fd.c,v 1.1 2006-11-15 09:17:04 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
* Portable ISO 'C' (1994) runtime library for the Amiga computer
|
||||
* Copyright (c) 2002-2006 by Olaf Barthel <olsen (at) sourcery.han.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Neither the name of Olaf Barthel nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _STDIO_HEADERS_H
|
||||
#include "stdio_headers.h"
|
||||
#endif /* _STDIO_HEADERS_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct _fd *
|
||||
__get_fd(int file_descriptor)
|
||||
{
|
||||
struct _fd * result;
|
||||
|
||||
result = (struct _fd *)__get_file_descriptor(file_descriptor);
|
||||
|
||||
return(result);
|
||||
}
|
||||
Reference in New Issue
Block a user