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

- The lseek() function return code was not consistently treated as the

then current file position. Fixed.

- Numerous house-keeping changes.


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14836 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2005-02-20 15:46:57 +00:00
parent 410833d2ed
commit 18f1f75479
20 changed files with 139 additions and 120 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: fcntl_close.c,v 1.9 2005-02-20 13:19:40 obarthel Exp $
* $Id: fcntl_close.c,v 1.10 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -70,9 +70,13 @@ close(int file_descriptor)
assert( fd->fd_Action != NULL );
result = (*fd->fd_Action)(fd,&fam);
if(result < 0)
if((*fd->fd_Action)(fd,&fam) < 0)
{
__set_errno(fam.fam_Error);
goto out;
}
result = 0;
out:

View File

@ -1,5 +1,5 @@
/*
* $Id: fcntl_lseek.c,v 1.6 2005-02-20 13:19:40 obarthel Exp $
* $Id: fcntl_lseek.c,v 1.7 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -46,6 +46,7 @@ lseek(int file_descriptor, off_t offset, int mode)
{
struct file_action_message fam;
off_t result = -1;
off_t position;
struct fd * fd;
ENTER();
@ -76,19 +77,21 @@ lseek(int file_descriptor, off_t offset, int mode)
goto out;
}
fam.fam_Action = file_action_seek;
fam.fam_Position = offset;
fam.fam_Mode = mode;
fam.fam_Action = file_action_seek;
fam.fam_Offset = offset;
fam.fam_Mode = mode;
assert( fd->fd_Action != NULL );
result = (*fd->fd_Action)(fd,&fam);
if(result < 0)
position = (*fd->fd_Action)(fd,&fam);
if(position < 0)
{
__set_errno(fam.fam_Error);
goto out;
}
result = position;
out:
RETURN(result);

View File

@ -1,5 +1,5 @@
/*
* $Id: fcntl_read.c,v 1.5 2005-02-20 13:19:40 obarthel Exp $
* $Id: fcntl_read.c,v 1.6 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -50,8 +50,9 @@
ssize_t
read(int file_descriptor, void * buffer, size_t num_bytes)
{
ssize_t num_bytes_read;
ssize_t result = -1;
struct fd * fd;
off_t result = -1;
ENTER();
@ -108,15 +109,20 @@ read(int file_descriptor, void * buffer, size_t num_bytes)
assert( fd->fd_Action != NULL );
result = (*fd->fd_Action)(fd,&fam);
if(result < 0)
num_bytes_read = (*fd->fd_Action)(fd,&fam);
if(num_bytes_read < 0)
{
__set_errno(fam.fam_Error);
goto out;
}
}
else
{
result = 0;
num_bytes_read = 0;
}
result = num_bytes_read;
out:
RETURN(result);

View File

@ -1,5 +1,5 @@
/*
* $Id: fcntl_write.c,v 1.5 2005-02-20 13:19:40 obarthel Exp $
* $Id: fcntl_write.c,v 1.6 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -50,8 +50,9 @@
ssize_t
write(int file_descriptor, const void * buffer, size_t num_bytes)
{
ssize_t num_bytes_written;
ssize_t result = -1;
struct fd * fd;
off_t result = -1;
ENTER();
@ -108,15 +109,20 @@ write(int file_descriptor, const void * buffer, size_t num_bytes)
assert( fd->fd_Action != NULL );
result = (*fd->fd_Action)(fd,&fam);
if(result < 0)
num_bytes_written = (*fd->fd_Action)(fd,&fam);
if(num_bytes_written < 0)
{
__set_errno(fam.fam_Error);
goto out;
}
}
else
{
result = 0;
num_bytes_written = 0;
}
result = num_bytes_written;
out:
RETURN(result);

View File

@ -1,5 +1,5 @@
/*
* $Id: types.h,v 1.3 2005-01-02 09:07:21 obarthel Exp $
* $Id: types.h,v 1.4 2005-02-20 15:46:57 obarthel Exp $
*
* :ts=4
*
@ -53,7 +53,7 @@ typedef unsigned int gid_t;
typedef unsigned int ino_t;
typedef unsigned int mode_t;
typedef unsigned int nlink_t;
typedef int off_t;
typedef long int off_t;
typedef int pid_t;
typedef unsigned int rlim_t;
typedef int ssize_t;

View File

@ -1,5 +1,5 @@
/*
* $Id: socket_hook_entry.c,v 1.8 2005-02-20 13:19:40 obarthel Exp $
* $Id: socket_hook_entry.c,v 1.9 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -51,7 +51,6 @@ __socket_hook_entry(
struct file_action_message * fam)
{
struct FileInfoBlock * fib;
int error = OK;
int result;
int param;
@ -73,7 +72,7 @@ __socket_hook_entry(
result = __recv((LONG)fd->fd_DefaultFile,fam->fam_Data,fam->fam_Size,0);
if(result < 0)
error = __get_errno();
fam->fam_Error = __get_errno();
PROFILE_ON();
@ -93,7 +92,7 @@ __socket_hook_entry(
result = __send((LONG)fd->fd_DefaultFile,fam->fam_Data,fam->fam_Size,0);
if(result < 0)
error = __get_errno();
fam->fam_Error = __get_errno();
PROFILE_ON();
@ -132,8 +131,9 @@ __socket_hook_entry(
SHOWMSG("file_action_seek");
result = -1;
error = ESPIPE;
result = -1;
fam->fam_Error = ESPIPE;
break;
@ -145,7 +145,7 @@ __socket_hook_entry(
result = __IoctlSocket(fd->fd_DefaultFile,FIONBIO,&param);
if(result < 0)
error = __get_errno();
fam->fam_Error = __get_errno();
break;
@ -157,7 +157,7 @@ __socket_hook_entry(
result = __IoctlSocket(fd->fd_DefaultFile,FIOASYNC,&param);
if(result < 0)
error = __get_errno();
fam->fam_Error = __get_errno();
break;
@ -183,14 +183,13 @@ __socket_hook_entry(
SHOWVALUE(fam->fam_Action);
result = -1;
error = EBADF;
result = -1;
fam->fam_Error = EBADF;
break;
}
fam->fam_Error = error;
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: socket_send.c,v 1.5 2005-02-18 18:53:16 obarthel Exp $
* $Id: socket_send.c,v 1.6 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -86,7 +86,7 @@ send(int sockfd,const void *buff,size_t nbytes,int flags)
goto out;
PROFILE_OFF();
result = __send((LONG)fd->fd_DefaultFile,buff,(LONG)nbytes,flags);
result = __send((LONG)fd->fd_DefaultFile,(void *)buff,(LONG)nbytes,flags);
PROFILE_ON();
out:

View File

@ -1,5 +1,5 @@
/*
* $Id: socket_sendto.c,v 1.5 2005-02-18 18:53:16 obarthel Exp $
* $Id: socket_sendto.c,v 1.6 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -87,7 +87,7 @@ sendto(int sockfd,const void *buff,int len,int flags,struct sockaddr *to,int tol
goto out;
PROFILE_OFF();
result = __sendto((LONG)fd->fd_DefaultFile,buff,len,flags,to,tolen);
result = __sendto((LONG)fd->fd_DefaultFile,(void *)buff,len,flags,to,tolen);
PROFILE_ON();
out:

View File

@ -1,5 +1,5 @@
/*
* $Id: socket_setsockopt.c,v 1.5 2005-02-18 18:53:16 obarthel Exp $
* $Id: socket_setsockopt.c,v 1.6 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -86,7 +86,7 @@ setsockopt(int sockfd,int level,int optname,const void *optval,int optlen)
goto out;
PROFILE_OFF();
result = __setsockopt((LONG)fd->fd_DefaultFile,level,optname,optval,optlen);
result = __setsockopt((LONG)fd->fd_DefaultFile,level,optname,(void *)optval,optlen);
PROFILE_ON();
out:

View File

@ -1,5 +1,5 @@
/*
* $Id: stat_fstat.c,v 1.5 2005-02-20 13:19:40 obarthel Exp $
* $Id: stat_fstat.c,v 1.6 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -104,6 +104,8 @@ fstat(int file_descriptor, struct stat * buffer)
__convert_file_info_to_stat(fam.fam_FileSystem,fib,buffer);
result = 0;
out:
RETURN(result);

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_dropiobreadbuffer.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_dropiobreadbuffer.c,v 1.5 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -77,9 +77,9 @@ __drop_iob_read_buffer(struct iob * file)
SHOWMSG("calling the action function");
fam.fam_Action = file_action_seek;
fam.fam_Position = -num_unread_bytes;
fam.fam_Mode = SEEK_CUR;
fam.fam_Action = file_action_seek;
fam.fam_Offset = -num_unread_bytes;
fam.fam_Mode = SEEK_CUR;
assert( file->iob_Action != NULL );

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fdhookentry.c,v 1.12 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_fdhookentry.c,v 1.13 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -59,12 +59,11 @@ __fd_hook_entry(
{
D_S(struct FileInfoBlock,fib);
BOOL fib_is_valid = FALSE;
LONG current_position;
LONG new_position;
LONG new_mode;
off_t current_position;
off_t new_position;
int new_mode;
char * buffer = NULL;
int result = -1;
int error = OK;
ENTER();
@ -81,7 +80,7 @@ __fd_hook_entry(
{
SHOWMSG("file is closed");
error = EBADF;
fam->fam_Error = EBADF;
break;
}
@ -100,7 +99,7 @@ __fd_hook_entry(
{
D(("read failed ioerr=%ld",IoErr()));
error = __translate_io_error_to_errno(IoErr());
fam->fam_Error = __translate_io_error_to_errno(IoErr());
break;
}
@ -117,7 +116,7 @@ __fd_hook_entry(
{
SHOWMSG("file is closed");
error = EBADF;
fam->fam_Error = EBADF;
break;
}
@ -151,7 +150,7 @@ __fd_hook_entry(
{
D(("write failed ioerr=%ld",IoErr()));
error = __translate_io_error_to_errno(IoErr());
fam->fam_Error = __translate_io_error_to_errno(IoErr());
break;
}
@ -176,10 +175,13 @@ __fd_hook_entry(
{
SHOWMSG("file is closed");
error = EBADF;
fam->fam_Error = EBADF;
break;
}
/* The following is almost guaranteed not to fail. */
result = 0;
/* Are we disallowed to close this file? */
if(FLAG_IS_SET(fd->fd_Flags,FDF_NO_CLOSE))
{
@ -212,7 +214,11 @@ __fd_hook_entry(
}
if(CANNOT Close(fd->fd_DefaultFile))
error = __translate_io_error_to_errno(IoErr());
{
fam->fam_Error = __translate_io_error_to_errno(IoErr());
result = -1;
}
PROFILE_ON();
@ -348,9 +354,6 @@ __fd_hook_entry(
/* And that's the last for this file descriptor. */
memset(fd,0,sizeof(*fd));
if(error == OK)
result = 0;
break;
case file_action_seek:
@ -364,7 +367,7 @@ __fd_hook_entry(
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)));
D(("seek to offset %ld, new_mode %ld; current position = %ld",fam->fam_Offset,new_mode,Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT)));
if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION))
{
@ -378,7 +381,7 @@ __fd_hook_entry(
if(current_position < 0)
{
error = EBADF;
fam->fam_Error = EBADF;
break;
}
}
@ -389,19 +392,19 @@ __fd_hook_entry(
{
case OFFSET_CURRENT:
new_position += fam->fam_Position;
new_position += fam->fam_Offset;
break;
case OFFSET_BEGINNING:
new_position = fam->fam_Position;
new_position = fam->fam_Offset;
break;
case OFFSET_END:
if(__safe_examine_file_handle(fd->fd_DefaultFile,fib))
{
new_position = fib->fib_Size + fam->fam_Position;
new_position = fib->fib_Size + fam->fam_Offset;
fib_is_valid = TRUE;
}
@ -414,32 +417,32 @@ __fd_hook_entry(
LONG position;
PROFILE_OFF();
position = Seek(fd->fd_DefaultFile,fam->fam_Position,new_mode);
position = Seek(fd->fd_DefaultFile,fam->fam_Offset,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()));
D(("seek failed, fam->fam_Mode=%ld (%ld), offset=%ld, ioerr=%ld",new_mode,fam->fam_Mode,fam->fam_Offset,IoErr()));
error = __translate_io_error_to_errno(IoErr());
fam->fam_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());
fam->fam_Error = __translate_io_error_to_errno(IoErr());
break;
}
if(new_position <= fib->fib_Size)
{
error = __translate_io_error_to_errno(IoErr());
fam->fam_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());
fam->fam_Error = __translate_io_error_to_errno(IoErr());
break;
}
}
@ -449,10 +452,10 @@ __fd_hook_entry(
}
#endif /* UNIX_PATH_SEMANTICS */
}
}
if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION))
fd->fd_Position = new_position;
if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION))
fd->fd_Position = new_position;
}
result = new_position;
@ -477,7 +480,7 @@ __fd_hook_entry(
if(CANNOT SetMode(fd->fd_DefaultFile,mode))
{
error = __translate_io_error_to_errno(IoErr());
fam->fam_Error = __translate_io_error_to_errno(IoErr());
break;
}
@ -487,7 +490,7 @@ __fd_hook_entry(
{
SHOWMSG("can't do anything here");
error = EBADF;
fam->fam_Error = EBADF;
}
PROFILE_ON();
@ -506,7 +509,7 @@ __fd_hook_entry(
{
SHOWMSG("couldn't examine the file");
error = __translate_io_error_to_errno(IoErr());
fam->fam_Error = __translate_io_error_to_errno(IoErr());
break;
}
@ -520,7 +523,7 @@ __fd_hook_entry(
{
SHOWMSG("file is already closed");
error = EBADF;
fam->fam_Error = EBADF;
}
break;
@ -529,7 +532,7 @@ __fd_hook_entry(
SHOWVALUE(fam->fam_Action);
error = EBADF;
fam->fam_Error = EBADF;
break;
}
@ -538,8 +541,6 @@ __fd_hook_entry(
SHOWVALUE(result);
fam->fam_Error = error;
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_filliobreadbuffer.c,v 1.5 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_filliobreadbuffer.c,v 1.6 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -89,11 +89,11 @@ __fill_iob_read_buffer(struct iob * file)
num_bytes_read = (*file->iob_Action)(file,&fam);
if(num_bytes_read < 0)
{
__set_errno(fam.fam_Error);
SET_FLAG(file->iob_Flags,IOBF_ERROR);
D(("got error %ld",fam.fam_Error));
SET_FLAG(file->iob_Flags,IOBF_ERROR);
__set_errno(fam.fam_Error);
goto out;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_flushiobwritebuffer.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_flushiobwritebuffer.c,v 1.5 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -75,15 +75,15 @@ __flush_iob_write_buffer(struct iob * file)
assert( file->iob_Action != NULL );
if((*file->iob_Action)(file,&fam) != file->iob_BufferWriteBytes)
if((*file->iob_Action)(file,&fam) < 0)
{
SHOWMSG("that didn't work");
result = -1;
SET_FLAG(file->iob_Flags,IOBF_ERROR);
__set_errno(fam.fam_Error);
result = -1;
goto out;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fseek.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_fseek.c,v 1.5 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -162,20 +162,21 @@ fseek(FILE *stream, long int offset, int wherefrom)
SHOWPOINTER(&fam);
fam.fam_Action = file_action_seek;
fam.fam_Position = offset;
fam.fam_Mode = wherefrom;
fam.fam_Action = file_action_seek;
fam.fam_Offset = offset;
fam.fam_Mode = wherefrom;
SHOWVALUE(fam.fam_Position);
SHOWVALUE(fam.fam_Offset);
SHOWVALUE(fam.fam_Mode);
assert( file->iob_Action != NULL );
if((*file->iob_Action)(file,&fam) < 0)
{
SET_FLAG(file->iob_Flags,IOBF_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.4 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_ftell.c,v 1.5 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -48,7 +48,8 @@ ftell(FILE *stream)
{
struct iob * file = (struct iob *)stream;
struct file_action_message fam;
long result = -1;
long int result = -1;
int position;
assert( stream != NULL );
@ -83,21 +84,22 @@ ftell(FILE *stream)
SHOWPOINTER(&fam);
fam.fam_Action = file_action_seek;
fam.fam_Position = 0;
fam.fam_Mode = SEEK_CUR;
fam.fam_Action = file_action_seek;
fam.fam_Offset = 0;
fam.fam_Mode = SEEK_CUR;
SHOWVALUE(fam.fam_Position);
SHOWVALUE(fam.fam_Offset);
SHOWVALUE(fam.fam_Mode);
assert( file->iob_Action != NULL );
if((*file->iob_Action)(file,&fam) < 0)
position = (*file->iob_Action)(file,&fam);
if(position < 0)
{
__set_errno(fam.fam_Error);
SET_FLAG(file->iob_Flags,IOBF_ERROR);
__set_errno(fam.fam_Error);
goto out;
}
@ -106,16 +108,18 @@ ftell(FILE *stream)
/* Subtract the number of bytes still in the buffer which have
* not been read before.
*/
result -= __iob_num_unread_bytes(file);
position -= __iob_num_unread_bytes(file);
}
else if (__iob_write_buffer_is_valid(file))
{
/* Add the number of bytes still stored in the buffer which have
* not been written to disk yet.
*/
result += __iob_num_unwritten_bytes(file);
position += __iob_num_unwritten_bytes(file);
}
result = position;
out:
return(result);

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_headers.h,v 1.14 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_headers.h,v 1.15 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -147,10 +147,10 @@ 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 */
int fam_Size; /* How much data to write */
long fam_Position; /* The seek position */
long fam_Mode; /* The seek mode */
long int fam_Offset; /* The seek offset */
int fam_Mode; /* The seek mode */
int fam_Arg; /* Whether or not this file should
be set non-blocking or use

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_sscanf_hook_entry.c,v 1.3 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_sscanf_hook_entry.c,v 1.4 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -87,6 +87,5 @@ __sscanf_hook_entry(
out:
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vasprintf_hook_entry.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_vasprintf_hook_entry.c,v 1.5 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -55,7 +55,6 @@ __vasprintf_hook_entry(
struct file_action_message * fam)
{
int result = -1;
int error = OK;
int num_bytes_left;
int num_bytes;
@ -64,7 +63,7 @@ __vasprintf_hook_entry(
if(fam->fam_Action != file_action_write)
{
error = EBADF;
fam->fam_Error = EBADF;
goto out;
}
@ -80,7 +79,7 @@ __vasprintf_hook_entry(
buffer = __malloc(new_size,string_iob->iob_File,string_iob->iob_Line);
if(buffer == NULL)
{
error = ENOBUFS;
fam->fam_Error = ENOBUFS;
goto out;
}
@ -113,7 +112,5 @@ __vasprintf_hook_entry(
out:
fam->fam_Error = error;
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vsnprintf_hook_entry.c,v 1.5 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_vsnprintf_hook_entry.c,v 1.6 2005-02-20 15:46:52 obarthel Exp $
*
* :ts=4
*
@ -49,13 +49,12 @@ __vsnprintf_hook_entry(
struct file_action_message * fam)
{
int result = -1;
int error = OK;
assert( fam != NULL && string_iob != NULL );
if(fam->fam_Action != file_action_write)
{
error = EBADF;
fam->fam_Error = EBADF;
goto out;
}
@ -83,7 +82,5 @@ __vsnprintf_hook_entry(
out:
fam->fam_Error = error;
return(result);
}