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

- Added a wrapper function which handles the thread-safe stdio stream

resolution.

- In tcflush() a break signal can no longer cause the read flush loop
  to be quit with two semaphores still locked.


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15170 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2006-11-16 14:39:23 +00:00
parent 77279e3224
commit 3a0324e4ff
24 changed files with 229 additions and 527 deletions

View File

@ -1,5 +1,5 @@
#
# $Id: GNUmakefile.68k,v 1.99 2006-11-15 09:17:04 obarthel Exp $
# $Id: GNUmakefile.68k,v 1.100 2006-11-16 14:39:23 obarthel Exp $
#
# :ts=8
#
@ -256,6 +256,7 @@ C_LIB = \
stdio_remove.o \
stdio_remove_fd_alias.o \
stdio_rename.o \
stdio_resolve_fd_file.o \
stdio_rewind.o \
stdio_scanf.o \
stdio_setbuf.o \

View File

@ -1,3 +1,9 @@
- Added a wrapper function which handles the thread-safe stdio stream
resolution.
- In tcflush() a break signal can no longer cause the read flush loop
to be quit with two semaphores still locked.
- In __obtain_daemon_message() the test to verify if the bsdsocket.library API
would support the server API functionality checked the wrong feature. Fixed.

View File

@ -1,5 +1,5 @@
/*
* $Id: fcntl_fcntl.c,v 1.19 2006-01-08 12:04:22 obarthel Exp $
* $Id: fcntl_fcntl.c,v 1.20 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -97,7 +97,7 @@ fcntl(int file_descriptor, int cmd, ... /* int arg */ )
goto out;
}
if(fd->fd_DefaultFile == ZERO)
if(fd->fd_File == ZERO)
{
__set_errno(EBADF);
goto out;
@ -155,7 +155,7 @@ fcntl(int file_descriptor, int cmd, ... /* int arg */ )
SHOWMSG("cmd=F_SETFL");
/* If this is a file, make sure that we don't hit a zero file handle. */
if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_SOCKET) && fd->fd_DefaultFile == ZERO)
if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_SOCKET) && fd->fd_File == ZERO)
{
__set_errno(EBADF);
goto out;

View File

@ -1,5 +1,5 @@
/*
* $Id: fcntl_get_default_file.c,v 1.7 2006-09-27 11:54:54 obarthel Exp $
* $Id: fcntl_get_default_file.c,v 1.8 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -46,7 +46,6 @@ __get_default_file(int file_descriptor,long * file_ptr)
{
int result = ERROR;
struct fd * fd;
BPTR file;
assert( file_descriptor >= 0 && file_descriptor < __num_fd );
assert( __fd[file_descriptor] != NULL );
@ -62,65 +61,7 @@ __get_default_file(int file_descriptor,long * file_ptr)
__fd_lock(fd);
#if defined(__THREAD_SAFE)
{
/* Check if this file should be dynamically bound to one of the
three standard I/O streams. */
if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO))
{
switch(fd->fd_DefaultFile)
{
case STDIN_FILENO:
file = Input();
break;
case STDOUT_FILENO:
file = Output();
break;
case STDERR_FILENO:
#if defined(__amigaos4__)
{
file = ErrorOutput();
}
#else
{
struct Process * this_process = (struct Process *)FindTask(NULL);
file = this_process->pr_CES;
}
#endif /* __amigaos4__ */
/* The following is rather controversial; if the standard error stream
is unavailable, we default to reuse the standard output stream. This
is problematic if the standard output stream was redirected and should
not be the same as the standard error output stream. */
if(file == ZERO)
file = Output();
break;
default:
file = ZERO;
break;
}
}
else
{
file = fd->fd_DefaultFile;
}
}
#else
{
file = fd->fd_DefaultFile;
}
#endif /* __THREAD_SAFE */
(*file_ptr) = (long)file;
(*file_ptr) = (long)__resolve_fd_file(fd);
result = 0;

View File

@ -1,5 +1,5 @@
/*
* $Id: clib2_io.h,v 1.3 2006-11-15 09:21:49 obarthel Exp $
* $Id: clib2_io.h,v 1.4 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -127,6 +127,7 @@ struct _fd
/* Sneaky preprocessor tricks to make access to the file/socket IDs
work smoothly. */
#define fd_DefaultFile fdu_Default.fdu_File
#define fd_File fdu_Default.fdu_File
#define fd_Socket fdu_Default.fdu_Socket
/****************************************************************************/

View File

@ -1,5 +1,5 @@
#
# $Id: libc.gmk,v 1.3 2006-11-15 09:17:04 obarthel Exp $
# $Id: libc.gmk,v 1.4 2006-11-16 14:39:23 obarthel Exp $
#
# :ts=8
#
@ -157,6 +157,7 @@ C_LIB := \
stdio_remove.o \
stdio_remove_fd_alias.o \
stdio_rename.o \
stdio_resolve_fd_file.o \
stdio_rewind.o \
stdio_scanf.o \
stdio_setbuf.o \

View File

@ -1,5 +1,5 @@
/*
* $Id: mount_fstatfs.c,v 1.13 2006-01-08 12:04:24 obarthel Exp $
* $Id: mount_fstatfs.c,v 1.14 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -106,7 +106,7 @@ fstatfs(int file_descriptor, struct statfs *buf)
}
PROFILE_OFF();
parent_dir = __safe_parent_of_file_handle(fd->fd_DefaultFile);
parent_dir = __safe_parent_of_file_handle(fd->fd_File);
PROFILE_ON();
if(parent_dir == ZERO)

View File

@ -1,5 +1,5 @@
/*
* $Id: socket_select_signal.c,v 1.4 2006-11-16 10:41:15 obarthel Exp $
* $Id: socket_select_signal.c,v 1.5 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -326,7 +326,7 @@ map_descriptor_sets(
/* Let's see if we can examine the file. Some file systems
may not support this. */
if(CANNOT __safe_examine_file_handle(fd->fd_DefaultFile,fib))
if(CANNOT __safe_examine_file_handle(fd->fd_File,fib))
{
SHOWMSG("file is unusable; we cannot examine the file.");
continue;
@ -812,7 +812,7 @@ __select(int num_fds,fd_set *read_fds,fd_set *write_fds,fd_set *except_fds,struc
if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE))
{
/* For an interactive stream, we simply ask. */
if(WaitForChar(fd->fd_DefaultFile,1))
if(WaitForChar(fd->fd_File,1))
got_input = TRUE;
}
else
@ -824,7 +824,7 @@ __select(int num_fds,fd_set *read_fds,fd_set *write_fds,fd_set *except_fds,struc
unread data in the file, we will be able to read from it.
For pipes, any data reported to be in the "file" indicates
that there is something worth reading available. */
if(__safe_examine_file_handle(fd->fd_DefaultFile,fib))
if(__safe_examine_file_handle(fd->fd_File,fib))
{
if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION))
{
@ -1010,14 +1010,14 @@ __select(int num_fds,fd_set *read_fds,fd_set *write_fds,fd_set *except_fds,struc
if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE))
{
if(WaitForChar(fd->fd_DefaultFile,1))
if(WaitForChar(fd->fd_File,1))
got_input = TRUE;
}
else
{
D_S(struct FileInfoBlock,fib);
if(__safe_examine_file_handle(fd->fd_DefaultFile,fib))
if(__safe_examine_file_handle(fd->fd_File,fib))
{
if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION))
{

View File

@ -1,5 +1,5 @@
/*
* $Id: stat_fchmod.c,v 1.12 2006-01-08 12:04:24 obarthel Exp $
* $Id: stat_fchmod.c,v 1.13 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -127,7 +127,7 @@ fchmod(int file_descriptor, mode_t mode)
SET_FLAG(protection,FIBF_OTR_EXECUTE);
PROFILE_OFF();
parent_dir = __safe_parent_of_file_handle(fd->fd_DefaultFile);
parent_dir = __safe_parent_of_file_handle(fd->fd_File);
PROFILE_ON();
if(parent_dir == ZERO)
@ -139,7 +139,7 @@ fchmod(int file_descriptor, mode_t mode)
}
PROFILE_OFF();
success = __safe_examine_file_handle(fd->fd_DefaultFile,fib);
success = __safe_examine_file_handle(fd->fd_File,fib);
PROFILE_ON();
if(NO success)

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fdhookentry.c,v 1.33 2006-09-20 19:46:57 obarthel Exp $
* $Id: stdio_fdhookentry.c,v 1.34 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -81,64 +81,7 @@ __fd_hook_entry(
__fd_lock(fd);
#if defined(__THREAD_SAFE)
{
/* Check if this file should be dynamically bound to one of the
three standard I/O streams. */
if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO))
{
switch(fd->fd_DefaultFile)
{
case STDIN_FILENO:
file = Input();
break;
case STDOUT_FILENO:
file = Output();
break;
case STDERR_FILENO:
#if defined(__amigaos4__)
{
file = ErrorOutput();
}
#else
{
struct Process * this_process = (struct Process *)FindTask(NULL);
file = this_process->pr_CES;
}
#endif /* __amigaos4__ */
/* The following is rather controversial; if the standard error stream
is unavailable, we default to reuse the standard output stream. This
is problematic if the standard output stream was redirected and should
not be the same as the standard error output stream. */
if(file == ZERO)
file = Output();
break;
default:
file = ZERO;
break;
}
}
else
{
file = fd->fd_DefaultFile;
}
}
#else
{
file = fd->fd_DefaultFile;
}
#endif /* __THREAD_SAFE */
file = __resolve_fd_file(fd);
if(file == ZERO)
{
SHOWMSG("file is closed");
@ -246,7 +189,7 @@ __fd_hook_entry(
{
/* Should we reset this file into line 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);
SetMode(fd->fd_File,DOSFALSE);
/* Are we allowed to close this file? */
if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_NO_CLOSE))
@ -265,14 +208,14 @@ __fd_hook_entry(
PROFILE_OFF();
parent_dir = __safe_parent_of_file_handle(fd->fd_DefaultFile);
parent_dir = __safe_parent_of_file_handle(fd->fd_File);
if(parent_dir != ZERO)
{
if(__safe_examine_file_handle(fd->fd_DefaultFile,fib))
if(__safe_examine_file_handle(fd->fd_File,fib))
name_and_path_valid = TRUE;
}
if(CANNOT Close(fd->fd_DefaultFile))
if(CANNOT Close(fd->fd_File))
{
fam->fam_Error = __translate_io_error_to_errno(IoErr());
@ -281,7 +224,7 @@ __fd_hook_entry(
PROFILE_ON();
fd->fd_DefaultFile = ZERO;
fd->fd_File = ZERO;
#if defined(UNIX_PATH_SEMANTICS)
{

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_file_init.c,v 1.11 2006-01-08 12:04:24 obarthel Exp $
* $Id: stdio_file_init.c,v 1.12 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -321,7 +321,7 @@ FILE_CONSTRUCTOR(stdio_file_init)
if(__WBenchMsg != NULL)
{
PROFILE_OFF();
__fd[STDERR_FILENO]->fd_DefaultFile = Output();
__fd[STDERR_FILENO]->fd_File = Output();
PROFILE_ON();
SET_FLAG(__fd[STDERR_FILENO]->fd_Flags,FDF_NO_CLOSE);
@ -351,13 +351,13 @@ FILE_CONSTRUCTOR(stdio_file_init)
Otherwise, try to duplicate the standard output stream. */
if(ces != ZERO)
{
__fd[STDERR_FILENO]->fd_DefaultFile = ces;
__fd[STDERR_FILENO]->fd_File = ces;
SET_FLAG(__fd[STDERR_FILENO]->fd_Flags,FDF_NO_CLOSE);
}
else
{
__fd[STDERR_FILENO]->fd_DefaultFile = Open("CONSOLE:",MODE_NEWFILE);
__fd[STDERR_FILENO]->fd_File = Open("CONSOLE:",MODE_NEWFILE);
}
}
@ -366,7 +366,7 @@ FILE_CONSTRUCTOR(stdio_file_init)
/* Figure out if the standard error stream is bound to a console. */
if(FLAG_IS_CLEAR(__fd[STDERR_FILENO]->fd_Flags,FDF_STDIO))
{
if(IsInteractive(__fd[STDERR_FILENO]->fd_DefaultFile))
if(IsInteractive(__fd[STDERR_FILENO]->fd_File))
SET_FLAG(__fd[STDERR_FILENO]->fd_Flags,FDF_IS_INTERACTIVE);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_grow_file.c,v 1.6 2006-01-08 12:04:24 obarthel Exp $
* $Id: stdio_grow_file.c,v 1.7 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -70,7 +70,7 @@ __grow_file_size(struct fd * fd,int num_bytes)
assert( FLAG_IS_CLEAR(fd->fd_Flags,FDF_STDIO) );
fh = BADDR(fd->fd_DefaultFile);
fh = BADDR(fd->fd_File);
if(fh != NULL && fh->fh_Type != NULL && DoPkt(fh->fh_Type,ACTION_DISK_INFO,MKBADDR(id),0,0,0,0))
block_size = id->id_BytesPerBlock;
@ -105,7 +105,7 @@ __grow_file_size(struct fd * fd,int num_bytes)
memset(aligned_buffer,0,(size_t)buffer_size);
PROFILE_OFF();
seek_position = Seek(fd->fd_DefaultFile,0,OFFSET_END);
seek_position = Seek(fd->fd_File,0,OFFSET_END);
PROFILE_ON();
if(seek_position == SEEK_ERROR && IoErr() != OK)
@ -117,7 +117,7 @@ __grow_file_size(struct fd * fd,int num_bytes)
position = (off_t)seek_position;
PROFILE_OFF();
seek_position = Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT);
seek_position = Seek(fd->fd_File,0,OFFSET_CURRENT);
PROFILE_ON();
current_position = (off_t)seek_position;
@ -147,7 +147,7 @@ __grow_file_size(struct fd * fd,int num_bytes)
alignment_skip = 0;
PROFILE_OFF();
bytes_written = Write(fd->fd_DefaultFile,aligned_buffer,size);
bytes_written = Write(fd->fd_File,aligned_buffer,size);
PROFILE_ON();
if(bytes_written != size)

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_headers.h,v 1.29 2006-11-15 08:51:07 obarthel Exp $
* $Id: stdio_headers.h,v 1.30 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -459,6 +459,10 @@ extern void __fd_unlock(struct fd *fd);
/****************************************************************************/
extern BPTR __resolve_fd_file(struct fd * fd);
/****************************************************************************/
#else
/****************************************************************************/
@ -475,6 +479,10 @@ extern void __fd_unlock(struct fd *fd);
/****************************************************************************/
#define __resolve_fd_file(fd) (fd->fd_File)
/****************************************************************************/
#endif /* __THREAD_SAFE */
/****************************************************************************/

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_record_locking.c,v 1.18 2006-10-10 13:39:26 obarthel Exp $
* $Id: stdio_record_locking.c,v 1.19 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -298,7 +298,7 @@ remove_locked_region_node(struct FileLockSemaphore * fls,struct fd * fd,LONG sta
/* Find the locked file this descriptor
* buffer belongs to.
*/
if(find_file_lock_node_by_file_handle(fls,fd->fd_DefaultFile,&which_lock) == OK)
if(find_file_lock_node_by_file_handle(fls,fd->fd_File,&which_lock) == OK)
{
struct LockedRegionNode * lrn;
struct LockedRegionNode * lrn_next;
@ -434,7 +434,7 @@ create_file_lock_node(struct fd * fd,struct FileLockNode ** result_ptr)
* and the name of the file for later use in
* comparisons.
*/
if(CANNOT __safe_examine_file_handle(fd->fd_DefaultFile,fib))
if(CANNOT __safe_examine_file_handle(fd->fd_File,fib))
{
SHOWMSG("couldn't examine file handle");
@ -453,7 +453,7 @@ create_file_lock_node(struct fd * fd,struct FileLockNode ** result_ptr)
memset(fln,0,sizeof(*fln));
fln->fln_FileParentDir = __safe_parent_of_file_handle(fd->fd_DefaultFile);
fln->fln_FileParentDir = __safe_parent_of_file_handle(fd->fd_File);
if(fln->fln_FileParentDir == ZERO)
{
SHOWMSG("couldn't get parent directory");
@ -678,7 +678,7 @@ cleanup_locked_records(struct fd * fd)
fls = obtain_file_lock_semaphore(FALSE);
if(fls != NULL)
{
BPTR file_handle = fd->fd_DefaultFile;
BPTR file_handle = fd->fd_File;
struct FileLockNode * which_lock = NULL;
pid_t this_task = getpid();
LONG error;
@ -741,7 +741,7 @@ int
__handle_record_locking(int cmd,struct flock * l,struct fd * fd,int * error_ptr)
{
struct FileLockSemaphore * fls = NULL;
BPTR file_handle = fd->fd_DefaultFile;
BPTR file_handle = fd->fd_File;
struct LockedRegionNode * lrn = NULL;
struct FileLockNode * fln = NULL;
D_S(struct FileInfoBlock,fib);

View File

@ -0,0 +1,115 @@
/*
* $Id: stdio_resolve_fd_file.c,v 1.1 2006-11-16 14:39:23 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 _FCNTL_HEADERS_H
#include "fcntl_headers.h"
#endif /* _FCNTL_HEADERS_H */
/****************************************************************************/
/* The following is not part of the ISO 'C' (1994) standard. */
/****************************************************************************/
#if defined(__THREAD_SAFE)
/****************************************************************************/
#ifdef __resolve_fd_file
#undef __resolve_fd_file
#endif /* __resolve_fd_file */
/****************************************************************************/
BPTR
__resolve_fd_file(struct fd * fd)
{
BPTR file;
/* Is this one the standard I/O streams for which the associated file
handle should be determined dynamically? */
if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO))
{
switch(fd->fd_File)
{
case STDIN_FILENO:
file = Input();
break;
case STDOUT_FILENO:
file = Output();
break;
case STDERR_FILENO:
#if defined(__amigaos4__)
{
file = ErrorOutput();
}
#else
{
struct Process * this_process = (struct Process *)FindTask(NULL);
file = this_process->pr_CES;
}
#endif /* __amigaos4__ */
/* The following is rather controversial; if the standard error stream
is unavailable, we default to reuse the standard output stream. This
is problematic if the standard output stream was redirected and should
not be the same as the standard error output stream. */
if(file == ZERO)
file = Output();
break;
default:
file = ZERO;
break;
}
}
else
{
/* Just return what's there. */
file = fd->fd_File;
}
return(file);
}
/****************************************************************************/
#endif /* __THREAD_SAFE */

View File

@ -1,5 +1,5 @@
/*
* $Id: termios_console_fdhookentry.c,v 1.4 2006-09-20 19:46:57 obarthel Exp $
* $Id: termios_console_fdhookentry.c,v 1.5 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -198,64 +198,7 @@ __termios_console_hook(
__fd_lock(fd);
#if defined(__THREAD_SAFE)
{
/* Check if this file should be dynamically bound to one of the
three standard I/O streams. */
if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO))
{
switch(fd->fd_DefaultFile)
{
case STDIN_FILENO:
file = Input();
break;
case STDOUT_FILENO:
file = Output();
break;
case STDERR_FILENO:
#if defined(__amigaos4__)
{
file = ErrorOutput();
}
#else
{
struct Process * this_process = (struct Process *)FindTask(NULL);
file = this_process->pr_CES;
}
#endif /* __amigaos4__ */
/* The following is rather controversial; if the standard error stream
is unavailable, we default to reuse the standard output stream. This
is problematic if the standard output stream was redirected and should
not be the same as the standard error output stream. */
if(file == ZERO)
file = Output();
break;
default:
file = ZERO;
break;
}
}
else
{
file = fd->fd_DefaultFile;
}
}
#else
{
file = fd->fd_DefaultFile;
}
#endif /* __THREAD_SAFE */
file = __resolve_fd_file(fd);
if(file == ZERO)
{
SHOWMSG("file is closed");
@ -493,7 +436,7 @@ __termios_console_hook(
{
/* Should we reset this file into line 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);
SetMode(fd->fd_File,DOSFALSE);
/* Are we allowed to close this file? */
if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_NO_CLOSE))
@ -506,7 +449,7 @@ __termios_console_hook(
PROFILE_OFF();
if(CANNOT Close(fd->fd_DefaultFile))
if(CANNOT Close(fd->fd_File))
{
fam->fam_Error = __translate_io_error_to_errno(IoErr());
@ -515,7 +458,7 @@ __termios_console_hook(
PROFILE_ON();
fd->fd_DefaultFile = ZERO;
fd->fd_File = ZERO;
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: termios_tcdrain.c,v 1.3 2006-01-08 12:04:27 obarthel Exp $
* $Id: termios_tcdrain.c,v 1.4 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -48,8 +48,6 @@ tcdrain(int file_descriptor)
{
int result = ERROR;
struct fd *fd;
struct termios *tios;
BPTR file;
ENTER();
@ -69,64 +67,18 @@ tcdrain(int file_descriptor)
__fd_lock(fd);
file = fd->fd_DefaultFile;
#if defined(__THREAD_SAFE)
{
if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO))
{
switch(fd->fd_DefaultFile)
{
case STDIN_FILENO:
file = Input();
break;
case STDOUT_FILENO:
file = Output();
break;
case STDERR_FILENO:
#if defined(__amigaos4__)
{
file = ErrorOutput();
}
#else
{
struct Process * this_process = (struct Process *)FindTask(NULL);
file = this_process->pr_CES;
}
#endif /* __amigaos4__ */
/* The following is rather controversial; if the standard error stream
is unavailable, we default to reuse the standard output stream. This
is problematic if the standard output stream was redirected and should
not be the same as the standard error output stream. */
if(file == ZERO)
file = Output();
break;
default:
file = ZERO;
break;
}
}
}
#endif /* __THREAD_SAFE */
if(FLAG_IS_SET(fd->fd_Flags,FDF_TERMIOS))
{
struct termios *tios;
BPTR file;
tios = fd->fd_Aux;
switch(tios->type)
{
case TIOST_CONSOLE:
file = __resolve_fd_file(fd);
if(file == ZERO)
{
__set_errno(EBADF);

View File

@ -1,5 +1,5 @@
/*
* $Id: termios_tcflush.c,v 1.4 2006-01-08 12:04:27 obarthel Exp $
* $Id: termios_tcflush.c,v 1.5 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -50,9 +50,6 @@ tcflush(int file_descriptor,int queue)
{
int result = ERROR;
struct fd *fd;
char buf[64];
struct termios *tios;
BPTR file;
ENTER();
@ -80,62 +77,16 @@ tcflush(int file_descriptor,int queue)
goto out;
}
file = fd->fd_DefaultFile;
#if defined(__THREAD_SAFE)
{
if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO))
{
switch(fd->fd_DefaultFile)
{
case STDIN_FILENO:
file = Input();
break;
case STDOUT_FILENO:
file = Output();
break;
case STDERR_FILENO:
#if defined(__amigaos4__)
{
file = ErrorOutput();
}
#else
{
struct Process * this_process = (struct Process *)FindTask(NULL);
file = this_process->pr_CES;
}
#endif /* __amigaos4__ */
/* The following is rather controversial; if the standard error stream
is unavailable, we default to reuse the standard output stream. This
is problematic if the standard output stream was redirected and should
not be the same as the standard error output stream. */
if(file == ZERO)
file = Output();
break;
default:
file = ZERO;
break;
}
}
}
#endif /* __THREAD_SAFE */
tios = fd->fd_Aux;
if(queue == TCIFLUSH || queue == TCIOFLUSH)
{
LONG num_bytes_read;
char buf[64];
struct termios *tios;
BPTR file;
tios = fd->fd_Aux;
file = __resolve_fd_file(fd);
if(file == ZERO)
{
__set_errno(EBADF);
@ -152,8 +103,8 @@ tcflush(int file_descriptor,int queue)
while(WaitForChar(file,1) != DOSFALSE)
{
if(__check_abort_enabled)
__check_abort();
if(__check_abort_enabled && FLAG_IS_SET(SetSignal(0,0),__break_signal_mask))
break;
/* Read away available data. (upto 8k) */
num_bytes_read = Read(file,buf,64);
@ -178,6 +129,11 @@ tcflush(int file_descriptor,int queue)
*/
result = tcdrain(file_descriptor);
}
else
{
/* ZZZ is this the correct result? */
result = OK;
}
out:

View File

@ -1,5 +1,5 @@
/*
* $Id: termios_tcsetattr.c,v 1.4 2006-01-08 12:04:27 obarthel Exp $
* $Id: termios_tcsetattr.c,v 1.5 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -53,56 +53,7 @@ set_console_termios(struct fd *fd,struct termios *new_tios)
if(old_tios->type != TIOST_CONSOLE)
goto out;
file = fd->fd_DefaultFile;
#if defined(__THREAD_SAFE)
{
if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO))
{
switch(fd->fd_DefaultFile)
{
case STDIN_FILENO:
file = Input();
break;
case STDOUT_FILENO:
file = Output();
break;
case STDERR_FILENO:
#if defined(__amigaos4__)
{
file = ErrorOutput();
}
#else
{
struct Process * this_process = (struct Process *)FindTask(NULL);
file = this_process->pr_CES;
}
#endif /* __amigaos4__ */
/* The following is rather controversial; if the standard error stream
is unavailable, we default to reuse the standard output stream. This
is problematic if the standard output stream was redirected and should
not be the same as the standard error output stream. */
if(file == ZERO)
file = Output();
break;
default:
file = ZERO;
break;
}
}
}
#endif /* __THREAD_SAFE */
file = __resolve_fd_file(fd);
if(file == ZERO)
goto out;

View File

@ -1,5 +1,5 @@
/*
* $Id: unistd_fchown.c,v 1.14 2006-09-25 15:38:21 obarthel Exp $
* $Id: unistd_fchown.c,v 1.15 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -89,7 +89,7 @@ fchown(int file_descriptor, uid_t owner, gid_t group)
}
PROFILE_OFF();
success = (__safe_examine_file_handle(fd->fd_DefaultFile,fib) && (parent_dir = __safe_parent_of_file_handle(fd->fd_DefaultFile)) != ZERO);
success = (__safe_examine_file_handle(fd->fd_File,fib) && (parent_dir = __safe_parent_of_file_handle(fd->fd_File)) != ZERO);
PROFILE_ON();
if(NO success)

View File

@ -1,5 +1,5 @@
/*
* $Id: unistd_ftruncate.c,v 1.14 2006-01-08 12:04:27 obarthel Exp $
* $Id: unistd_ftruncate.c,v 1.15 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -107,7 +107,7 @@ ftruncate(int file_descriptor, off_t length)
}
/* Figure out how large the file is right now. */
if(CANNOT __safe_examine_file_handle(fd->fd_DefaultFile,fib))
if(CANNOT __safe_examine_file_handle(fd->fd_File,fib))
{
SHOWMSG("couldn't examine file");
@ -123,7 +123,7 @@ ftruncate(int file_descriptor, off_t length)
/* Remember where we started. */
if(NOT initial_position_valid)
{
initial_position = Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT);
initial_position = Seek(fd->fd_File,0,OFFSET_CURRENT);
if(initial_position == SEEK_ERROR && IoErr() != OK)
goto out;
@ -131,7 +131,7 @@ ftruncate(int file_descriptor, off_t length)
}
/* Careful: seek to a position where the file can be safely truncated. */
if(Seek(fd->fd_DefaultFile,length,OFFSET_BEGINNING) == SEEK_ERROR && IoErr() != OK)
if(Seek(fd->fd_File,length,OFFSET_BEGINNING) == SEEK_ERROR && IoErr() != OK)
{
D(("could not move to file offset %ld",length));
@ -139,7 +139,7 @@ ftruncate(int file_descriptor, off_t length)
goto out;
}
if(SetFileSize(fd->fd_DefaultFile,length,OFFSET_BEGINNING) == SEEK_ERROR)
if(SetFileSize(fd->fd_File,length,OFFSET_BEGINNING) == SEEK_ERROR)
{
D(("could not reduce file to size %ld",length));
@ -164,7 +164,7 @@ ftruncate(int file_descriptor, off_t length)
/* Remember where we started. */
if(NOT initial_position_valid)
{
initial_position = Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT);
initial_position = Seek(fd->fd_File,0,OFFSET_CURRENT);
if(initial_position == SEEK_ERROR && IoErr() != OK)
goto out;
@ -172,7 +172,7 @@ ftruncate(int file_descriptor, off_t length)
}
/* Move to what should be the end of the file. */
if(Seek(fd->fd_DefaultFile,current_file_size,OFFSET_BEGINNING) == SEEK_ERROR && IoErr() != OK)
if(Seek(fd->fd_File,current_file_size,OFFSET_BEGINNING) == SEEK_ERROR && IoErr() != OK)
{
D(("could not move to file offset %ld",current_file_size));
@ -198,7 +198,7 @@ ftruncate(int file_descriptor, off_t length)
/* ftruncate() may change the size of the file, but it may
not change the current file position. */
if(initial_position_valid)
Seek(fd->fd_DefaultFile,initial_position,OFFSET_CURRENT);
Seek(fd->fd_File,initial_position,OFFSET_CURRENT);
__fd_unlock(fd);

View File

@ -1,5 +1,5 @@
/*
* $Id: unistd_isatty.c,v 1.8 2006-01-08 12:04:27 obarthel Exp $
* $Id: unistd_isatty.c,v 1.9 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -69,74 +69,16 @@ isatty(int file_descriptor)
__fd_lock(fd);
#if defined(__THREAD_SAFE)
result = 1;
if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_INTERACTIVE))
{
if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO))
{
BPTR file;
BPTR file;
switch(fd->fd_DefaultFile)
{
case STDIN_FILENO:
file = Input();
break;
case STDOUT_FILENO:
file = Output();
break;
case STDERR_FILENO:
#if defined(__amigaos4__)
{
file = ErrorOutput();
}
#else
{
struct Process * this_process = (struct Process *)FindTask(NULL);
file = this_process->pr_CES;
}
#endif /* __amigaos4__ */
/* The following is rather controversial; if the standard error stream
is unavailable, we default to reuse the standard output stream. This
is problematic if the standard output stream was redirected and should
not be the same as the standard error output stream. */
if(file == ZERO)
file = Output();
break;
default:
file = ZERO;
break;
}
if(file != ZERO && IsInteractive(file))
result = 1;
else
result = 0;
}
else
{
if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE))
result = 1;
else
result = 0;
}
}
#else
{
if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE))
result = 1;
else
file = __resolve_fd_file(fd);
if(file == ZERO || NOT IsInteractive(file))
result = 0;
}
#endif /* __THREAD_SAFE */
out:

View File

@ -1,5 +1,5 @@
/*
* $Id: unistd_sync_fd.c,v 1.7 2006-01-08 12:04:27 obarthel Exp $
* $Id: unistd_sync_fd.c,v 1.8 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -70,11 +70,11 @@ __sync_fd(struct fd * fd,int mode)
/* The mode tells us what to flush. 0 means "flush just the data", and
everything else means "flush everything. */
Flush(fd->fd_DefaultFile);
Flush(fd->fd_File);
if(mode != 0)
{
struct FileHandle * fh = BADDR(fd->fd_DefaultFile);
struct FileHandle * fh = BADDR(fd->fd_File);
/* Verify that this file is not bound to "NIL:". */
if(fh->fh_Type != NULL)

View File

@ -1,5 +1,5 @@
/*
* $Id: unistd_ttyname_r.c,v 1.5 2006-09-27 11:54:54 obarthel Exp $
* $Id: unistd_ttyname_r.c,v 1.6 2006-11-16 14:39:23 obarthel Exp $
*
* :ts=4
*
@ -45,7 +45,6 @@ int
ttyname_r(int file_descriptor,char *name,size_t buflen)
{
const char *tty_file_name;
BOOL is_tty = FALSE;
struct fd *fd;
int result;
@ -64,73 +63,16 @@ ttyname_r(int file_descriptor,char *name,size_t buflen)
__fd_lock(fd);
#if defined(__THREAD_SAFE)
if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_INTERACTIVE))
{
if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO))
BPTR file;
file = __resolve_fd_file(fd);
if(file == ZERO || NOT IsInteractive(file))
{
BPTR file;
switch(fd->fd_DefaultFile)
{
case STDIN_FILENO:
file = Input();
break;
case STDOUT_FILENO:
file = Output();
break;
case STDERR_FILENO:
#if defined(__amigaos4__)
{
file = ErrorOutput();
}
#else
{
struct Process * this_process = (struct Process *)FindTask(NULL);
file = this_process->pr_CES;
}
#endif /* __amigaos4__ */
/* The following is rather controversial; if the standard error stream
is unavailable, we default to reuse the standard output stream. This
is problematic if the standard output stream was redirected and should
not be the same as the standard error output stream. */
if(file == ZERO)
file = Output();
break;
default:
file = ZERO;
break;
}
if(file != ZERO && IsInteractive(file))
is_tty = TRUE;
result = ENOTTY;
goto out;
}
else
{
if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE))
is_tty = TRUE;
}
}
#else
{
if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE))
is_tty = TRUE;
}
#endif /* __THREAD_SAFE */
if(NOT is_tty)
{
result = ENOTTY;
goto out;
}
#if defined(UNIX_PATH_SEMANTICS)