1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

- The buffered and unbuffered file hook code is now invoked through

function pointers alone. The utility.library/CallHookPkt mechanism
  is no longer required.

- Moved the entire lseek() code relevant for files into the hook
  function.

- Simplified the close() function which now just calls into the
  hook code to perform whatever is necessary. The hook code is
  responsible for cleaning up after aliases, etc. This change in
  turn made it possible to greatly simplify the hook code for
  buffered files which now bypasses close/read/write/lseek and
  directly invokes the hook code for unbuffered files.


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14835 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2005-02-20 13:19:40 +00:00
parent cfa6f566db
commit 410833d2ed
42 changed files with 841 additions and 999 deletions

View File

@ -1,5 +1,5 @@
#
# $Id: GNUmakefile.68k,v 1.27 2005-02-18 18:53:16 obarthel Exp $
# $Id: GNUmakefile.68k,v 1.28 2005-02-20 13:19:40 obarthel Exp $
#
# :ts=8
#
@ -228,6 +228,7 @@ C_LIB = \
stdio_putchar.o \
stdio_puts.o \
stdio_remove.o \
stdio_remove_fd_alias.o \
stdio_rename.o \
stdio_rewind.o \
stdio_scanf.o \

View File

@ -1,5 +1,5 @@
#
# $Id: GNUmakefile.os4,v 1.27 2005-02-18 18:53:16 obarthel Exp $
# $Id: GNUmakefile.os4,v 1.28 2005-02-20 13:19:40 obarthel Exp $
#
# :ts=8
#
@ -232,6 +232,7 @@ C_LIB = \
stdio_putchar.o \
stdio_puts.o \
stdio_remove.o \
stdio_remove_fd_alias.o \
stdio_rename.o \
stdio_rewind.o \
stdio_scanf.o \

View File

@ -1,6 +1,6 @@
- Rewrote the __translate_unix_to_amiga_path_name() function to
translate patterns such as "foo/bar/../../baz" properly, and to
use strlen() less.
use strlen() a lot less.
- Major, major changes! Moved most of the monolithic code out of
the file descriptor hook and into the respective functions,
@ -11,6 +11,20 @@
NOTE: these changes require that the entire library is rebuilt!
- The buffered and unbuffered file hook code is now invoked through
function pointers alone. The utility.library/CallHookPkt mechanism
is no longer required.
- Moved the entire lseek() code relevant for files into the hook
function.
- Simplified the close() function which now just calls into the
hook code to perform whatever is necessary. The hook code is
responsible for cleaning up after aliases, etc. This change in
turn made it possible to greatly simplify the hook code for
buffered files which now bypasses close/read/write/lseek and
directly invokes the hook code for unbuffered files.
c.lib 1.188 (7.2.2005)

View File

@ -1,5 +1,5 @@
/*
* $Id: fcntl_close.c,v 1.8 2005-02-04 08:49:10 obarthel Exp $
* $Id: fcntl_close.c,v 1.9 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -42,23 +42,16 @@
/****************************************************************************/
int
__close(int file_descriptor,int * error_ptr)
close(int file_descriptor)
{
DECLARE_UTILITYBASE();
struct file_hook_message message;
struct file_action_message fam;
struct fd * fd;
int result = -1;
BOOL no_close;
BOOL is_alias;
ENTER();
SHOWVALUE(file_descriptor);
assert( UtilityBase != NULL );
assert( error_ptr != NULL );
assert( file_descriptor >= 0 && file_descriptor < __num_fd );
assert( __fd[file_descriptor] != NULL );
assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) );
@ -69,121 +62,20 @@ __close(int file_descriptor,int * error_ptr)
fd = __get_file_descriptor(file_descriptor);
if(fd == NULL)
{
(*error_ptr) = EBADF;
__set_errno(EBADF);
goto out;
}
result = 0;
fam.fam_Action = file_action_close;
SHOWMSG("last customer; cleaning up");
assert( fd->fd_Action != NULL );
if(fd->fd_Original != NULL) /* this is an alias */
{
struct fd * list_fd;
SHOWMSG("taking out the alias");
assert( fd->fd_Original != fd );
assert( fd->fd_Original->fd_Original == NULL );
/* Remove this alias from the list. */
for(list_fd = fd->fd_Original ;
list_fd != NULL ;
list_fd = list_fd->fd_NextLink)
{
if(list_fd->fd_NextLink == fd)
{
list_fd->fd_NextLink = fd->fd_NextLink;
break;
}
}
no_close = TRUE;
is_alias = TRUE;
}
else if (fd->fd_NextLink != NULL) /* this one has aliases attached; it is the 'original' resource */
{
struct fd * first_alias;
struct fd * list_fd;
SHOWMSG("closing original descriptor; migrating it to first alias");
/* The first link now becomes the original resource */
first_alias = fd->fd_NextLink;
first_alias->fd_Original = NULL;
/* The resources are migrated to the first link. */
for(list_fd = first_alias->fd_NextLink ;
list_fd != NULL ;
list_fd = list_fd->fd_NextLink)
{
list_fd->fd_Original = first_alias;
}
no_close = TRUE;
is_alias = TRUE;
}
else
{
no_close = FLAG_IS_SET(fd->fd_Flags,FDF_NO_CLOSE);
is_alias = FALSE;
}
/* Reset the console to regular buffered/unbuffered input. We don't do this
for aliases and their like since the original stream is still in use. */
if(NOT is_alias)
{
if(FLAG_IS_SET(fd->fd_Flags,FDF_NON_BLOCKING))
{
SHOWMSG("resetting non-blocking access mode");
message.action = file_hook_action_set_blocking;
message.arg = TRUE;
assert( fd->fd_Hook != NULL );
CallHookPkt(fd->fd_Hook,fd,&message);
}
}
(*error_ptr) = OK;
if(NOT no_close && NOT is_alias)
{
SHOWMSG("shutting down");
message.action = file_hook_action_close;
assert( fd->fd_Hook != NULL );
CallHookPkt(fd->fd_Hook,fd,&message);
result = message.result;
(*error_ptr) = message.error;
}
memset(fd,0,sizeof(*fd));
result = (*fd->fd_Action)(fd,&fam);
if(result < 0)
__set_errno(fam.fam_Error);
out:
RETURN(result);
return(result);
}
/****************************************************************************/
int
close(int file_descriptor)
{
int result;
int error;
ENTER();
result = __close(file_descriptor,&error);
__set_errno(error);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: fcntl_fcntl.c,v 1.8 2005-02-20 09:03:02 obarthel Exp $
* $Id: fcntl_fcntl.c,v 1.9 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -44,8 +44,7 @@
int
fcntl(int file_descriptor, int cmd, ... /* int arg */ )
{
DECLARE_UTILITYBASE();
struct file_hook_message message;
struct file_action_message fam;
struct flock * l;
int vacant_slot;
int result = -1;
@ -61,8 +60,6 @@ fcntl(int file_descriptor, int cmd, ... /* int arg */ )
SHOWVALUE(file_descriptor);
SHOWVALUE(cmd);
assert( UtilityBase != NULL );
assert( file_descriptor >= 0 && file_descriptor < __num_fd );
assert( __fd[file_descriptor] != NULL );
assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) );
@ -160,16 +157,14 @@ fcntl(int file_descriptor, int cmd, ... /* int arg */ )
if((FLAG_IS_SET(flags,O_NONBLOCK) && FLAG_IS_CLEAR(fd->fd_Flags,FDF_NON_BLOCKING)) ||
(FLAG_IS_CLEAR(flags,O_NONBLOCK) && FLAG_IS_SET(fd->fd_Flags,FDF_NON_BLOCKING)))
{
message.action = file_hook_action_set_blocking;
message.arg = FLAG_IS_CLEAR(flags,O_NONBLOCK);
fam.fam_Action = file_action_set_blocking;
fam.fam_Arg = FLAG_IS_CLEAR(flags,O_NONBLOCK);
assert( fd->fd_Hook != NULL );
assert( fd->fd_Action != NULL );
CallHookPkt(fd->fd_Hook,fd,&message);
if(message.result < 0)
if((*fd->fd_Action)(fd,&fam) < 0)
{
__set_errno(message.error);
__set_errno(fam.fam_Error);
goto out;
}
@ -183,16 +178,14 @@ fcntl(int file_descriptor, int cmd, ... /* int arg */ )
if((FLAG_IS_SET(flags,O_ASYNC) && FLAG_IS_CLEAR(fd->fd_Flags,FDF_ASYNC_IO)) ||
(FLAG_IS_CLEAR(flags,O_ASYNC) && FLAG_IS_SET(fd->fd_Flags,FDF_ASYNC_IO)))
{
message.action = file_hook_action_set_async;
message.arg = FLAG_IS_SET(flags,O_ASYNC);
fam.fam_Action = file_action_set_async;
fam.fam_Arg = FLAG_IS_SET(flags,O_ASYNC);
assert( fd->fd_Hook != NULL );
assert( fd->fd_Action != NULL );
CallHookPkt(fd->fd_Hook,fd,&message);
if(message.result < 0)
if((*fd->fd_Action)(fd,&fam) < 0)
{
__set_errno(message.error);
__set_errno(fam.fam_Error);
goto out;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: fcntl_lseek.c,v 1.5 2005-02-18 18:53:16 obarthel Exp $
* $Id: fcntl_lseek.c,v 1.6 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -42,15 +42,11 @@
/****************************************************************************/
off_t
__lseek(int file_descriptor, off_t offset, int mode, int * error_ptr)
lseek(int file_descriptor, off_t offset, int mode)
{
D_S(struct FileInfoBlock,fib);
struct file_action_message fam;
off_t result = -1;
struct fd * fd;
BOOL fib_is_valid = FALSE;
LONG current_position;
LONG new_position;
LONG new_mode;
ENTER();
@ -58,7 +54,6 @@ __lseek(int file_descriptor, off_t offset, int mode, int * error_ptr)
SHOWVALUE(offset);
SHOWVALUE(mode);
assert( error_ptr != NULL );
assert( file_descriptor >= 0 && file_descriptor < __num_fd );
assert( __fd[file_descriptor] != NULL );
assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) );
@ -69,15 +64,7 @@ __lseek(int file_descriptor, off_t offset, int mode, int * error_ptr)
fd = __get_file_descriptor(file_descriptor);
if(fd == NULL)
{
(*error_ptr) = EBADF;
goto out;
}
if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_SOCKET))
{
SHOWMSG("can't seek on a socket");
(*error_ptr) = ESPIPE;
__set_errno(EBADF);
goto out;
}
@ -85,129 +72,25 @@ __lseek(int file_descriptor, off_t offset, int mode, int * error_ptr)
{
SHOWMSG("seek mode is invalid");
(*error_ptr) = EINVAL;
__set_errno(EINVAL);
goto out;
}
if(mode == SEEK_CUR)
new_mode = OFFSET_CURRENT;
else if (mode == SEEK_SET)
new_mode = OFFSET_BEGINNING;
else
new_mode = OFFSET_END;
fam.fam_Action = file_action_seek;
fam.fam_Position = offset;
fam.fam_Mode = mode;
D(("seek&extended to offset %ld, mode %ld; current position = %ld",offset,new_mode,Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT)));
assert( fd->fd_Action != NULL );
if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION))
result = (*fd->fd_Action)(fd,&fam);
if(result < 0)
{
current_position = fd->fd_Position;
__set_errno(fam.fam_Error);
goto out;
}
else
{
PROFILE_OFF();
current_position = Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT);
PROFILE_ON();
if(current_position < 0)
{
(*error_ptr) = EBADF;
goto out;
}
}
new_position = current_position;
switch(new_mode)
{
case OFFSET_CURRENT:
new_position += offset;
break;
case OFFSET_BEGINNING:
new_position = offset;
break;
case OFFSET_END:
if(__safe_examine_file_handle(fd->fd_DefaultFile,fib))
{
new_position = fib->fib_Size + offset;
fib_is_valid = TRUE;
}
break;
}
if(new_position != current_position)
{
LONG position;
PROFILE_OFF();
position = Seek(fd->fd_DefaultFile,offset,new_mode);
PROFILE_ON();
if(position < 0)
{
D(("seek failed, mode=%ld (%ld), offset=%ld, ioerr=%ld",new_mode,message->mode,offset,IoErr()));
(*error_ptr) = __translate_io_error_to_errno(IoErr());
#if defined(UNIX_PATH_SEMANTICS)
{
if(NOT fib_is_valid && CANNOT __safe_examine_file_handle(fd->fd_DefaultFile,fib))
{
(*error_ptr) = __translate_io_error_to_errno(IoErr());
goto out;
}
if(new_position <= fib->fib_Size)
{
(*error_ptr) = __translate_io_error_to_errno(IoErr());
goto out;
}
if(__grow_file_size(fd,new_position - fib->fib_Size) != OK)
{
(*error_ptr) = __translate_io_error_to_errno(IoErr());
goto out;
}
}
#else
{
(*error_ptr) = __translate_io_error_to_errno(IoErr());
goto out;
}
#endif /* UNIX_PATH_SEMANTICS */
}
}
if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION))
fd->fd_Position = new_position;
result = new_position;
out:
RETURN(result);
return(result);
}
/****************************************************************************/
off_t
lseek(int file_descriptor, off_t offset, int mode)
{
off_t result;
int error;
ENTER();
result = __lseek(file_descriptor,offset,mode,&error);
__set_errno(error);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: fcntl_open.c,v 1.8 2005-02-03 16:56:15 obarthel Exp $
* $Id: fcntl_open.c,v 1.9 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -328,7 +328,7 @@ open(const char *path_name, int open_flag, ... /* mode_t mode */ )
fd = __fd[fd_slot_number];
__initialize_fd(fd,(HOOKFUNC)__fd_hook_entry,handle,0);
__initialize_fd(fd,__fd_hook_entry,handle,0);
/* Figure out if this stream is attached to a console. */
PROFILE_OFF();
@ -343,7 +343,7 @@ open(const char *path_name, int open_flag, ... /* mode_t mode */ )
{
SHOWMSG("enabling non-blocking mode");
if(SetMode(handle,1)) /* single character mode */
if(SetMode(handle,DOSTRUE)) /* single character mode */
SET_FLAG(fd->fd_Flags,FDF_NON_BLOCKING);
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: fcntl_read.c,v 1.4 2005-02-03 16:56:15 obarthel Exp $
* $Id: fcntl_read.c,v 1.5 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -48,9 +48,8 @@
/****************************************************************************/
ssize_t
__read(int file_descriptor, void * buffer, size_t num_bytes, int * error_ptr)
read(int file_descriptor, void * buffer, size_t num_bytes)
{
DECLARE_UTILITYBASE();
struct fd * fd;
off_t result = -1;
@ -60,10 +59,8 @@ __read(int file_descriptor, void * buffer, size_t num_bytes, int * error_ptr)
SHOWPOINTER(buffer);
SHOWVALUE(num_bytes);
assert( error_ptr != NULL );
assert( buffer != NULL );
assert( (int)num_bytes >= 0);
assert( UtilityBase != NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
@ -71,7 +68,7 @@ __read(int file_descriptor, void * buffer, size_t num_bytes, int * error_ptr)
{
SHOWMSG("invalid buffer");
(*error_ptr) = EFAULT;
__set_errno(EFAULT);
goto out;
}
}
@ -87,7 +84,7 @@ __read(int file_descriptor, void * buffer, size_t num_bytes, int * error_ptr)
fd = __get_file_descriptor(file_descriptor);
if(fd == NULL)
{
(*error_ptr) = EBADF;
__set_errno(EBADF);
goto out;
}
@ -95,32 +92,28 @@ __read(int file_descriptor, void * buffer, size_t num_bytes, int * error_ptr)
{
SHOWMSG("this descriptor is not read-enabled");
(*error_ptr) = EBADF;
__set_errno(EBADF);
goto out;
}
if(num_bytes > 0)
{
struct file_hook_message message;
struct file_action_message fam;
SHOWMSG("calling the hook");
message.action = file_hook_action_read;
message.data = buffer;
message.size = num_bytes;
fam.fam_Action = file_action_read;
fam.fam_Data = buffer;
fam.fam_Size = num_bytes;
assert( fd->fd_Hook != NULL );
assert( fd->fd_Action != NULL );
CallHookPkt(fd->fd_Hook,fd,&message);
(*error_ptr) = message.error;
result = message.result;
result = (*fd->fd_Action)(fd,&fam);
if(result < 0)
__set_errno(fam.fam_Error);
}
else
{
(*error_ptr) = 0;
result = 0;
}
@ -129,20 +122,3 @@ __read(int file_descriptor, void * buffer, size_t num_bytes, int * error_ptr)
RETURN(result);
return(result);
}
/****************************************************************************/
ssize_t
read(int file_descriptor, void * buffer, size_t num_bytes)
{
ssize_t result;
int error;
ENTER();
result = __read(file_descriptor,buffer,num_bytes,&error);
__set_errno(error);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: fcntl_write.c,v 1.4 2005-02-03 16:56:15 obarthel Exp $
* $Id: fcntl_write.c,v 1.5 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -48,9 +48,8 @@
/****************************************************************************/
ssize_t
__write(int file_descriptor, const void * buffer, size_t num_bytes, int * error_ptr)
write(int file_descriptor, const void * buffer, size_t num_bytes)
{
DECLARE_UTILITYBASE();
struct fd * fd;
off_t result = -1;
@ -60,10 +59,8 @@ __write(int file_descriptor, const void * buffer, size_t num_bytes, int * error_
SHOWPOINTER(buffer);
SHOWVALUE(num_bytes);
assert( error_ptr != NULL );
assert( buffer != NULL );
assert( (int)num_bytes >= 0 );
assert( UtilityBase != NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
@ -71,7 +68,7 @@ __write(int file_descriptor, const void * buffer, size_t num_bytes, int * error_
{
SHOWMSG("invalid buffer address");
(*error_ptr) = EFAULT;
__set_errno(EFAULT);
goto out;
}
}
@ -87,7 +84,7 @@ __write(int file_descriptor, const void * buffer, size_t num_bytes, int * error_
fd = __get_file_descriptor(file_descriptor);
if(fd == NULL)
{
(*error_ptr) = EBADF;
__set_errno(EBADF);
goto out;
}
@ -95,32 +92,28 @@ __write(int file_descriptor, const void * buffer, size_t num_bytes, int * error_
{
SHOWMSG("file descriptor is not write-enabled");
(*error_ptr) = EBADF;
__set_errno(EBADF);
goto out;
}
if(num_bytes > 0)
{
struct file_hook_message message;
struct file_action_message fam;
SHOWMSG("calling the hook");
message.action = file_hook_action_write;
message.data = (void *)buffer;
message.size = num_bytes;
fam.fam_Action = file_action_write;
fam.fam_Data = (void *)buffer;
fam.fam_Size = num_bytes;
assert( fd->fd_Hook != NULL );
assert( fd->fd_Action != NULL );
CallHookPkt(fd->fd_Hook,fd,&message);
(*error_ptr) = message.error;
result = message.result;
result = (*fd->fd_Action)(fd,&fam);
if(result < 0)
__set_errno(fam.fam_Error);
}
else
{
(*error_ptr) = 0;
result = 0;
}
@ -129,20 +122,3 @@ __write(int file_descriptor, const void * buffer, size_t num_bytes, int * error_
RETURN(result);
return(result);
}
/****************************************************************************/
ssize_t
write(int file_descriptor, const void * buffer, size_t num_bytes)
{
ssize_t result;
int error;
ENTER();
result = __write(file_descriptor,buffer,num_bytes,&error);
__set_errno(error);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
_#
# $Id: smakefile,v 1.21 2005-02-18 18:53:16 obarthel Exp $
# $Id: smakefile,v 1.22 2005-02-20 13:19:40 obarthel Exp $
#
# :ts=8
#
@ -28,7 +28,7 @@ INCLUDE_DIR = V:include
#DEBUG = debug=line noopt define=CHECK_FOR_NULL_POINTERS
#DEBUG = debug=line
#DEBUG = debug=line define=NDEBUG
DEBUG = debug=sf noopt
DEBUG = debug=sf noopt define=DEBUG
#DEBUG = debug=sf noopt define=CHECK_FOR_NULL_POINTERS
#PROFILE = profile
DATA = data=faronly
@ -292,6 +292,7 @@ STDIO_OBJ = \
stdio_fclose.o \
stdio_fdhookentry.o \
stdio_record_locking.o \
stdio_remove_fd_alias.o \
stdio_feof.o \
stdio_ferror.o \
stdio_fflush.o \

View File

@ -1,5 +1,5 @@
/*
* $Id: socket_accept.c,v 1.4 2005-02-18 18:53:16 obarthel Exp $
* $Id: socket_accept.c,v 1.5 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -111,7 +111,7 @@ accept(int sockfd,struct sockaddr *cliaddr,int *addrlen)
new_fd = __fd[new_fd_slot_number];
__initialize_fd(new_fd,(HOOKFUNC)__socket_hook_entry,(BPTR)new_socket_fd,FDF_IN_USE | FDF_IS_SOCKET | FDF_READ | FDF_WRITE);
__initialize_fd(new_fd,__socket_hook_entry,(BPTR)new_socket_fd,FDF_IN_USE | FDF_IS_SOCKET | FDF_READ | FDF_WRITE);
result = new_fd_slot_number;

View File

@ -1,5 +1,5 @@
/*
* $Id: socket_headers.h,v 1.6 2005-02-18 18:53:16 obarthel Exp $
* $Id: socket_headers.h,v 1.7 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -71,7 +71,7 @@ extern int NOCOMMON h_errno;
/****************************************************************************/
extern struct fd * __get_file_descriptor_socket(int socket_descriptor);
extern void __socket_hook_entry(struct Hook * hook,struct fd * fd,struct file_hook_message * message);
extern int __socket_hook_entry(struct fd * fd,struct file_action_message * fam);
/****************************************************************************/

View File

@ -1,5 +1,5 @@
/*
* $Id: socket_hook_entry.c,v 1.7 2005-02-18 18:53:16 obarthel Exp $
* $Id: socket_hook_entry.c,v 1.8 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -45,102 +45,127 @@
/****************************************************************************/
void
int
__socket_hook_entry(
struct Hook * UNUSED unused_hook,
struct fd * fd,
struct file_hook_message * message)
struct fd * fd,
struct file_action_message * fam)
{
struct FileInfoBlock * fib;
int error = OK;
int param;
int result;
int param;
assert( message != NULL && fd != NULL );
assert( fam != NULL && fd != NULL );
switch(message->action)
switch(fam->fam_Action)
{
case file_hook_action_read:
case file_action_read:
SHOWMSG("file_hook_action_read");
SHOWMSG("file_action_read");
assert( message->data != NULL );
assert( message->size > 0 );
assert( fam->fam_Data != NULL );
assert( fam->fam_Size > 0 );
SHOWVALUE(message->data);
SHOWVALUE(message->size);
SHOWPOINTER(fam->fam_Data);
SHOWVALUE(fam->fam_Size);
PROFILE_OFF();
result = __recv((LONG)fd->fd_DefaultFile,message->data,message->size,0);
error = __get_errno();
result = __recv((LONG)fd->fd_DefaultFile,fam->fam_Data,fam->fam_Size,0);
if(result < 0)
error = __get_errno();
PROFILE_ON();
break;
case file_hook_action_write:
case file_action_write:
SHOWMSG("file_hook_action_write");
SHOWMSG("file_action_write");
assert( message->data != NULL );
assert( message->size > 0 );
assert( fam->fam_Data != NULL );
assert( fam->fam_Size > 0 );
SHOWVALUE(message->data);
SHOWVALUE(message->size);
SHOWPOINTER(fam->fam_Data);
SHOWVALUE(fam->fam_Size);
PROFILE_OFF();
result = __send((LONG)fd->fd_DefaultFile,message->data,message->size,0);
error = __get_errno();
result = __send((LONG)fd->fd_DefaultFile,fam->fam_Data,fam->fam_Size,0);
if(result < 0)
error = __get_errno();
PROFILE_ON();
break;
case file_hook_action_close:
case file_action_close:
SHOWMSG("file_hook_action_close");
SHOWMSG("file_action_close");
PROFILE_OFF();
/* If this is an alias, just remove it. */
if(__fd_is_aliased(fd))
{
__remove_fd_alias(fd);
}
else
{
/* Are we permitted to close this file? */
if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_NO_CLOSE))
{
PROFILE_OFF();
__CloseSocket((LONG)fd->fd_DefaultFile);
__CloseSocket((LONG)fd->fd_DefaultFile);
PROFILE_ON();
PROFILE_ON();
}
}
fd->fd_DefaultFile = -1; /* paranoia! */
/* And that's the last for this file descriptor. */
memset(fd,0,sizeof(*fd));
result = 0;
break;
case file_hook_action_set_blocking:
case file_action_seek:
SHOWMSG("file_hook_action_set_blocking");
SHOWMSG("file_action_seek");
param = (int)(message->arg == 0);
result = __IoctlSocket(fd->fd_DefaultFile,FIONBIO,&param);
error = __get_errno();
result = -1;
error = ESPIPE;
break;
case file_hook_action_set_async:
case file_action_set_blocking:
SHOWMSG("file_hook_action_set_async");
SHOWMSG("file_action_set_blocking");
param = (int)(message->arg != 0);
param = (int)(fam->fam_Arg == 0);
result = __IoctlSocket(fd->fd_DefaultFile,FIOASYNC,&param);
error = __get_errno();
result = __IoctlSocket(fd->fd_DefaultFile,FIONBIO,&param);
if(result < 0)
error = __get_errno();
break;
case file_hook_action_examine:
case file_action_set_async:
SHOWMSG("file_hook_action_examine");
SHOWMSG("file_action_set_async");
fib = message->file_info;
param = (int)(fam->fam_Arg != 0);
result = __IoctlSocket(fd->fd_DefaultFile,FIOASYNC,&param);
if(result < 0)
error = __get_errno();
break;
case file_action_examine:
SHOWMSG("file_action_examine");
fib = fam->fam_FileInfo;
memset(fib,0,sizeof(*fib));
@ -156,7 +181,7 @@ __socket_hook_entry(
default:
SHOWVALUE(message->action);
SHOWVALUE(fam->fam_Action);
result = -1;
error = EBADF;
@ -164,10 +189,10 @@ __socket_hook_entry(
break;
}
SHOWVALUE(result);
fam->fam_Error = error;
message->result = result;
message->error = error;
RETURN(result);
return(result);
}
/****************************************************************************/

View File

@ -1,5 +1,5 @@
/*
* $Id: socket_init_exit.c,v 1.8 2005-01-09 10:10:41 obarthel Exp $
* $Id: socket_init_exit.c,v 1.9 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -277,7 +277,7 @@ __socket_init(void)
}
}
__initialize_fd(fd,(HOOKFUNC)__socket_hook_entry,(BPTR)sockfd,FDF_IN_USE | FDF_IS_SOCKET | FDF_READ | FDF_WRITE);
__initialize_fd(fd,__socket_hook_entry,(BPTR)sockfd,FDF_IN_USE | FDF_IS_SOCKET | FDF_READ | FDF_WRITE);
}
/* This program now runs as an internet superserver client (daemon). */

View File

@ -1,5 +1,5 @@
/*
* $Id: socket_socket.c,v 1.2 2005-01-02 09:07:08 obarthel Exp $
* $Id: socket_socket.c,v 1.3 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -80,7 +80,7 @@ socket(int domain,int type,int protocol)
fd = __fd[fd_slot_number];
__initialize_fd(fd,(HOOKFUNC)__socket_hook_entry,(BPTR)socket_fd,FDF_IN_USE | FDF_IS_SOCKET | FDF_READ | FDF_WRITE);
__initialize_fd(fd,__socket_hook_entry,(BPTR)socket_fd,FDF_IN_USE | FDF_IS_SOCKET | FDF_READ | FDF_WRITE);
result = fd_slot_number;

View File

@ -1,5 +1,5 @@
/*
* $Id: stat_fstat.c,v 1.4 2005-02-03 16:56:15 obarthel Exp $
* $Id: stat_fstat.c,v 1.5 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -50,8 +50,7 @@
int
fstat(int file_descriptor, struct stat * buffer)
{
DECLARE_UTILITYBASE();
struct file_hook_message message;
struct file_action_message fam;
D_S(struct FileInfoBlock,fib);
int result = -1;
struct fd * fd;
@ -62,7 +61,6 @@ fstat(int file_descriptor, struct stat * buffer)
SHOWPOINTER(buffer);
assert( buffer != NULL );
assert( UtilityBase != NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
@ -92,22 +90,19 @@ fstat(int file_descriptor, struct stat * buffer)
SHOWMSG("calling the hook");
message.action = file_hook_action_examine;
message.file_info = fib;
message.file_system = NULL;
fam.fam_Action = file_action_examine;
fam.fam_FileInfo = fib;
fam.fam_FileSystem = NULL;
assert( fd->fd_Hook != NULL );
assert( fd->fd_Action != NULL );
CallHookPkt(fd->fd_Hook,fd,&message);
result = message.result;
if(result != 0)
if((*fd->fd_Action)(fd,&fam) < 0)
{
__set_errno(message.error);
__set_errno(fam.fam_Error);
goto out;
}
__convert_file_info_to_stat(message.file_system,fib,buffer);
__convert_file_info_to_stat(fam.fam_FileSystem,fib,buffer);
out:

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_dropiobreadbuffer.c,v 1.3 2005-02-03 16:56:15 obarthel Exp $
* $Id: stdio_dropiobreadbuffer.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -45,7 +45,6 @@
int
__drop_iob_read_buffer(struct iob * file)
{
DECLARE_UTILITYBASE();
int result = 0;
ENTER();
@ -53,7 +52,6 @@ __drop_iob_read_buffer(struct iob * file)
SHOWPOINTER(file);
assert( file != NULL );
assert( UtilityBase != NULL );
if(__check_abort_enabled)
__check_abort();
@ -75,20 +73,17 @@ __drop_iob_read_buffer(struct iob * file)
if(num_unread_bytes > 0)
{
struct file_hook_message message;
struct file_action_message fam;
SHOWMSG("calling the hook");
SHOWMSG("calling the action function");
message.action = file_hook_action_seek;
message.position = -num_unread_bytes;
message.mode = SEEK_CUR;
message.result = 0;
fam.fam_Action = file_action_seek;
fam.fam_Position = -num_unread_bytes;
fam.fam_Mode = SEEK_CUR;
assert( file->iob_Hook != NULL );
assert( file->iob_Action != NULL );
CallHookPkt(file->iob_Hook,file,&message);
if(message.result < 0)
if((*file->iob_Action)(file,&fam) < 0)
{
SHOWMSG("that didn't work");
@ -96,7 +91,7 @@ __drop_iob_read_buffer(struct iob * file)
result = -1;
__set_errno(message.error);
__set_errno(fam.fam_Error);
goto out;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_duplicate_fd.c,v 1.2 2005-01-02 09:07:08 obarthel Exp $
* $Id: stdio_duplicate_fd.c,v 1.3 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -40,25 +40,10 @@
void
__duplicate_fd(struct fd * duplicate_fd,struct fd * original_fd)
{
HOOKFUNC hook_function;
assert( duplicate_fd != NULL && original_fd != NULL );
/* Obtain the hook function associated with the file; note that
this is different depending upon which operating system
release is being used (compare "stdio_initializefd.c"). */
#if defined(__amigaos4__)
{
hook_function = original_fd->fd_Hook->h_Entry;
}
#else
{
hook_function = original_fd->fd_Hook->h_SubEntry;
}
#endif /* __amigaos4__ */
/* Initialize the duplicate to match the original. */
__initialize_fd(duplicate_fd,hook_function,original_fd->fd_DefaultFile,original_fd->fd_Flags);
__initialize_fd(duplicate_fd,original_fd->fd_Action,original_fd->fd_DefaultFile,original_fd->fd_Flags);
/* Figure out where the linked list of file descriptors associated
with this one starts. */

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fclose.c,v 1.3 2005-02-03 16:56:15 obarthel Exp $
* $Id: stdio_fclose.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -52,9 +52,8 @@
int
fclose(FILE *stream)
{
DECLARE_UTILITYBASE();
struct iob * file = (struct iob *)stream;
struct file_hook_message message;
struct file_action_message fam;
int result = OK;
ENTER();
@ -62,7 +61,6 @@ fclose(FILE *stream)
SHOWPOINTER(stream);
assert( stream != NULL );
assert( UtilityBase != NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
@ -100,20 +98,17 @@ fclose(FILE *stream)
result = EOF;
/* Make sure that the stream is closed. */
SHOWMSG("calling the hook");
SHOWMSG("calling the action function");
message.action = file_hook_action_close;
message.result = OK;
fam.fam_Action = file_action_close;
assert( file->iob_Hook != NULL );
assert( file->iob_Action != NULL );
CallHookPkt(file->iob_Hook,file,&message);
if(result != EOF)
if((*file->iob_Action)(file,&fam) < 0 && result != EOF)
{
result = message.result;
result = EOF;
__set_errno(message.error);
__set_errno(fam.fam_Error);
}
/* Now that the file is closed and we are in fact

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fdhookentry.c,v 1.11 2005-02-18 18:53:16 obarthel Exp $
* $Id: stdio_fdhookentry.c,v 1.12 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -52,26 +52,30 @@
/****************************************************************************/
void
int
__fd_hook_entry(
struct Hook * UNUSED unused_hook,
struct fd * fd,
struct file_hook_message * message)
struct fd * fd,
struct file_action_message * fam)
{
D_S(struct FileInfoBlock,fib);
BOOL fib_is_valid = FALSE;
LONG current_position;
LONG new_position;
LONG new_mode;
char * buffer = NULL;
int result = -1;
int error = OK;
ENTER();
assert( message != NULL && fd != NULL );
assert( fam != NULL && fd != NULL );
assert( __is_valid_fd(fd) );
switch(message->action)
switch(fam->fam_Action)
{
case file_hook_action_read:
case file_action_read:
SHOWMSG("file_hook_action_read");
SHOWMSG("file_action_read");
if(fd->fd_DefaultFile == ZERO)
{
@ -81,14 +85,14 @@ __fd_hook_entry(
break;
}
assert( message->data != NULL );
assert( message->size > 0 );
assert( fam->fam_Data != NULL );
assert( fam->fam_Size > 0 );
D(("read %ld bytes from position %ld to 0x%08lx",message->size,Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT),message->data));
D(("read %ld bytes from position %ld to 0x%08lx",fam->fam_Size,Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT),fam->fam_Data));
PROFILE_OFF();
result = Read(fd->fd_DefaultFile,message->data,message->size);
result = Read(fd->fd_DefaultFile,fam->fam_Data,fam->fam_Size);
PROFILE_ON();
@ -105,9 +109,9 @@ __fd_hook_entry(
break;
case file_hook_action_write:
case file_action_write:
SHOWMSG("file_hook_action_write");
SHOWMSG("file_action_write");
if(fd->fd_DefaultFile == ZERO)
{
@ -117,8 +121,8 @@ __fd_hook_entry(
break;
}
assert( message->data != NULL );
assert( message->size > 0 );
assert( fam->fam_Data != NULL );
assert( fam->fam_Size > 0 );
if(FLAG_IS_SET(fd->fd_Flags,FDF_APPEND))
{
@ -135,11 +139,11 @@ __fd_hook_entry(
PROFILE_ON();
}
D(("write %ld bytes to position %ld from 0x%08lx",message->size,Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT),message->data));
D(("write %ld bytes to position %ld from 0x%08lx",fam->fam_Size,Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT),fam->fam_Data));
PROFILE_OFF();
result = Write(fd->fd_DefaultFile,message->data,message->size);
result = Write(fd->fd_DefaultFile,fam->fam_Data,fam->fam_Size);
PROFILE_ON();
@ -156,179 +160,307 @@ __fd_hook_entry(
break;
case file_hook_action_close:
case file_action_close:
SHOWMSG("file_hook_action_close");
SHOWMSG("file_action_close");
if(fd->fd_DefaultFile != ZERO)
/* If this is an alias, just remove it. */
if(__fd_is_aliased(fd))
{
BOOL name_and_path_valid = FALSE;
D_S(struct FileInfoBlock,fib);
BPTR parent_dir;
memset(fib,0,sizeof(*fib));
/* Call a cleanup function, such as the one which
* releases locked records.
*/
if(fd->fd_Cleanup != NULL)
(*fd->fd_Cleanup)(fd);
PROFILE_OFF();
parent_dir = __safe_parent_of_file_handle(fd->fd_DefaultFile);
if(parent_dir != ZERO)
__remove_fd_alias(fd);
}
else
{
/* Is this file open in the first place? */
if(fd->fd_DefaultFile == ZERO)
{
if(__safe_examine_file_handle(fd->fd_DefaultFile,fib))
name_and_path_valid = TRUE;
SHOWMSG("file is closed");
error = EBADF;
break;
}
if(CANNOT Close(fd->fd_DefaultFile))
error = __translate_io_error_to_errno(IoErr());
PROFILE_ON();
fd->fd_DefaultFile = ZERO;
#if defined(UNIX_PATH_SEMANTICS)
/* Are we disallowed to close this file? */
if(FLAG_IS_SET(fd->fd_Flags,FDF_NO_CLOSE))
{
DECLARE_UTILITYBASE();
/* OK, so we cannot close it. But we might be obliged to
reset a console into buffered mode. */
if(FLAG_IS_SET(fd->fd_Flags,FDF_NON_BLOCKING) && FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE))
SetMode(fd->fd_DefaultFile,DOSFALSE);
}
else
{
BOOL name_and_path_valid = FALSE;
D_S(struct FileInfoBlock,fib);
BPTR parent_dir;
assert( UtilityBase != NULL );
memset(fib,0,sizeof(*fib));
/* Now that we have closed this file, know where it is and what its
* name would be, check if we tried to unlink it earlier. If we did,
* we'll try to finish the job here and now.
/* Call a cleanup function, such as the one which
* releases locked records.
*/
if(name_and_path_valid)
if(fd->fd_Cleanup != NULL)
(*fd->fd_Cleanup)(fd);
PROFILE_OFF();
parent_dir = __safe_parent_of_file_handle(fd->fd_DefaultFile);
if(parent_dir != ZERO)
{
struct UnlinkNode * node;
struct UnlinkNode * uln_next;
struct UnlinkNode * uln;
BOOL file_deleted = FALSE;
if(__safe_examine_file_handle(fd->fd_DefaultFile,fib))
name_and_path_valid = TRUE;
}
assert( __unlink_list.mlh_Head != NULL );
if(CANNOT Close(fd->fd_DefaultFile))
error = __translate_io_error_to_errno(IoErr());
/* Check all files to be unlinked when this program exits. */
for(uln = (struct UnlinkNode *)__unlink_list.mlh_Head ;
(uln_next = (struct UnlinkNode *)uln->uln_MinNode.mln_Succ) != NULL ;
uln = uln_next)
PROFILE_ON();
fd->fd_DefaultFile = ZERO;
#if defined(UNIX_PATH_SEMANTICS)
{
DECLARE_UTILITYBASE();
assert( UtilityBase != NULL );
/* Now that we have closed this file, know where it is and what its
* name would be, check if we tried to unlink it earlier. If we did,
* we'll try to finish the job here and now.
*/
if(name_and_path_valid)
{
node = NULL;
struct UnlinkNode * node;
struct UnlinkNode * uln_next;
struct UnlinkNode * uln;
BOOL file_deleted = FALSE;
/* If the file name matches, check if the path matches, too. */
if(Stricmp(FilePart(uln->uln_Name),fib->fib_FileName) == SAME)
assert( __unlink_list.mlh_Head != NULL );
/* Check all files to be unlinked when this program exits. */
for(uln = (struct UnlinkNode *)__unlink_list.mlh_Head ;
(uln_next = (struct UnlinkNode *)uln->uln_MinNode.mln_Succ) != NULL ;
uln = uln_next)
{
BPTR old_dir;
BPTR node_lock;
BPTR path_lock = ZERO;
node = NULL;
PROFILE_OFF();
/* Try to get a lock on the file first, then move on to
* the directory it is stored in.
*/
old_dir = CurrentDir(uln->uln_Lock);
node_lock = Lock(uln->uln_Name,SHARED_LOCK);
if(node_lock != ZERO)
{
path_lock = ParentDir(node_lock);
UnLock(node_lock);
}
CurrentDir(old_dir);
/* If we found the file's parent directory, check if it matches
* the parent directory of the file we just closed.
*/
if(path_lock != ZERO)
{
if(SameLock(path_lock,parent_dir) == LOCK_SAME)
node = uln;
UnLock(path_lock);
}
PROFILE_ON();
}
/* If we found that this file was set up for deletion,
* delete it here and now.
*/
if(node != NULL)
{
if(NOT file_deleted)
/* If the file name matches, check if the path matches, too. */
if(Stricmp(FilePart(uln->uln_Name),fib->fib_FileName) == SAME)
{
BPTR old_dir;
BPTR node_lock;
BPTR path_lock = ZERO;
PROFILE_OFF();
old_dir = CurrentDir(parent_dir);
/* Try to get a lock on the file first, then move on to
* the directory it is stored in.
*/
old_dir = CurrentDir(uln->uln_Lock);
if(DeleteFile(fib->fib_FileName))
node_lock = Lock(uln->uln_Name,SHARED_LOCK);
if(node_lock != ZERO)
{
file_deleted = TRUE;
name_and_path_valid = FALSE;
path_lock = ParentDir(node_lock);
UnLock(node_lock);
}
CurrentDir(old_dir);
/* If we found the file's parent directory, check if it matches
* the parent directory of the file we just closed.
*/
if(path_lock != ZERO)
{
if(SameLock(path_lock,parent_dir) == LOCK_SAME)
node = uln;
UnLock(path_lock);
}
PROFILE_ON();
}
if(file_deleted)
/* If we found that this file was set up for deletion,
* delete it here and now.
*/
if(node != NULL)
{
Remove((struct Node *)node);
free(node);
if(NOT file_deleted)
{
BPTR old_dir;
PROFILE_OFF();
old_dir = CurrentDir(parent_dir);
if(DeleteFile(fib->fib_FileName))
{
file_deleted = TRUE;
name_and_path_valid = FALSE;
}
CurrentDir(old_dir);
PROFILE_ON();
}
if(file_deleted)
{
Remove((struct Node *)node);
free(node);
}
}
}
}
}
}
#endif /* UNIX_PATH_SEMANTICS */
#endif /* UNIX_PATH_SEMANTICS */
if(FLAG_IS_SET(fd->fd_Flags,FDF_CREATED) && name_and_path_valid)
{
ULONG flags;
BPTR old_dir;
if(FLAG_IS_SET(fd->fd_Flags,FDF_CREATED) && name_and_path_valid)
{
ULONG flags;
BPTR old_dir;
PROFILE_OFF();
old_dir = CurrentDir(parent_dir);
flags = fib->fib_Protection ^ (FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE);
CLEAR_FLAG(flags,FIBF_EXECUTE);
CLEAR_FLAG(flags,FIBF_OTR_EXECUTE);
CLEAR_FLAG(flags,FIBF_GRP_EXECUTE);
SetProtection(fib->fib_FileName,(LONG)(flags ^ (FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE)));
CurrentDir(old_dir);
PROFILE_ON();
}
PROFILE_OFF();
old_dir = CurrentDir(parent_dir);
flags = fib->fib_Protection ^ (FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE);
CLEAR_FLAG(flags,FIBF_EXECUTE);
CLEAR_FLAG(flags,FIBF_OTR_EXECUTE);
CLEAR_FLAG(flags,FIBF_GRP_EXECUTE);
SetProtection(fib->fib_FileName,(LONG)(flags ^ (FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE)));
CurrentDir(old_dir);
UnLock(parent_dir);
PROFILE_ON();
}
}
PROFILE_OFF();
UnLock(parent_dir);
PROFILE_ON();
/* And that's the last for this file descriptor. */
memset(fd,0,sizeof(*fd));
if(error == OK)
result = 0;
}
else
{
SHOWMSG("file is closed");
error = EBADF;
}
break;
case file_hook_action_set_blocking:
case file_action_seek:
SHOWMSG("file_hook_action_set_blocking");
SHOWMSG("file_action_seek");
if(fam->fam_Mode == SEEK_CUR)
new_mode = OFFSET_CURRENT;
else if (fam->fam_Mode == SEEK_SET)
new_mode = OFFSET_BEGINNING;
else
new_mode = OFFSET_END;
D(("seek to offset %ld, new_mode %ld; current position = %ld",fam->fam_Position,new_mode,Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT)));
if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION))
{
current_position = fd->fd_Position;
}
else
{
PROFILE_OFF();
current_position = Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT);
PROFILE_ON();
if(current_position < 0)
{
error = EBADF;
break;
}
}
new_position = current_position;
switch(new_mode)
{
case OFFSET_CURRENT:
new_position += fam->fam_Position;
break;
case OFFSET_BEGINNING:
new_position = fam->fam_Position;
break;
case OFFSET_END:
if(__safe_examine_file_handle(fd->fd_DefaultFile,fib))
{
new_position = fib->fib_Size + fam->fam_Position;
fib_is_valid = TRUE;
}
break;
}
if(new_position != current_position)
{
LONG position;
PROFILE_OFF();
position = Seek(fd->fd_DefaultFile,fam->fam_Position,new_mode);
PROFILE_ON();
if(position < 0)
{
D(("seek failed, fam->fam_Mode=%ld (%ld), offset=%ld, ioerr=%ld",new_mode,fam->fam_Mode,fam->fam_Position,IoErr()));
error = __translate_io_error_to_errno(IoErr());
#if defined(UNIX_PATH_SEMANTICS)
{
if(NOT fib_is_valid && CANNOT __safe_examine_file_handle(fd->fd_DefaultFile,fib))
{
error = __translate_io_error_to_errno(IoErr());
break;
}
if(new_position <= fib->fib_Size)
{
error = __translate_io_error_to_errno(IoErr());
break;
}
if(__grow_file_size(fd,new_position - fib->fib_Size) != OK)
{
error = __translate_io_error_to_errno(IoErr());
break;
}
}
#else
{
break;
}
#endif /* UNIX_PATH_SEMANTICS */
}
}
if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION))
fd->fd_Position = new_position;
result = new_position;
break;
case file_action_set_blocking:
SHOWMSG("file_action_set_blocking");
PROFILE_OFF();
@ -338,14 +470,14 @@ __fd_hook_entry(
SHOWMSG("changing the mode");
if(message->arg != 0)
if(fam->fam_Arg != 0)
mode = DOSFALSE; /* buffered mode */
else
mode = DOSTRUE; /* single character mode */
if(CANNOT SetMode(fd->fd_DefaultFile,mode))
{
error = EBADF;
error = __translate_io_error_to_errno(IoErr());
break;
}
@ -362,15 +494,15 @@ __fd_hook_entry(
break;
case file_hook_action_examine:
case file_action_examine:
SHOWMSG("file_hook_action_examine");
SHOWMSG("file_action_examine");
if(fd->fd_DefaultFile != ZERO)
{
struct FileHandle * fh;
if(CANNOT __safe_examine_file_handle(fd->fd_DefaultFile,message->file_info))
if(CANNOT __safe_examine_file_handle(fd->fd_DefaultFile,fam->fam_FileInfo))
{
SHOWMSG("couldn't examine the file");
@ -380,7 +512,7 @@ __fd_hook_entry(
fh = BADDR(fd->fd_DefaultFile);
message->file_system = fh->fh_Type;
fam->fam_FileSystem = fh->fh_Type;
result = 0;
}
@ -395,7 +527,7 @@ __fd_hook_entry(
default:
SHOWVALUE(message->action);
SHOWVALUE(fam->fam_Action);
error = EBADF;
break;
@ -406,8 +538,8 @@ __fd_hook_entry(
SHOWVALUE(result);
message->result = result;
message->error = error;
fam->fam_Error = error;
LEAVE();
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_filliobreadbuffer.c,v 1.4 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_filliobreadbuffer.c,v 1.5 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -40,8 +40,8 @@
int
__fill_iob_read_buffer(struct iob * file)
{
DECLARE_UTILITYBASE();
struct file_hook_message message;
struct file_action_message fam;
int num_bytes_read;
int result = -1;
ENTER();
@ -52,7 +52,6 @@ __fill_iob_read_buffer(struct iob * file)
assert( file != NULL && (file->iob_BufferReadBytes == 0 || file->iob_BufferPosition == file->iob_BufferReadBytes) && file->iob_BufferWriteBytes == 0 );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_READ) );
assert( file->iob_BufferSize > 0 );
assert( UtilityBase != NULL );
if(__check_abort_enabled)
__check_abort();
@ -81,26 +80,24 @@ __fill_iob_read_buffer(struct iob * file)
SHOWPOINTER(file->iob_Buffer);
SHOWVALUE(file->iob_BufferSize);
message.action = file_hook_action_read;
message.data = file->iob_Buffer;
message.size = file->iob_BufferSize;
message.result = 0;
fam.fam_Action = file_action_read;
fam.fam_Data = file->iob_Buffer;
fam.fam_Size = file->iob_BufferSize;
assert( file->iob_Hook != NULL );
assert( file->iob_Action != NULL );
CallHookPkt(file->iob_Hook,file,&message);
if(message.result < 0)
num_bytes_read = (*file->iob_Action)(file,&fam);
if(num_bytes_read < 0)
{
__set_errno(message.error);
__set_errno(fam.fam_Error);
D(("got error %ld",message.error));
D(("got error %ld",fam.fam_Error));
SET_FLAG(file->iob_Flags,IOBF_ERROR);
goto out;
}
file->iob_BufferReadBytes = message.result;
file->iob_BufferReadBytes = num_bytes_read;
file->iob_BufferPosition = 0;
SHOWVALUE(file->iob_BufferReadBytes);

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_flushiobwritebuffer.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_flushiobwritebuffer.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -42,26 +42,9 @@
/****************************************************************************/
/*
int
__iob_write_buffer_is_full(struct iob * file)
{
int result;
assert( file != NULL );
result = (file->iob_BufferSize > 0 && (ULONG)file->iob_BufferWriteBytes == file->iob_BufferSize);
return(result);
}
*/
/****************************************************************************/
int
__flush_iob_write_buffer(struct iob * file)
{
DECLARE_UTILITYBASE();
int result = 0;
ENTER();
@ -69,7 +52,6 @@ __flush_iob_write_buffer(struct iob * file)
SHOWPOINTER(file);
assert( file != NULL );
assert( UtilityBase != NULL );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
assert( file->iob_BufferSize > 0 );
@ -78,7 +60,7 @@ __flush_iob_write_buffer(struct iob * file)
if(FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) && file->iob_BufferWriteBytes > 0)
{
struct file_hook_message message;
struct file_action_message fam;
assert( FLAG_IS_SET(file->iob_Flags,IOBF_WRITE) );
assert( file->iob_BufferSize > 0 );
@ -87,22 +69,19 @@ __flush_iob_write_buffer(struct iob * file)
SHOWMSG("calling the hook");
message.action = file_hook_action_write;
message.data = file->iob_Buffer;
message.size = file->iob_BufferWriteBytes;
message.result = 0;
fam.fam_Action = file_action_write;
fam.fam_Data = file->iob_Buffer;
fam.fam_Size = file->iob_BufferWriteBytes;
assert( file->iob_Hook != NULL );
assert( file->iob_Action != NULL );
CallHookPkt(file->iob_Hook,file,&message);
if(message.result != file->iob_BufferWriteBytes)
if((*file->iob_Action)(file,&fam) != file->iob_BufferWriteBytes)
{
SHOWMSG("that didn't work");
SET_FLAG(file->iob_Flags,IOBF_ERROR);
__set_errno(message.error);
__set_errno(fam.fam_Error);
result = -1;
goto out;

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fseek.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_fseek.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -46,7 +46,6 @@
int
fseek(FILE *stream, long int offset, int wherefrom)
{
DECLARE_UTILITYBASE();
struct iob * file = (struct iob *)stream;
int result = -1;
@ -57,7 +56,6 @@ fseek(FILE *stream, long int offset, int wherefrom)
SHOWVALUE(wherefrom);
assert(stream != NULL);
assert( UtilityBase != NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
@ -140,7 +138,7 @@ fseek(FILE *stream, long int offset, int wherefrom)
if(NOT buffer_position_adjusted)
{
struct file_hook_message message;
struct file_action_message fam;
/* Oh dear, no luck. So we have to get rid of the
* current buffer contents and start with a clean
@ -162,23 +160,20 @@ fseek(FILE *stream, long int offset, int wherefrom)
SHOWMSG("calling the hook");
SHOWPOINTER(&message);
SHOWPOINTER(&fam);
message.action = file_hook_action_seek;
message.position = offset;
message.mode = wherefrom;
message.result = 0;
fam.fam_Action = file_action_seek;
fam.fam_Position = offset;
fam.fam_Mode = wherefrom;
SHOWVALUE(message.position);
SHOWVALUE(message.mode);
SHOWVALUE(fam.fam_Position);
SHOWVALUE(fam.fam_Mode);
assert( file->iob_Hook != NULL );
assert( file->iob_Action != NULL );
CallHookPkt(file->iob_Hook,file,&message);
if(message.result < 0)
if((*file->iob_Action)(file,&fam) < 0)
{
__set_errno(message.error);
__set_errno(fam.fam_Error);
SET_FLAG(file->iob_Flags,IOBF_ERROR);
goto out;

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_ftell.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_ftell.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -46,13 +46,11 @@
long int
ftell(FILE *stream)
{
DECLARE_UTILITYBASE();
struct iob * file = (struct iob *)stream;
struct file_hook_message message;
struct file_action_message fam;
long result = -1;
assert( stream != NULL );
assert( UtilityBase != NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
@ -83,24 +81,20 @@ ftell(FILE *stream)
SHOWMSG("calling the hook");
SHOWPOINTER(&message);
SHOWPOINTER(&fam);
message.action = file_hook_action_seek;
message.position = 0;
message.mode = SEEK_CUR;
message.result = 0;
fam.fam_Action = file_action_seek;
fam.fam_Position = 0;
fam.fam_Mode = SEEK_CUR;
SHOWVALUE(message.position);
SHOWVALUE(message.mode);
SHOWVALUE(fam.fam_Position);
SHOWVALUE(fam.fam_Mode);
assert( file->iob_Hook != NULL );
assert( file->iob_Action != NULL );
CallHookPkt(file->iob_Hook,file,&message);
result = message.result;
if(result < 0)
if((*file->iob_Action)(file,&fam) < 0)
{
__set_errno(message.error);
__set_errno(fam.fam_Error);
SET_FLAG(file->iob_Flags,IOBF_ERROR);

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_headers.h,v 1.13 2005-02-18 18:53:16 obarthel Exp $
* $Id: stdio_headers.h,v 1.14 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -104,6 +104,13 @@
/****************************************************************************/
/* Forward declarations for below... */
struct fd;
struct iob;
struct file_action_message;
/****************************************************************************/
/* CPU cache line size; used for alignment purposes with some data structures.
This should be determined dynamically rather than preset here. For the
68040/68060 the cache line size is 16 bytes, for the PowerPC G4 it's
@ -121,6 +128,47 @@
/****************************************************************************/
/* Operations that can be performed by the file action function. */
enum file_action_t
{
file_action_read,
file_action_write,
file_action_seek,
file_action_close,
file_action_set_blocking,
file_action_set_async,
file_action_examine
};
/****************************************************************************/
/* A message sent to a file action function. */
struct file_action_message
{
enum file_action_t fam_Action; /* What to do */
char * fam_Data; /* Where to read/write the data */
long fam_Size; /* How much data to write */
long fam_Position; /* The seek position */
long fam_Mode; /* The seek mode */
int fam_Arg; /* Whether or not this file should
be set non-blocking or use
asynchronous I/O */
struct FileInfoBlock * fam_FileInfo;
struct MsgPort * fam_FileSystem;
int fam_Error; /* Error code, if any... */
};
/****************************************************************************/
/* The file action function for buffered files. */
typedef int (*file_action_iob_t)(struct iob * iob,struct file_action_message * fam);
/****************************************************************************/
/* The three file buffering modes supported. */
#define IOBF_BUFFER_MODE_FULL _IOFBF /* Buffer is flushed when it fills up */
#define IOBF_BUFFER_MODE_LINE _IOLBF /* Buffer is flushed when it fills up
@ -162,60 +210,58 @@
things will take a turn for the worse! */
struct iob
{
ULONG iob_Flags; /* Properties and options
associated with this file */
ULONG iob_Flags; /* Properties and options
associated with this file */
UBYTE * iob_Buffer; /* Points to the file buffer */
LONG iob_BufferSize; /* Size of the buffer in bytes */
LONG iob_BufferPosition; /* Current read position
in the buffer (grows when any
data is read from the buffer) */
LONG iob_BufferReadBytes; /* Number of bytes available for
reading (shrinks when any data
is read from the buffer) */
LONG iob_BufferWriteBytes; /* Number of bytes written to the
buffer which still need to be
flushed to disk (grows when any
data is written to the buffer) */
UBYTE * iob_Buffer; /* Points to the file buffer */
LONG iob_BufferSize; /* Size of the buffer in bytes */
LONG iob_BufferPosition; /* Current read position
in the buffer (grows when any
data is read from the buffer) */
LONG iob_BufferReadBytes; /* Number of bytes available for
reading (shrinks when any data
is read from the buffer) */
LONG iob_BufferWriteBytes; /* Number of bytes written to the
buffer which still need to be
flushed to disk (grows when any
data is written to the buffer) */
/************************************************************************/
/* Public portion ends here */
/************************************************************************/
struct Hook * iob_Hook; /* The hook to invoke for file
operations, such as read,
write and seek. */
file_action_iob_t iob_Action; /* The function to invoke for file
operations, such as read,
write and seek. */
int iob_SlotNumber; /* Points back to the iob table
entry number. */
int iob_SlotNumber; /* Points back to the iob table
entry number. */
int iob_Descriptor; /* Associated file descriptor */
int iob_Descriptor; /* Associated file descriptor */
STRPTR iob_String; /* Alternative source of data;
a pointer to a string */
LONG iob_StringSize; /* Number of bytes that may be
stored in the string */
LONG iob_StringPosition; /* Current read/write position
in the string */
LONG iob_StringLength; /* Number of characters stored
in the string */
STRPTR iob_String; /* Alternative source of data;
a pointer to a string */
LONG iob_StringSize; /* Number of bytes that may be
stored in the string */
LONG iob_StringPosition; /* Current read/write position
in the string */
LONG iob_StringLength; /* Number of characters stored
in the string */
char * iob_File; /* For access tracking with the
memory allocator. */
int iob_Line;
char * iob_File; /* For access tracking with the
memory allocator. */
int iob_Line;
struct Hook iob_DefaultHook; /* Static hook */
APTR iob_CustomBuffer; /* A custom buffer allocated
by setvbuf() */
APTR iob_CustomBuffer; /* A custom buffer allocated
by setvbuf() */
char * iob_TempFileName; /* If this is a temporary
file, this is its name */
BPTR iob_TempFileLock; /* The directory in which this
temporary file is stored */
char * iob_TempFileName; /* If this is a temporary
file, this is its name */
BPTR iob_TempFileLock; /* The directory in which this
temporary file is stored */
UBYTE iob_SingleByte; /* Fall-back buffer for 'unbuffered'
files */
UBYTE iob_SingleByte; /* Fall-back buffer for 'unbuffered'
files */
};
/****************************************************************************/
@ -271,29 +317,28 @@ struct iob
/****************************************************************************/
/* Forward declaration... */
struct fd;
/* The file action function for unbuffered files. */
typedef int (*file_action_fd_t)(struct fd * fd,struct file_action_message * fam);
/****************************************************************************/
/* Function to be called before a file descriptor is "closed". */
typedef void (*fd_cleanup_t)(struct fd * fd);
/****************************************************************************/
struct fd
{
struct Hook * fd_Hook; /* Hook to invoke to perform actions */
ULONG fd_Flags; /* File properties */
struct fd * fd_Original; /* NULL if this is not a dup()ed file
descriptor; points to original
descriptor if non-NULL */
struct fd * fd_NextLink; /* Points to next duplicate of this
file descriptor; NULL for none */
struct Hook fd_DefaultHook; /* Static hook */
BPTR fd_DefaultFile; /* A dos.library file handle */
LONG fd_Position; /* Cached file position (seek offset). */
fd_cleanup_t fd_Cleanup; /* Cleanup function, if any. */
file_action_fd_t fd_Action; /* Function to invoke to perform actions */
ULONG fd_Flags; /* File properties */
struct fd * fd_Original; /* NULL if this is not a dup()ed file
descriptor; points to original
descriptor if non-NULL */
struct fd * fd_NextLink; /* Points to next duplicate of this
file descriptor; NULL for none */
BPTR fd_DefaultFile; /* A dos.library file handle */
LONG fd_Position; /* Cached file position (seek offset). */
fd_cleanup_t fd_Cleanup; /* Cleanup function, if any. */
};
/****************************************************************************/
@ -317,44 +362,6 @@ struct bcpl_name
/****************************************************************************/
/* Actions that can be performed by the file handle hook. */
enum file_hook_action_t
{
file_hook_action_read,
file_hook_action_write,
file_hook_action_seek,
file_hook_action_close,
file_hook_action_set_blocking,
file_hook_action_set_async,
file_hook_action_examine
};
/****************************************************************************/
/* A message sent to a file handle hook. */
struct file_hook_message
{
enum file_hook_action_t action; /* What to do */
char * data; /* Where to read/write the data */
long size; /* How much data to write */
long position; /* The seek position */
long mode; /* The seek mode */
int arg; /* Whether or not this file should
be set non-blocking or use
asynchronous I/O */
struct FileInfoBlock * file_info;
struct MsgPort * file_system;
int error; /* Error code, if any... */
long result; /* Whatever this produced */
};
/****************************************************************************/
/* The file handle table. */
extern struct iob ** NOCOMMON __iob;
extern int NOCOMMON __num_iob;
@ -414,6 +421,11 @@ extern BOOL NOCOMMON __no_standard_io;
/****************************************************************************/
#define __fd_is_aliased(fd) \
((fd)->fd_Original != NULL || (fd)->fd_NextLink != NULL)
/****************************************************************************/
#ifndef _STDIO_PROTOS_H
#include "stdio_protos.h"
#endif /* _STDIO_PROTOS_H */

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_init_exit.c,v 1.16 2005-02-04 08:49:10 obarthel Exp $
* $Id: stdio_init_exit.c,v 1.17 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -201,9 +201,9 @@ __stdio_init(void)
/* Align the buffer start address to a cache line boundary. */
aligned_buffer = (char *)((ULONG)(buffer + (CACHE_LINE_SIZE-1)) & ~(CACHE_LINE_SIZE-1));
__initialize_fd(__fd[i],(HOOKFUNC)__fd_hook_entry,default_file,fd_flags);
__initialize_fd(__fd[i],__fd_hook_entry,default_file,fd_flags);
__initialize_iob(__iob[i],(HOOKFUNC)__iob_hook_entry,
__initialize_iob(__iob[i],__iob_hook_entry,
buffer,
aligned_buffer,BUFSIZ,
i,

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_initializefd.c,v 1.2 2005-01-02 09:07:08 obarthel Exp $
* $Id: stdio_initializefd.c,v 1.3 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -39,27 +39,16 @@
void
__initialize_fd(
struct fd * fd,
HOOKFUNC hook_function,
BPTR default_file,
ULONG flags)
struct fd * fd,
file_action_fd_t action_function,
BPTR default_file,
ULONG flags)
{
assert( fd != NULL && hook_function != NULL );
assert( fd != NULL && action_function != NULL );
memset(fd,0,sizeof(*fd));
fd->fd_DefaultFile = default_file;
fd->fd_Flags = flags;
fd->fd_Hook = &fd->fd_DefaultHook;
#if defined(__amigaos4__)
{
fd->fd_Hook->h_Entry = (HOOKFUNC)hook_function;
}
#else
{
fd->fd_Hook->h_Entry = (HOOKFUNC)HookEntry;
fd->fd_Hook->h_SubEntry = (HOOKFUNC)hook_function;
}
#endif /* __amigaos4__ */
fd->fd_Action = action_function;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_initializeiob.c,v 1.2 2005-01-02 09:07:08 obarthel Exp $
* $Id: stdio_initializeiob.c,v 1.3 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -39,16 +39,16 @@
void
__initialize_iob(
struct iob * iob,
HOOKFUNC hook_function,
STRPTR custom_buffer,
STRPTR buffer,
int buffer_size,
int file_descriptor,
int slot_number,
ULONG flags)
struct iob * iob,
file_action_iob_t action_function,
STRPTR custom_buffer,
STRPTR buffer,
int buffer_size,
int file_descriptor,
int slot_number,
ULONG flags)
{
assert( iob != NULL && hook_function != NULL );
assert( iob != NULL && action_function != NULL );
memset(iob,0,sizeof(*iob));
@ -58,16 +58,5 @@ __initialize_iob(
iob->iob_Descriptor = file_descriptor;
iob->iob_SlotNumber = slot_number;
iob->iob_Flags = flags;
iob->iob_Hook = &iob->iob_DefaultHook;
#if defined(__amigaos4__)
{
iob->iob_Hook->h_Entry = (HOOKFUNC)hook_function;
}
#else
{
iob->iob_Hook->h_Entry = (HOOKFUNC)HookEntry;
iob->iob_Hook->h_SubEntry = (HOOKFUNC)hook_function;
}
#endif /* __amigaos4__ */
iob->iob_Action = action_function;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_iobhookentry.c,v 1.2 2005-01-02 09:07:08 obarthel Exp $
* $Id: stdio_iobhookentry.c,v 1.3 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -37,86 +37,51 @@
/****************************************************************************/
void
int
__iob_hook_entry(
struct Hook * UNUSED unused_hook,
struct iob * file_iob,
struct file_hook_message * message)
struct iob * file_iob,
struct file_action_message * fam)
{
struct fd * fd;
int result;
int error;
assert( message != NULL && file_iob != NULL );
assert( fam != NULL && file_iob != NULL );
switch(message->action)
switch(fam->fam_Action)
{
case file_hook_action_read:
case file_action_read:
case file_action_write:
case file_action_seek:
case file_action_close:
SHOWMSG("file_hook_action_read");
assert( file_iob->iob_Descriptor >= 0 && file_iob->iob_Descriptor < __num_fd );
assert( __fd[file_iob->iob_Descriptor] != NULL );
assert( FLAG_IS_SET(__fd[file_iob->iob_Descriptor]->fd_Flags,FDF_IN_USE) );
SHOWVALUE(file_iob->iob_Descriptor);
SHOWPOINTER(message->data);
SHOWVALUE(message->size);
fd = __get_file_descriptor(file_iob->iob_Descriptor);
if(fd == NULL)
{
fam->fam_Error = EBADF;
break;
}
assert( message->data != NULL );
assert( message->size > 0 );
assert( FLAG_IS_SET(file_iob->iob_Flags,IOBF_IN_USE) );
assert( fd->fd_Action != NULL );
result = __read(file_iob->iob_Descriptor,message->data,(size_t)message->size,&error);
break;
result = (*fd->fd_Action)(fd,fam);
case file_hook_action_write:
SHOWMSG("file_hook_action_write");
SHOWVALUE(file_iob->iob_Descriptor);
SHOWPOINTER(message->data);
SHOWVALUE(message->size);
assert( message->data != NULL );
assert( message->size > 0 );
assert( FLAG_IS_SET(file_iob->iob_Flags,IOBF_IN_USE) );
result = __write(file_iob->iob_Descriptor,message->data,(size_t)message->size,&error);
break;
case file_hook_action_seek:
SHOWMSG("file_hook_action_seek");
SHOWVALUE(file_iob->iob_Descriptor);
SHOWVALUE(message->position);
SHOWVALUE(message->mode);
assert( FLAG_IS_SET(file_iob->iob_Flags,IOBF_IN_USE) );
result = __lseek(file_iob->iob_Descriptor,message->position,message->mode,&error);
break;
case file_hook_action_close:
SHOWMSG("file_hook_action_close");
SHOWVALUE(file_iob->iob_Descriptor);
assert( FLAG_IS_SET(file_iob->iob_Flags,IOBF_IN_USE) );
result = __close(file_iob->iob_Descriptor,&error);
break;
default:
SHOWVALUE(message->action);
SHOWVALUE(fam->fam_Action);
result = -1;
error = EBADF;
fam->fam_Error = EBADF;
result = -1;
break;
}
SHOWVALUE(result);
message->result = result;
message->error = error;
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_openiob.c,v 1.6 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_openiob.c,v 1.7 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -171,7 +171,7 @@ __open_iob(const char *filename, const char *mode, int file_descriptor, int slot
if(FLAG_IS_SET(open_mode,O_WRONLY) || FLAG_IS_SET(open_mode,O_RDWR))
SET_FLAG(file_flags,IOBF_WRITE);
__initialize_iob(file,(HOOKFUNC)__iob_hook_entry,
__initialize_iob(file,__iob_hook_entry,
buffer,
aligned_buffer,BUFSIZ,
file_descriptor,

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_protos.h,v 1.6 2005-02-18 18:53:16 obarthel Exp $
* $Id: stdio_protos.h,v 1.7 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -57,7 +57,7 @@
#ifndef _STDIO_HEADERS_H
/* Forward declarations */
struct file_hook_message;
struct file_action_message;
struct iob;
struct fd;
@ -82,17 +82,17 @@ extern struct fd * __get_file_descriptor(int file_descriptor);
/****************************************************************************/
/* stdio_iobhookentry.c */
extern void __iob_hook_entry(struct Hook * hook,struct iob * iob,struct file_hook_message * message);
extern int __iob_hook_entry(struct iob * iob,struct file_action_message * fam);
/****************************************************************************/
/* stdio_fdhookentry.c */
extern void __fd_hook_entry(struct Hook * hook,struct fd * fd,struct file_hook_message * message);
extern int __fd_hook_entry(struct fd * fd,struct file_action_message * fam);
/****************************************************************************/
/* stdio_initializefd.c */
extern void __initialize_fd(struct fd * fd,HOOKFUNC hook_function,BPTR default_file,ULONG flags);
extern void __initialize_fd(struct fd * fd,file_action_fd_t action_function,BPTR default_file,ULONG flags);
/****************************************************************************/
@ -103,7 +103,7 @@ extern int __find_vacant_fd_entry(void);
/****************************************************************************/
/* stdio_initializeiob.c */
extern void __initialize_iob(struct iob * iob,HOOKFUNC hook_function,STRPTR custom_buffer,STRPTR buffer,int buffer_size,int file_descriptor,int slot_number,ULONG flags);
extern void __initialize_iob(struct iob * iob,file_action_iob_t action_function,STRPTR custom_buffer,STRPTR buffer,int buffer_size,int file_descriptor,int slot_number,ULONG flags);
/****************************************************************************/
@ -148,21 +148,6 @@ extern int __vfscanf(FILE *stream, const char *format, va_list arg);
/****************************************************************************/
/* fcntl_write.c */
extern ssize_t __write(int file_descriptor, const void * buffer, size_t num_bytes, int * error_ptr);
/****************************************************************************/
/* fcntl_lseek.c */
extern off_t __lseek(int file_descriptor, off_t offset, int mode, int * error_ptr);
/****************************************************************************/
/* fcntl_close.c */
extern int __close(int file_descriptor,int * error_ptr);
/****************************************************************************/
/* stdio_fgetc.c */
extern int __fgetc_check(FILE * stream);
extern int __fgetc(FILE *stream);
@ -176,27 +161,22 @@ extern int __fputc(int c,FILE *stream,int buffer_mode);
/****************************************************************************/
/* stdio_sscanf_hook_entry.c */
extern void __sscanf_hook_entry(struct Hook *UNUSED unused_hook,struct iob *string,struct file_hook_message *message);
extern int __sscanf_hook_entry(struct iob *string,struct file_action_message *fam);
/****************************************************************************/
/* stdio_vasprintf_hook_entry.c */
extern void __vasprintf_hook_entry(struct Hook *UNUSED unused_hook,struct iob *string,struct file_hook_message *message);
extern int __vasprintf_hook_entry(struct iob *string,struct file_action_message *fam);
/****************************************************************************/
/* stdio_vsprintf_hook_entry.c */
extern void __vsprintf_hook_entry(struct Hook *UNUSED unused_hook,struct iob *string,struct file_hook_message *message);
extern int __vsprintf_hook_entry(struct iob *string,struct file_action_message *fam);
/****************************************************************************/
/* stdio_vsnprintf_hook_entry.c */
extern void __vsnprintf_hook_entry(struct Hook *UNUSED unused_hook,struct iob *string,struct file_hook_message *message);
/****************************************************************************/
/* fcntl_read.c */
extern ssize_t __read(int file_descriptor, void * buffer, size_t num_bytes, int * error_ptr);
extern int __vsnprintf_hook_entry(struct iob *string,struct file_action_message *fam);
/****************************************************************************/
@ -230,4 +210,9 @@ extern int __handle_record_locking(int cmd,struct flock * l,struct fd * fd,int *
/****************************************************************************/
/* stdio_remove_fd_alias.c */
extern void __remove_fd_alias(struct fd * fd);
/****************************************************************************/
#endif /* _STDIO_PROTOS_H */

View File

@ -0,0 +1,81 @@
/*
* $Id: stdio_remove_fd_alias.c,v 1.1 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
* Portable ISO 'C' (1994) runtime library for the Amiga computer
* Copyright (c) 2002-2005 by Olaf Barthel <olsen@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 */
/****************************************************************************/
void
__remove_fd_alias(struct fd * fd)
{
assert( fd != NULL );
if(fd->fd_Original != NULL) /* this is an alias */
{
struct fd * list_fd;
assert( fd->fd_Original != fd );
assert( fd->fd_Original->fd_Original == NULL );
/* Remove this alias from the list. */
for(list_fd = fd->fd_Original ;
list_fd != NULL ;
list_fd = list_fd->fd_NextLink)
{
if(list_fd->fd_NextLink == fd)
{
list_fd->fd_NextLink = fd->fd_NextLink;
break;
}
}
}
else if (fd->fd_NextLink != NULL) /* this one has aliases attached; it is the 'original' resource */
{
struct fd * first_alias;
struct fd * list_fd;
/* The first link now becomes the original resource */
first_alias = fd->fd_NextLink;
first_alias->fd_Original = NULL;
/* The resources are migrated to the first link. */
for(list_fd = first_alias->fd_NextLink ;
list_fd != NULL ;
list_fd = list_fd->fd_NextLink)
{
list_fd->fd_Original = first_alias;
}
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_sscanf.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_sscanf.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -73,7 +73,7 @@ sscanf(const char *s,const char *format, ...)
if(__check_abort_enabled)
__check_abort();
__initialize_iob(&string_iob,(HOOKFUNC)__sscanf_hook_entry,
__initialize_iob(&string_iob,__sscanf_hook_entry,
NULL,
local_buffer,sizeof(local_buffer),
-1,

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_sscanf_hook_entry.c,v 1.2 2005-01-02 09:07:08 obarthel Exp $
* $Id: stdio_sscanf_hook_entry.c,v 1.3 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -43,21 +43,19 @@
/****************************************************************************/
void
int
__sscanf_hook_entry(
struct Hook * UNUSED unused_hook,
struct iob * string_iob,
struct file_hook_message * message)
struct iob * string_iob,
struct file_action_message * fam)
{
int result = -1;
int error = OK;
int num_bytes;
assert( message != NULL && string_iob != NULL );
assert( fam != NULL && string_iob != NULL );
if(message->action != file_hook_action_read)
if(fam->fam_Action != file_action_read)
{
error = EBADF;
fam->fam_Error = EBADF;
goto out;
}
@ -70,14 +68,14 @@ __sscanf_hook_entry(
num_bytes_left = string_iob->iob_StringLength - string_iob->iob_StringPosition;
num_bytes = message->size;
num_bytes = fam->fam_Size;
if(num_bytes > num_bytes_left)
num_bytes = num_bytes_left;
assert( message->data != NULL );
assert( fam->fam_Data != NULL );
assert( num_bytes >= 0 );
memmove(message->data,&string_iob->iob_String[string_iob->iob_StringPosition],(size_t)num_bytes);
memmove(fam->fam_Data,&string_iob->iob_String[string_iob->iob_StringPosition],(size_t)num_bytes);
string_iob->iob_StringPosition += num_bytes;
}
else
@ -89,6 +87,6 @@ __sscanf_hook_entry(
out:
message->result = result;
message->error = error;
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vasprintf.c,v 1.6 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_vasprintf.c,v 1.7 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -88,7 +88,7 @@ __vasprintf(const char *file,int line,char **ret,const char *format,va_list arg)
(*ret) = NULL;
__initialize_iob(&string_iob,(HOOKFUNC)__vasprintf_hook_entry,
__initialize_iob(&string_iob,__vasprintf_hook_entry,
NULL,
local_buffer,sizeof(local_buffer),
-1,

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vasprintf_hook_entry.c,v 1.3 2005-01-02 09:07:08 obarthel Exp $
* $Id: stdio_vasprintf_hook_entry.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -49,34 +49,33 @@
/****************************************************************************/
void
int
__vasprintf_hook_entry(
struct Hook * UNUSED unused_hook,
struct iob * string_iob,
struct file_hook_message * message)
struct iob * string_iob,
struct file_action_message * fam)
{
int result = -1;
int error = OK;
int num_bytes_left;
int num_bytes;
assert( message != NULL && string_iob != NULL );
assert( message->action == file_hook_action_write );
assert( fam != NULL && string_iob != NULL );
assert( fam->fam_Action == file_action_write );
if(message->action != file_hook_action_write)
if(fam->fam_Action != file_action_write)
{
error = EBADF;
goto out;
}
if(string_iob->iob_StringPosition + message->size > string_iob->iob_StringSize)
if(string_iob->iob_StringPosition + fam->fam_Size > string_iob->iob_StringSize)
{
const int granularity = 64;
size_t new_size;
char * buffer;
new_size = string_iob->iob_StringPosition + message->size + granularity;
new_size = string_iob->iob_StringPosition + fam->fam_Size + granularity;
buffer = __malloc(new_size,string_iob->iob_File,string_iob->iob_Line);
if(buffer == NULL)
@ -100,20 +99,21 @@ __vasprintf_hook_entry(
num_bytes_left = string_iob->iob_StringSize - string_iob->iob_StringPosition;
num_bytes = message->size;
num_bytes = fam->fam_Size;
if(num_bytes > num_bytes_left)
num_bytes = num_bytes_left;
assert( num_bytes >= 0 );
assert( message->data != NULL );
assert( fam->fam_Data != NULL );
memmove(&string_iob->iob_String[string_iob->iob_StringPosition],message->data,(size_t)num_bytes);
memmove(&string_iob->iob_String[string_iob->iob_StringPosition],fam->fam_Data,(size_t)num_bytes);
string_iob->iob_StringPosition += num_bytes;
result = num_bytes;
out:
message->result = result;
message->error = error;
fam->fam_Error = error;
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vfprintf.c,v 1.8 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_vfprintf.c,v 1.9 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -732,8 +732,8 @@ vfprintf(FILE * stream,const char * format, va_list arg)
if(precision < 1)
precision = 1;
SHOWVALUE(local_exponent);
SHOWVALUE(local_precision);
SHOWVALUE(exponent);
SHOWVALUE(precision);
/* If the exponent is < -4 or greater than or equal to
* the precision, we switch to 'e' or 'f' format,

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vsnprintf.c,v 1.4 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_vsnprintf.c,v 1.5 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -78,7 +78,7 @@ vsnprintf(char *buffer,size_t size,const char *format,va_list arg)
if(__check_abort_enabled)
__check_abort();
__initialize_iob(&string_iob,(HOOKFUNC)__vsnprintf_hook_entry,
__initialize_iob(&string_iob,__vsnprintf_hook_entry,
NULL,
local_buffer,sizeof(local_buffer),
-1,

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vsnprintf_hook_entry.c,v 1.4 2005-01-02 09:07:08 obarthel Exp $
* $Id: stdio_vsnprintf_hook_entry.c,v 1.5 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -43,47 +43,47 @@
/****************************************************************************/
void
int
__vsnprintf_hook_entry(
struct Hook * UNUSED unused_hook,
struct iob * string_iob,
struct file_hook_message * message)
struct iob * string_iob,
struct file_action_message * fam)
{
int result = -1;
int error = OK;
assert( message != NULL && string_iob != NULL );
assert( fam != NULL && string_iob != NULL );
if(message->action != file_hook_action_write)
if(fam->fam_Action != file_action_write)
{
error = EBADF;
goto out;
}
if(message->size > 0 && string_iob->iob_StringSize > 0 && string_iob->iob_StringPosition < string_iob->iob_StringSize)
if(fam->fam_Size > 0 && string_iob->iob_StringSize > 0 && string_iob->iob_StringPosition < string_iob->iob_StringSize)
{
int num_bytes_left;
int num_bytes;
num_bytes_left = string_iob->iob_StringSize - string_iob->iob_StringPosition;
num_bytes = message->size;
num_bytes = fam->fam_Size;
if(num_bytes > num_bytes_left)
num_bytes = num_bytes_left;
assert( num_bytes >= 0 );
assert( message->data != NULL );
assert( fam->fam_Data != NULL );
assert( string_iob->iob_String != NULL );
memmove(&string_iob->iob_String[string_iob->iob_StringPosition],message->data,(size_t)num_bytes);
memmove(&string_iob->iob_String[string_iob->iob_StringPosition],fam->fam_Data,(size_t)num_bytes);
string_iob->iob_StringPosition += num_bytes;
}
result = message->size;
result = fam->fam_Size;
out:
message->result = result;
message->error = error;
fam->fam_Error = error;
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vsprintf.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_vsprintf.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -65,7 +65,7 @@ vsprintf(char *s,const char *format,va_list arg)
if(__check_abort_enabled)
__check_abort();
__initialize_iob(&string_iob,(HOOKFUNC)__vsprintf_hook_entry,
__initialize_iob(&string_iob,__vsprintf_hook_entry,
NULL,
buffer,sizeof(buffer),
-1,

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vsprintf_hook_entry.c,v 1.2 2005-01-02 09:07:08 obarthel Exp $
* $Id: stdio_vsprintf_hook_entry.c,v 1.3 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -43,35 +43,32 @@
/****************************************************************************/
void
int
__vsprintf_hook_entry(
struct Hook * UNUSED unused_hook,
struct iob * string_iob,
struct file_hook_message * message)
struct iob * string_iob,
struct file_action_message * fam)
{
int result = -1;
int error = OK;
assert( message != NULL && string_iob != NULL );
assert( fam != NULL && string_iob != NULL );
if(message->action != file_hook_action_write)
if(fam->fam_Action != file_action_write)
{
error = EBADF;
fam->fam_Error = EBADF;
goto out;
}
assert( message->size >= 0 );
assert( fam->fam_Size >= 0 );
assert( message->data != NULL );
assert( fam->fam_Data != NULL );
assert( string_iob->iob_StringPosition >= 0 );
memmove(&string_iob->iob_String[string_iob->iob_StringPosition],message->data,(size_t)message->size);
string_iob->iob_StringPosition += message->size;
memmove(&string_iob->iob_String[string_iob->iob_StringPosition],fam->fam_Data,(size_t)fam->fam_Size);
string_iob->iob_StringPosition += fam->fam_Size;
result = message->size;
result = fam->fam_Size;
out:
message->result = result;
message->error = error;
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: unistd_dup2.c,v 1.5 2005-02-18 18:53:17 obarthel Exp $
* $Id: unistd_dup2.c,v 1.6 2005-02-20 13:19:40 obarthel Exp $
*
* :ts=4
*
@ -44,7 +44,6 @@
int
dup2(int file_descriptor1, int file_descriptor2)
{
DECLARE_UTILITYBASE();
struct fd * fd1;
int result = -1;
@ -53,8 +52,6 @@ dup2(int file_descriptor1, int file_descriptor2)
SHOWVALUE(file_descriptor1);
SHOWVALUE(file_descriptor2);
assert( UtilityBase != NULL );
if(__check_abort_enabled)
__check_abort();