From 5191ee5660b337f3766568432d9c86914c8070b3 Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Sun, 9 Jan 2005 15:58:02 +0000 Subject: [PATCH] - The V37/V40 compatibility code is no longer built for the AmigaOS4 version of the library. - Switched over the last use of DeviceProc() to GetDeviceProc(), etc. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14798 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/changes | 9 +++ library/dirent_readdir.c | 13 ++-- library/fcntl_open.c | 140 +++++++++++++++++++++++------------- library/stdio_fdhookentry.c | 109 ++++++++++++++++++---------- library/stdio_init_exit.c | 10 +-- library/stdlib_malloc.c | 12 +++- library/stdlib_startup.c | 18 ++--- library/unistd_chown.c | 84 +++++++++++----------- 8 files changed, 241 insertions(+), 154 deletions(-) diff --git a/library/changes b/library/changes index 19c2da1..e380727 100644 --- a/library/changes +++ b/library/changes @@ -31,6 +31,15 @@ - Made the macros more robust. +- Removed the "NIL:" file handle tests preceding the Open("CONSOLE:",..) + calls. As of Kickstart 2.x and beyond these are no longer a source of + trouble. + +- The V37/V40 compatibility code is no longer built for the AmigaOS4 + version of the library. + +- Switched over the last use of DeviceProc() to GetDeviceProc(), etc. + c.lib 1.185 (2.1.2005) diff --git a/library/dirent_readdir.c b/library/dirent_readdir.c index 0821d88..9dbc0d8 100644 --- a/library/dirent_readdir.c +++ b/library/dirent_readdir.c @@ -1,5 +1,5 @@ /* - * $Id: dirent_readdir.c,v 1.4 2005-01-02 09:07:07 obarthel Exp $ + * $Id: dirent_readdir.c,v 1.5 2005-01-09 15:58:02 obarthel Exp $ * * :ts=4 * @@ -89,7 +89,6 @@ readdir(DIR * directory_pointer) D_S(struct FileInfoBlock,fib); D_S(struct bcpl_name,bcpl_name); UBYTE * name = bcpl_name->name; - struct MsgPort * port; BPTR dir_lock; assert( (((ULONG)name) & 3) == 0 ); @@ -103,10 +102,12 @@ readdir(DIR * directory_pointer) { if(IsFileSystem(dh->dh_VolumeNode->ln_Name)) { - port = DeviceProc(dh->dh_VolumeNode->ln_Name); - if(port != NULL) + struct DevProc * dvp; + + dvp = GetDeviceProc(dh->dh_VolumeNode->ln_Name,NULL); + if(dvp != NULL) { - dir_lock = DoPkt(port,ACTION_LOCATE_OBJECT,ZERO,MKBADDR(name),SHARED_LOCK, 0,0); + dir_lock = DoPkt(dvp->dvp_Port,ACTION_LOCATE_OBJECT,ZERO,MKBADDR(name),SHARED_LOCK, 0,0); if(dir_lock != ZERO) { if(Examine(dir_lock,fib)) @@ -122,6 +123,8 @@ readdir(DIR * directory_pointer) UnLock(dir_lock); } + + FreeDeviceProc(dvp); } } diff --git a/library/fcntl_open.c b/library/fcntl_open.c index b56d883..b38c81e 100644 --- a/library/fcntl_open.c +++ b/library/fcntl_open.c @@ -1,5 +1,5 @@ /* - * $Id: fcntl_open.c,v 1.5 2005-01-09 09:54:33 obarthel Exp $ + * $Id: fcntl_open.c,v 1.6 2005-01-09 15:58:02 obarthel Exp $ * * :ts=4 * @@ -53,6 +53,69 @@ /****************************************************************************/ +/* This is used in place of ExamineFH() in order to work around a bug in + dos.library V40 and below: a "NIL:" file handle will crash the + ExamineFH() function. */ +static LONG +safe_examine_file_handle(BPTR file_handle,struct FileInfoBlock *fib) +{ + LONG result = DOSFALSE; + + assert( fib != NULL ); + + #ifndef __amigaos4__ + { + struct FileHandle * fh = (struct FileHandle *)BADDR(file_handle); + + if(fh == NULL || fh->fh_Type == NULL) + { + SetIoErr(ERROR_OBJECT_WRONG_TYPE); + goto out; + } + } + #endif /* __amigaos4__ */ + + PROFILE_OFF(); + result = ExamineFH(file_handle,fib); + PROFILE_ON(); + + out: + + return(result); +} + +/* Same thing as above, but for ChangeMode(), which suffers from + the same problem. */ +static LONG +safe_change_mode(LONG type,BPTR file_handle,LONG mode) +{ + LONG result = DOSFALSE; + + #ifndef __amigaos4__ + { + struct FileHandle * fh = (struct FileHandle *)BADDR(file_handle); + + assert( type == CHANGE_FH ); + + if(fh == NULL || fh->fh_Type == NULL) + { + SetIoErr(ERROR_OBJECT_WRONG_TYPE); + goto out; + } + } + #endif /* __amigaos4__ */ + + PROFILE_OFF(); + result = ChangeMode(type,file_handle,mode); + PROFILE_ON(); + + out: + + return(result); +} + +/****************************************************************************/ + int open(const char *path_name, int open_flag, ... /* mode_t mode */ ) { @@ -64,7 +127,6 @@ open(const char *path_name, int open_flag, ... /* mode_t mode */ ) LONG is_file_system = FALSE; LONG open_mode; BPTR lock = ZERO; - struct FileHandle * file_handle; BPTR handle = ZERO; BOOL create_new_file = FALSE; LONG is_interactive; @@ -294,47 +356,33 @@ open(const char *path_name, int open_flag, ... /* mode_t mode */ ) goto out; } - file_handle = BADDR(handle); - - /* NOTE: workaround for a bug in dos.library V40 and below which will - * crash the caller if the file handle refers to "NIL:". - */ - if(file_handle->fh_Type != NULL) + if(safe_examine_file_handle(handle,fib) != DOSFALSE) { - LONG status; + BOOL operation_permitted = TRUE; - PROFILE_OFF(); - status = ExamineFH(handle,fib); - PROFILE_ON(); - - if(status != DOSFALSE) + /* Check if the file is readable. */ + if(FLAG_IS_SET(fib->fib_Protection,FIBF_READ)) { - BOOL operation_permitted = TRUE; - - /* Check if the file is readable. */ - if(FLAG_IS_SET(fib->fib_Protection,FIBF_READ)) + if(access_mode == O_RDONLY || + access_mode == O_RDWR) { - if(access_mode == O_RDONLY || - access_mode == O_RDWR) - { - operation_permitted = FALSE; - } + operation_permitted = FALSE; } + } - /* Check if the file can be written to. */ - if(FLAG_IS_SET(fib->fib_Protection,FIBF_WRITE)) - { - if(access_mode == O_WRONLY) - operation_permitted = FALSE; - } + /* Check if the file can be written to. */ + if(FLAG_IS_SET(fib->fib_Protection,FIBF_WRITE)) + { + if(access_mode == O_WRONLY) + operation_permitted = FALSE; + } - if(NOT operation_permitted) - { - SHOWMSG("this object must not be opened"); + if(NOT operation_permitted) + { + SHOWMSG("this object must not be opened"); - errno = EACCES; - goto out; - } + errno = EACCES; + goto out; } } @@ -365,7 +413,7 @@ open(const char *path_name, int open_flag, ... /* mode_t mode */ ) len = 0; - for(i = 0 ; i < (int)strlen(path_name) ; i++) + for(i = 0 ; path_name[i] != '\0' ; i++) { if(path_name[i] == ':') { @@ -400,21 +448,11 @@ open(const char *path_name, int open_flag, ... /* mode_t mode */ ) if(is_file_system) { - /* NOTE: workaround for a bug in dos.library V40 and below which will - * crash the caller if the file handle refers to "NIL:". - */ - if(file_handle->fh_Type != NULL) - { - /* We opened the file in exclusive access mode. Switch it back - into shared access mode so that its contents can be read - while it's still open. */ - if(open_mode == MODE_NEWFILE) - { - PROFILE_OFF(); - ChangeMode(CHANGE_FH,handle,SHARED_LOCK); - PROFILE_ON(); - } - } + /* We opened the file in exclusive access mode. Switch it back + into shared access mode so that its contents can be read + while it's still open. */ + if(open_mode == MODE_NEWFILE) + safe_change_mode(CHANGE_FH,handle,SHARED_LOCK); /* We should be able to seek in this file. */ SET_FLAG(fd->fd_Flags,FDF_CACHE_POSITION); diff --git a/library/stdio_fdhookentry.c b/library/stdio_fdhookentry.c index 6e566a8..2d796b6 100644 --- a/library/stdio_fdhookentry.c +++ b/library/stdio_fdhookentry.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_fdhookentry.c,v 1.5 2005-01-02 09:07:08 obarthel Exp $ + * $Id: stdio_fdhookentry.c,v 1.6 2005-01-09 15:58:02 obarthel Exp $ * * :ts=4 * @@ -59,16 +59,21 @@ static LONG safe_examine_file_handle(BPTR file_handle,struct FileInfoBlock *fib) { - struct FileHandle * fh = (struct FileHandle *)BADDR(file_handle); LONG result = DOSFALSE; assert( fib != NULL ); - if(fh == NULL || fh->fh_Type == NULL) + #ifndef __amigaos4__ { - SetIoErr(ERROR_OBJECT_WRONG_TYPE); - goto out; + struct FileHandle * fh = (struct FileHandle *)BADDR(file_handle); + + if(fh == NULL || fh->fh_Type == NULL) + { + SetIoErr(ERROR_OBJECT_WRONG_TYPE); + goto out; + } } + #endif /* __amigaos4__ */ PROFILE_OFF(); result = ExamineFH(file_handle,fib); @@ -85,14 +90,19 @@ safe_examine_file_handle(BPTR file_handle,struct FileInfoBlock *fib) static BPTR safe_parent_of_file_handle(BPTR file_handle) { - struct FileHandle * fh = (struct FileHandle *)BADDR(file_handle); BPTR result = ZERO; - if(fh == NULL || fh->fh_Type == NULL) + #ifndef __amigaos4__ { - SetIoErr(ERROR_OBJECT_WRONG_TYPE); - goto out; + struct FileHandle * fh = (struct FileHandle *)BADDR(file_handle); + + if(fh == NULL || fh->fh_Type == NULL) + { + SetIoErr(ERROR_OBJECT_WRONG_TYPE); + goto out; + } } + #endif /* __amigaos4__ */ PROFILE_OFF(); result = ParentOfFH(file_handle); @@ -244,19 +254,27 @@ obtain_file_lock_semaphore(BOOL shared) if(shared) { - if(((struct Library *)SysBase)->lib_Version >= 39) + #if defined(__amigaos4__) { ObtainSemaphoreShared((struct SignalSemaphore *)FileLockSemaphore); } - else + #else { - /* Workaround for shared semaphore nesting problem. */ - if(CANNOT AttemptSemaphoreShared((struct SignalSemaphore *)FileLockSemaphore)) + if(((struct Library *)SysBase)->lib_Version >= 39) { - if(CANNOT AttemptSemaphore((struct SignalSemaphore *)FileLockSemaphore)) - ObtainSemaphoreShared((struct SignalSemaphore *)FileLockSemaphore); + ObtainSemaphoreShared((struct SignalSemaphore *)FileLockSemaphore); + } + else + { + /* Workaround for shared semaphore nesting problem. */ + if(CANNOT AttemptSemaphoreShared((struct SignalSemaphore *)FileLockSemaphore)) + { + if(CANNOT AttemptSemaphore((struct SignalSemaphore *)FileLockSemaphore)) + ObtainSemaphoreShared((struct SignalSemaphore *)FileLockSemaphore); + } } } + #endif /* __amigaos4__ */ } else { @@ -1885,10 +1903,8 @@ __fd_hook_entry( old_current_dir = CurrentDir(parent_dir); - if(((struct Library *)DOSBase)->lib_Version >= 39) + #if defined(__amigaos4__) { - SHOWMSG("changing owner"); - if(SetOwner(fib->fib_FileName,(LONG)((((ULONG)message->owner) << 16) | message->group))) { result = 0; @@ -1900,36 +1916,55 @@ __fd_hook_entry( __translate_io_error_to_errno(IoErr(),&error); } } - else + #else { - D_S(struct bcpl_name,new_name); - struct DevProc * dvp; - unsigned int len; - - SHOWMSG("have to do this manually..."); - - len = strlen(fib->fib_FileName); - - assert( len < sizeof(new_name->name) ); - - dvp = GetDeviceProc(fib->fib_FileName,NULL); - if(dvp != NULL) + if(((struct Library *)DOSBase)->lib_Version >= 39) { - new_name->name[0] = len; - memmove(&new_name->name[1],fib->fib_FileName,len); + SHOWMSG("changing owner"); - if(DoPkt(dvp->dvp_Port,ACTION_SET_OWNER,dvp->dvp_Lock,MKBADDR(new_name),(LONG)((((ULONG)message->owner) << 16) | message->group),0,0)) + if(SetOwner(fib->fib_FileName,(LONG)((((ULONG)message->owner) << 16) | message->group))) + { result = 0; + } else - __translate_io_error_to_errno(IoErr(),&error); + { + SHOWMSG("that didn't work"); - FreeDeviceProc(dvp); + __translate_io_error_to_errno(IoErr(),&error); + } } else { - __translate_io_error_to_errno(IoErr(),&error); + D_S(struct bcpl_name,new_name); + struct DevProc * dvp; + unsigned int len; + + SHOWMSG("have to do this manually..."); + + len = strlen(fib->fib_FileName); + + assert( len < sizeof(new_name->name) ); + + dvp = GetDeviceProc(fib->fib_FileName,NULL); + if(dvp != NULL) + { + new_name->name[0] = len; + memmove(&new_name->name[1],fib->fib_FileName,len); + + if(DoPkt(dvp->dvp_Port,ACTION_SET_OWNER,dvp->dvp_Lock,MKBADDR(new_name),(LONG)((((ULONG)message->owner) << 16) | message->group),0,0)) + result = 0; + else + __translate_io_error_to_errno(IoErr(),&error); + + FreeDeviceProc(dvp); + } + else + { + __translate_io_error_to_errno(IoErr(),&error); + } } } + #endif /* __amigaos4__ */ CurrentDir(old_current_dir); diff --git a/library/stdio_init_exit.c b/library/stdio_init_exit.c index 855a26f..a2eafe2 100644 --- a/library/stdio_init_exit.c +++ b/library/stdio_init_exit.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_init_exit.c,v 1.10 2005-01-09 10:43:40 obarthel Exp $ + * $Id: stdio_init_exit.c,v 1.11 2005-01-09 15:58:02 obarthel Exp $ * * :ts=4 * @@ -242,13 +242,9 @@ __stdio_init(void) SET_FLAG(__fd[STDERR_FILENO]->fd_Flags,FDF_NO_CLOSE); } - else if (__fd[STDOUT_FILENO]->fd_DefaultFile != ZERO) + else { - struct FileHandle * fh = (struct FileHandle *)BADDR(__fd[STDOUT_FILENO]->fd_DefaultFile); - - /* Careful, this could be "NIL:". */ - if(fh->fh_Type != NULL) - __fd[STDERR_FILENO]->fd_DefaultFile = Open("CONSOLE:",MODE_NEWFILE); + __fd[STDERR_FILENO]->fd_DefaultFile = Open("CONSOLE:",MODE_NEWFILE); } } diff --git a/library/stdlib_malloc.c b/library/stdlib_malloc.c index 1a2e084..ad6ca3f 100644 --- a/library/stdlib_malloc.c +++ b/library/stdlib_malloc.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_malloc.c,v 1.5 2005-01-02 09:07:18 obarthel Exp $ + * $Id: stdlib_malloc.c,v 1.6 2005-01-09 15:58:02 obarthel Exp $ * * :ts=4 * @@ -275,8 +275,16 @@ __memory_init(void) NewList((struct List *)&__memory_list); - if(((struct Library *)SysBase)->lib_Version >= 39) + #if defined(__amigaos4__) + { __memory_pool = CreatePool(MEMF_ANY,(ULONG)__default_pool_size,(ULONG)__default_puddle_size); + } + #else + { + if(((struct Library *)SysBase)->lib_Version >= 39) + __memory_pool = CreatePool(MEMF_ANY,(ULONG)__default_pool_size,(ULONG)__default_puddle_size); + } + #endif /* __amigaos4__ */ LEAVE(); } diff --git a/library/stdlib_startup.c b/library/stdlib_startup.c index b39fce4..7a93cf0 100644 --- a/library/stdlib_startup.c +++ b/library/stdlib_startup.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_startup.c,v 1.5 2005-01-02 09:07:19 obarthel Exp $ + * $Id: stdlib_startup.c,v 1.6 2005-01-09 15:58:02 obarthel Exp $ * * :ts=4 * @@ -387,17 +387,13 @@ __startup_init(void) { struct FileHandle * fh = BADDR(input); - /* Careful: "NIL:" will have a NULL MsgPort in the file handle. */ - if(fh->fh_Type != NULL) - { - old_console_task = SetConsoleTask(fh->fh_Type); + old_console_task = SetConsoleTask(fh->fh_Type); - output = Open("CONSOLE:",MODE_NEWFILE); - if(output != ZERO) - restore_console_task = TRUE; - else - SetConsoleTask((struct MsgPort *)old_console_task); - } + output = Open("CONSOLE:",MODE_NEWFILE); + if(output != ZERO) + restore_console_task = TRUE; + else + SetConsoleTask((struct MsgPort *)old_console_task); } if(output == ZERO) diff --git a/library/unistd_chown.c b/library/unistd_chown.c index f8200f2..abb011c 100644 --- a/library/unistd_chown.c +++ b/library/unistd_chown.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_chown.c,v 1.3 2005-01-02 09:07:19 obarthel Exp $ + * $Id: unistd_chown.c,v 1.4 2005-01-09 15:58:02 obarthel Exp $ * * :ts=4 * @@ -106,57 +106,59 @@ chown(const char * path_name, uid_t owner, gid_t group) D(("changing owner of '%s'",path_name)); - if(((struct Library *)DOSBase)->lib_Version >= 39) + #if defined(__amigaos4__) { PROFILE_OFF(); status = SetOwner((STRPTR)path_name,(LONG)((((ULONG)owner) << 16) | group)); PROFILE_ON(); - - if(status == DOSFALSE) - { - __translate_io_error_to_errno(IoErr(),&errno); - goto out; - } - - result = 0; } - else + #else { - D_S(struct bcpl_name,new_name); - size_t len; - - len = strlen(path_name); - if(len >= sizeof(new_name->name)) + if(((struct Library *)DOSBase)->lib_Version >= 39) { - errno = ENAMETOOLONG; - goto out; + PROFILE_OFF(); + status = SetOwner((STRPTR)path_name,(LONG)((((ULONG)owner) << 16) | group)); + PROFILE_ON(); } - - PROFILE_OFF(); - dvp = GetDeviceProc((STRPTR)path_name,NULL); - PROFILE_ON(); - - if(dvp == NULL) + else { - __translate_io_error_to_errno(IoErr(),&errno); - goto out; + D_S(struct bcpl_name,new_name); + size_t len; + + len = strlen(path_name); + if(len >= sizeof(new_name->name)) + { + errno = ENAMETOOLONG; + goto out; + } + + PROFILE_OFF(); + dvp = GetDeviceProc((STRPTR)path_name,NULL); + PROFILE_ON(); + + if(dvp == NULL) + { + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + new_name->name[0] = len; + memmove(&new_name->name[1],path_name,len); + + PROFILE_OFF(); + status = DoPkt(dvp->dvp_Port,ACTION_SET_OWNER,dvp->dvp_Lock,MKBADDR(new_name),(LONG)((((ULONG)owner) << 16) | group),0,0); + PROFILE_ON(); } - - new_name->name[0] = len; - memmove(&new_name->name[1],path_name,len); - - PROFILE_OFF(); - status = DoPkt(dvp->dvp_Port,ACTION_SET_OWNER,dvp->dvp_Lock,MKBADDR(new_name),(LONG)((((ULONG)owner) << 16) | group),0,0); - PROFILE_ON(); - - if(status == DOSFALSE) - { - __translate_io_error_to_errno(IoErr(),&errno); - goto out; - } - - result = 0; } + #endif /* __amigaos4__ */ + + if(status == DOSFALSE) + { + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + result = 0; out: