From 3548d3cf7e40c5b8d47d71d65665bf54d6a0a1d7 Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Thu, 3 Feb 2005 12:14:55 +0000 Subject: [PATCH] - We now allocate the AnchorPath used in the unistd_wildcard_expand.c code. Also, the contents of the AnchorPath structure are no longer modified between calls. MatchEnd() has to be sufficient. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14822 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/changes | 5 ++ library/dirent_closedir.c | 10 ++-- library/dirent_headers.h | 5 +- library/dirent_opendir.c | 20 ++++---- library/dirent_readdir.c | 6 +-- library/stdlib_headers.h | 6 ++- library/unistd_wildcard_expand.c | 81 ++++++++++++++++++++------------ 7 files changed, 87 insertions(+), 46 deletions(-) diff --git a/library/changes b/library/changes index 53ecbaa..67c440b 100644 --- a/library/changes +++ b/library/changes @@ -14,6 +14,11 @@ modified unless the library is built with the "CHECK_FOR_NULL_POINTERS" option. +- We now allocate the AnchorPath used in the unistd_wildcard_expand.c + code. Also, the contents of the AnchorPath structure are no longer + modified between calls. MatchEnd() has to be sufficient. + + c.lib 1.187 (29.1.2005) diff --git a/library/dirent_closedir.c b/library/dirent_closedir.c index 61a3025..02fc063 100644 --- a/library/dirent_closedir.c +++ b/library/dirent_closedir.c @@ -1,5 +1,5 @@ /* - * $Id: dirent_closedir.c,v 1.3 2005-01-02 09:07:07 obarthel Exp $ + * $Id: dirent_closedir.c,v 1.4 2005-02-03 12:14:55 obarthel Exp $ * * :ts=4 * @@ -94,8 +94,12 @@ closedir(DIR * directory_pointer) Remove((struct Node *)dh); - while((node = RemHead(&dh->dh_VolumeList)) != NULL) - free(node); + #if defined(UNIX_PATH_SEMANTICS) + { + while((node = RemHead((struct List *)&dh->dh_VolumeList)) != NULL) + free(node); + } + #endif /* UNIX_PATH_SEMANTICS */ PROFILE_OFF(); UnLock(dh->dh_DirLock); diff --git a/library/dirent_headers.h b/library/dirent_headers.h index e6f9ca6..e2a5014 100644 --- a/library/dirent_headers.h +++ b/library/dirent_headers.h @@ -1,5 +1,5 @@ /* - * $Id: dirent_headers.h,v 1.3 2005-01-02 09:07:07 obarthel Exp $ + * $Id: dirent_headers.h,v 1.4 2005-02-03 12:14:55 obarthel Exp $ * * :ts=4 * @@ -54,9 +54,10 @@ struct DirectoryHandle BPTR dh_DirLock; struct FileInfoBlock dh_FileInfo; struct dirent dh_DirectoryEntry; + int dh_Position; struct Node * dh_VolumeNode; - struct List dh_VolumeList; + struct MinList dh_VolumeList; BOOL dh_ScanVolumeList; }; diff --git a/library/dirent_opendir.c b/library/dirent_opendir.c index 4b7cf0c..63bdeea 100644 --- a/library/dirent_opendir.c +++ b/library/dirent_opendir.c @@ -1,5 +1,5 @@ /* - * $Id: dirent_opendir.c,v 1.3 2005-01-02 09:07:07 obarthel Exp $ + * $Id: dirent_opendir.c,v 1.4 2005-02-03 12:14:55 obarthel Exp $ * * :ts=4 * @@ -121,10 +121,10 @@ opendir(const char * path_name) memset(dh,0,sizeof(*dh)); - NewList(&dh->dh_VolumeList); - #if defined(UNIX_PATH_SEMANTICS) { + NewList((struct List *)&dh->dh_VolumeList); + if(__unix_path_semantics) { if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) @@ -172,7 +172,7 @@ opendir(const char * path_name) /* Check if the name is already on the list. Mind you, this is not the most sophisticated algorithm but then the number of volumes should be small. */ - if(find_by_name(&dh->dh_VolumeList,node->ln_Name) != NULL) + if(find_by_name((struct List *)&dh->dh_VolumeList,node->ln_Name) != NULL) { free(node); continue; @@ -180,14 +180,14 @@ opendir(const char * path_name) D(("adding '%s'",node->ln_Name)); - AddTail(&dh->dh_VolumeList,node); + AddTail((struct List *)&dh->dh_VolumeList,node); } } UnLockDosList(LDF_VOLUMES|LDF_READ); /* Bail out if we cannot present anything. */ - if(IsListEmpty(&dh->dh_VolumeList)) + if(IsListEmpty((struct List *)&dh->dh_VolumeList)) { errno = ENOMEM; goto out; @@ -254,8 +254,12 @@ opendir(const char * path_name) { SHOWMSG("ouch. cleaning up"); - while((node = RemHead(&dh->dh_VolumeList)) != NULL) - free(node); + #if defined(UNIX_PATH_SEMANTICS) + { + while((node = RemHead((struct List *)&dh->dh_VolumeList)) != NULL) + free(node); + } + #endif /* UNIX_PATH_SEMANTICS */ PROFILE_OFF(); UnLock(dh->dh_DirLock); diff --git a/library/dirent_readdir.c b/library/dirent_readdir.c index 9dbc0d8..53924b0 100644 --- a/library/dirent_readdir.c +++ b/library/dirent_readdir.c @@ -1,5 +1,5 @@ /* - * $Id: dirent_readdir.c,v 1.5 2005-01-09 15:58:02 obarthel Exp $ + * $Id: dirent_readdir.c,v 1.6 2005-02-03 12:14:55 obarthel Exp $ * * :ts=4 * @@ -93,8 +93,8 @@ readdir(DIR * directory_pointer) assert( (((ULONG)name) & 3) == 0 ); - if(dh->dh_VolumeNode == NULL && NOT IsListEmpty(&dh->dh_VolumeList)) - dh->dh_VolumeNode = dh->dh_VolumeList.lh_Head; + if(dh->dh_VolumeNode == NULL && NOT IsListEmpty((struct List *)&dh->dh_VolumeList)) + dh->dh_VolumeNode = (struct Node *)dh->dh_VolumeList.mlh_Head; strcpy(name,"\1:"); /* BSTR for ":" */ diff --git a/library/stdlib_headers.h b/library/stdlib_headers.h index 4777d61..0e01d3a 100644 --- a/library/stdlib_headers.h +++ b/library/stdlib_headers.h @@ -1,5 +1,5 @@ /* - * $Id: stdlib_headers.h,v 1.6 2005-01-02 09:07:18 obarthel Exp $ + * $Id: stdlib_headers.h,v 1.7 2005-02-03 12:14:55 obarthel Exp $ * * :ts=4 * @@ -42,7 +42,11 @@ /****************************************************************************/ /* This enables the legacy compatible 'struct AnchorPathOld'. */ +#ifndef __amigaos4__ #define USE_OLD_ANCHORPATH +#endif /* USE_OLD_ANCHORPATH */ + +/****************************************************************************/ #if (INCLUDE_VERSION >= 50) #include diff --git a/library/unistd_wildcard_expand.c b/library/unistd_wildcard_expand.c index 12b6ab2..b3d37f7 100644 --- a/library/unistd_wildcard_expand.c +++ b/library/unistd_wildcard_expand.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_wildcard_expand.c,v 1.4 2005-01-02 09:07:19 obarthel Exp $ + * $Id: unistd_wildcard_expand.c,v 1.5 2005-02-03 12:14:55 obarthel Exp $ * * :ts=4 * @@ -81,6 +81,13 @@ CLIB_DESTRUCTOR(__wildcard_expand_exit) if(anchor != NULL) { MatchEnd(anchor); + + #if defined(__amigaos4__) + { + FreeDosObject(DOS_ANCHORPATH,anchor); + } + #endif /* __amigaos4__ */ + anchor = NULL; } @@ -136,23 +143,45 @@ __wildcard_expand_init(void) argc = __argc; argv = __argv; - /* We need some extra room in this data structure as the buffer - * will be used to check if a string contains a pattern. - */ - ap = malloc(sizeof(*ap) + 2 * MAXPATHLEN); - if(ap == NULL) + #if defined(__amigaos4__) { - error = ENOMEM; - goto out; + ap = AllocDosObjectTags(DOS_ANCHORPATH, + ADO_Strlen, 2 * MAXPATHLEN, + ADO_Mask, (__check_abort_enabled) ? SIGBREAKF_CTRL_C : 0, + TAG_END); + + if(ap == NULL) + { + error = ENOMEM; + goto out; + } } + #else + { + /* We need some extra room in this data structure as the buffer + will be used to check if a string contains a pattern. */ + ap = malloc(sizeof(*ap) + 2 * MAXPATHLEN); + if(ap == NULL) + { + error = ENOMEM; + goto out; + } - /* This has to be long-word aligned. */ - assert( (((ULONG)ap) & 3) == 0 ); + /* This has to be long-word aligned. */ + assert( (((ULONG)ap) & 3) == 0 ); + memset(ap,0,sizeof(*ap)); + + ap->ap_Strlen = MAXPATHLEN; + + if(__check_abort_enabled) + ap->ap_BreakBits = SIGBREAKF_CTRL_C; + } + #endif /* __amigaos4__ */ + + /* This may have to be cleaned up later. */ anchor = ap; - memset(ap,0,sizeof(*ap)); - /* The argument list will go in here. */ NewList((struct List *)&argument_list); argument_list_size = 0; @@ -169,13 +198,6 @@ __wildcard_expand_init(void) BOOL is_first = TRUE; LONG rc; - memset(ap,0,sizeof(*ap)); - - ap->ap_Strlen = MAXPATHLEN; - - if(__check_abort_enabled) - ap->ap_BreakBits = SIGBREAKF_CTRL_C; - rc = MatchFirst(argv[i],ap); while(TRUE) @@ -191,13 +213,6 @@ __wildcard_expand_init(void) { MatchEnd(ap); - memset(ap,0,sizeof(*ap)); - - ap->ap_Strlen = MAXPATHLEN; - - if(__check_abort_enabled) - ap->ap_BreakBits = SIGBREAKF_CTRL_C; - rc = MatchFirst(argv[i],ap); } else @@ -356,15 +371,23 @@ __wildcard_expand_init(void) out: - anchor = NULL; - if(ap != NULL) { MatchEnd(ap); - free(ap); + #if defined(__amigaos4__) + { + FreeDosObject(DOS_ANCHORPATH,anchor); + } + #else + { + free(ap); + } + #endif /* __amigaos4__ */ } + anchor = NULL; + if(error != OK) { errno = error;