diff --git a/library/changes b/library/changes index a418499..33f18b1 100644 --- a/library/changes +++ b/library/changes @@ -1,3 +1,12 @@ +- The internal 'struct fd' file descriptor table entry data structure + now has a user data field entry. + +- Rearranged the contents of the 'struct fd' file descriptor table entry + data structure in preparation for making it public. Also added a version + field so that user code can handle changes to it gracefully. The default + file is no longer a BCPL pointer to a file handle by default, but + both a BPTR and a socket identifier, wrapped into a union. + - Added experimental tilde expansion in Unix path names. This still needs some more work. diff --git a/library/stdio_duplicate_fd.c b/library/stdio_duplicate_fd.c index 28c42c5..b37f406 100644 --- a/library/stdio_duplicate_fd.c +++ b/library/stdio_duplicate_fd.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_duplicate_fd.c,v 1.5 2006-01-08 12:04:24 obarthel Exp $ + * $Id: stdio_duplicate_fd.c,v 1.6 2006-10-10 13:39:26 obarthel Exp $ * * :ts=4 * @@ -55,8 +55,8 @@ __duplicate_fd(struct fd * duplicate_fd,struct fd * original_fd) duplicate_fd->fd_Original = original_fd; /* Add the duplicate at the beginning of the list. */ - duplicate_fd->fd_NextLink = duplicate_fd->fd_Original->fd_NextLink; - duplicate_fd->fd_Original->fd_NextLink = duplicate_fd; + duplicate_fd->fd_NextAlias = duplicate_fd->fd_Original->fd_NextAlias; + duplicate_fd->fd_Original->fd_NextAlias = duplicate_fd; __fd_unlock(original_fd); } diff --git a/library/stdio_headers.h b/library/stdio_headers.h index 947a08e..b6190b0 100644 --- a/library/stdio_headers.h +++ b/library/stdio_headers.h @@ -1,5 +1,5 @@ /* - * $Id: stdio_headers.h,v 1.27 2006-09-25 14:05:31 obarthel Exp $ + * $Id: stdio_headers.h,v 1.28 2006-10-10 13:39:26 obarthel Exp $ * * :ts=4 * @@ -365,6 +365,7 @@ struct iob standard input/output/error streams. */ #define FDF_TERMIOS (1UL<<13) /* File is under termios control. FDF_IS_INTERACTIVE should also be set. */ + /****************************************************************************/ /* The file action function for unbuffered files. */ @@ -379,25 +380,39 @@ typedef void (*fd_cleanup_t)(struct fd * fd); struct fd { - 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 */ - ULONG fd_Position; /* Cached file position (seek offset). */ - fd_cleanup_t fd_Cleanup; /* Cleanup function, if any. */ + int fd_Version; /* Version number of this definition + of the 'fd' data structure. */ + file_action_fd_t fd_Action; /* Function to invoke to perform actions */ + void * fd_UserData; /* To be used by custom file action + functions */ + ULONG fd_Flags; /* File properties */ - struct SignalSemaphore * fd_Lock; /* For thread locking */ + union + { + BPTR fdu_File; /* A dos.library file handle */ + LONG fdu_Socket; /* A socket identifier */ + } fdu_Default; - void * fd_Aux; /* Auxilliary data for "special" files, - e.g. termios support. */ + struct SignalSemaphore * fd_Lock; /* For thread locking */ + ULONG fd_Position; /* Cached file position (seek offset). */ + fd_cleanup_t fd_Cleanup; /* Cleanup function, if any. */ + + struct fd * fd_Original; /* NULL if this is not a dup()ed file + descriptor; points to original + descriptor if non-NULL */ + struct fd * fd_NextAlias; /* Points to next duplicate of this + file descriptor; NULL for none */ + void * fd_Aux; /* Auxilliary data for "special" files, + e.g. termios support. */ }; /****************************************************************************/ +#define fd_DefaultFile fdu_Default.fdu_File +#define fd_Socket fdu_Default.fdu_Socket + +/****************************************************************************/ + /* Files and directories to be unlinked when the program exits. */ struct UnlinkNode { @@ -481,7 +496,7 @@ extern BOOL NOCOMMON __no_standard_io; /****************************************************************************/ #define __fd_is_aliased(fd) \ - ((fd)->fd_Original != NULL || (fd)->fd_NextLink != NULL) + ((fd)->fd_Original != NULL || (fd)->fd_NextAlias != NULL) /****************************************************************************/ diff --git a/library/stdio_initializefd.c b/library/stdio_initializefd.c index 0ab9f84..50585c5 100644 --- a/library/stdio_initializefd.c +++ b/library/stdio_initializefd.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_initializefd.c,v 1.6 2006-01-08 12:04:24 obarthel Exp $ + * $Id: stdio_initializefd.c,v 1.7 2006-10-10 13:39:26 obarthel Exp $ * * :ts=4 * @@ -49,6 +49,7 @@ __initialize_fd( memset(fd,0,sizeof(*fd)); + fd->fd_Version = 1; fd->fd_DefaultFile = default_file; fd->fd_Flags = flags; fd->fd_Action = action_function; diff --git a/library/stdio_record_locking.c b/library/stdio_record_locking.c index 0f7d623..761add9 100644 --- a/library/stdio_record_locking.c +++ b/library/stdio_record_locking.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_record_locking.c,v 1.17 2006-09-25 14:51:15 obarthel Exp $ + * $Id: stdio_record_locking.c,v 1.18 2006-10-10 13:39:26 obarthel Exp $ * * :ts=4 * @@ -342,7 +342,7 @@ remove_locked_region_node(struct FileLockSemaphore * fls,struct fd * fd,LONG sta { CLEAR_FLAG(fd->fd_Flags,FDF_IS_LOCKED); } - while((fd = fd->fd_NextLink) != NULL); + while((fd = fd->fd_NextAlias) != NULL); } } } @@ -725,7 +725,7 @@ cleanup_locked_records(struct fd * fd) { CLEAR_FLAG(fd->fd_Flags,FDF_IS_LOCKED); } - while((fd = fd->fd_NextLink) != NULL); + while((fd = fd->fd_NextAlias) != NULL); } release_file_lock_semaphore(fls); @@ -1086,7 +1086,7 @@ __handle_record_locking(int cmd,struct flock * l,struct fd * fd,int * error_ptr) { SET_FLAG(fd->fd_Flags,FDF_IS_LOCKED); } - while((fd = fd->fd_NextLink) != NULL); + while((fd = fd->fd_NextAlias) != NULL); } else if (cmd == F_SETLK) { @@ -1164,7 +1164,7 @@ __handle_record_locking(int cmd,struct flock * l,struct fd * fd,int * error_ptr) { SET_FLAG(fd->fd_Flags,FDF_IS_LOCKED); } - while((fd = fd->fd_NextLink) != NULL); + while((fd = fd->fd_NextAlias) != NULL); } else if (cmd == F_GETLK) { diff --git a/library/stdio_remove_fd_alias.c b/library/stdio_remove_fd_alias.c index 0ac89b7..0de2c14 100644 --- a/library/stdio_remove_fd_alias.c +++ b/library/stdio_remove_fd_alias.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_remove_fd_alias.c,v 1.4 2006-01-08 12:04:25 obarthel Exp $ + * $Id: stdio_remove_fd_alias.c,v 1.5 2006-10-10 13:39:26 obarthel Exp $ * * :ts=4 * @@ -54,36 +54,36 @@ __remove_fd_alias(struct fd * fd) /* Remove this alias from the list. */ for(list_fd = fd->fd_Original ; list_fd != NULL ; - list_fd = list_fd->fd_NextLink) + list_fd = list_fd->fd_NextAlias) { - if(list_fd->fd_NextLink == fd) + if(list_fd->fd_NextAlias == fd) { - list_fd->fd_NextLink = fd->fd_NextLink; + list_fd->fd_NextAlias = fd->fd_NextAlias; break; } } } - else if (fd->fd_NextLink != NULL) /* this one has aliases attached; it is the 'original' resource */ + else if (fd->fd_NextAlias != NULL) /* this one has aliases attached; it is the 'original' resource */ { struct fd * first_alias; struct fd * next_alias; struct fd * list_fd; /* The first link now becomes the original resource */ - first_alias = fd->fd_NextLink; - next_alias = first_alias->fd_NextLink; + first_alias = fd->fd_NextAlias; + next_alias = first_alias->fd_NextAlias; /* Structure copy... */ (*first_alias) = (*fd); /* Fix up the linkage. */ - first_alias->fd_NextLink = next_alias; + first_alias->fd_NextAlias = next_alias; first_alias->fd_Original = NULL; /* The resources are migrated to the first link. */ for(list_fd = next_alias ; list_fd != NULL ; - list_fd = list_fd->fd_NextLink) + list_fd = list_fd->fd_NextAlias) { list_fd->fd_Original = first_alias; }