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

- Unlink is now reentrant, or at least thread-safe.

- You can now make unlink() stop after a failed deletion attempt which
  failed because the object to be deleted was reported as being "in use".
  The libunix.a variant defaults to report the deletion to have succeeded
  under these circumstances and later tries to delete the files marked
  for deletion. See <dos.h> for a brief documentation of how to change
  the behaviour.


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15155 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2006-09-27 09:40:06 +00:00
parent 0b833b8680
commit 9984a37cb4
9 changed files with 110 additions and 22 deletions

View File

@ -1,5 +1,5 @@
#
# $Id: GNUmakefile.68k,v 1.96 2006-09-17 17:36:42 obarthel Exp $
# $Id: GNUmakefile.68k,v 1.97 2006-09-27 09:40:05 obarthel Exp $
#
# :ts=8
#
@ -455,6 +455,7 @@ C_LIB = \
unistd_time_delay.o \
unistd_truncate.o \
unistd_unlink.o \
unistd_unlink_retries.o \
unistd_usleep.o \
utime_utime.o \
utsname_uname.o

View File

@ -1,3 +1,12 @@
- Unlink is now reentrant, or at least thread-safe.
- You can now make unlink() stop after a failed deletion attempt which
failed because the object to be deleted was reported as being "in use".
The libunix.a variant defaults to report the deletion to have succeeded
under these circumstances and later tries to delete the files marked
for deletion. See <dos.h> for a brief documentation of how to change
the behaviour.
- basename() and dirname() can no longer return NULL. They truncate the
resulting path name instead. This is done so because some code that
calls basename() or dirname() does not check if the function's return

View File

@ -1,5 +1,5 @@
/*
* $Id: dos.h,v 1.27 2006-09-25 14:51:15 obarthel Exp $
* $Id: dos.h,v 1.28 2006-09-27 09:40:06 obarthel Exp $
*
* :ts=4
*
@ -555,6 +555,16 @@ extern void __execve_exit(int return_code);
/****************************************************************************/
/*
* The unlink() and remove() functions in libunix.a may return success even
* though deletion failed because the file/directory/link in question is still
* reported as being "in use". This is the default behaviour. If you want the
* deletion to fail instead, set '__unlink_retries' to FALSE.
*/
extern BOOL __unlink_retries;
/****************************************************************************/
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -1,5 +1,5 @@
#
# $Id: libunix.gmk,v 1.1 2006-09-17 17:37:27 obarthel Exp $
# $Id: libunix.gmk,v 1.2 2006-09-27 09:40:06 obarthel Exp $
#
# :ts=8
#
@ -122,6 +122,7 @@ UNIX_LIB := \
unistd_ttyname_r.o \
unistd_unix_path_semantics.o \
unistd_unlink.o \
unistd_unlink_retries.o \
unistd_wildcard_expand.o \
utime_utime.o

View File

@ -1,5 +1,5 @@
/*
* $Id: time_gettimeofday.c,v 1.10 2006-01-08 12:04:27 obarthel Exp $
* $Id: time_gettimeofday.c,v 1.11 2006-09-27 09:40:06 obarthel Exp $
*
* :ts=4
*
@ -59,6 +59,23 @@
/****************************************************************************/
/* A quick workaround for the timeval/timerequest->TimeVal/TimeRequest
change in the recent OS4 header files. */
#if defined(__NEW_TIMEVAL_DEFINITION_USED__)
#define timeval TimeVal
#define tv_secs Seconds
#define tv_micro Microseconds
#define timerequest TimeRequest
#define tr_node Request
#define tr_time Time
#endif /* __NEW_TIMEVAL_DEFINITION_USED__ */
/****************************************************************************/
int
gettimeofday(struct timeval *tp, struct timezone *tzp)
{

View File

@ -1,5 +1,5 @@
/*
* $Id: unistd_headers.h,v 1.11 2006-07-28 14:37:28 obarthel Exp $
* $Id: unistd_headers.h,v 1.12 2006-09-27 09:40:06 obarthel Exp $
*
* :ts=4
*
@ -59,7 +59,8 @@ extern char NOCOMMON __current_path_name[MAXPATHLEN];
/****************************************************************************/
/* Names of files and directories to delete when shutting down. */
extern struct MinList NOCOMMON __unlink_list;
extern struct MinList NOCOMMON __unlink_list;
extern struct SignalSemaphore NOCOMMON __unlink_semaphore;
/****************************************************************************/

View File

@ -1,5 +1,5 @@
/*
* $Id: unistd_init_exit.c,v 1.13 2006-01-08 12:04:27 obarthel Exp $
* $Id: unistd_init_exit.c,v 1.14 2006-09-27 09:40:06 obarthel Exp $
*
* :ts=4
*
@ -44,7 +44,8 @@
/****************************************************************************/
/* Names of files and directories to delete when shutting down. */
struct MinList NOCOMMON __unlink_list;
struct MinList NOCOMMON __unlink_list;
struct SignalSemaphore NOCOMMON __unlink_semaphore;
/****************************************************************************/
@ -53,6 +54,7 @@ CLIB_CONSTRUCTOR(unistd_init)
ENTER();
NewList((struct List *)&__unlink_list);
InitSemaphore(&__unlink_semaphore);
LEAVE();
@ -77,12 +79,10 @@ CLIB_DESTRUCTOR(unistd_exit)
while((uln = (struct UnlinkNode *)RemHead((struct List *)&__unlink_list)))
{
old_dir = CurrentDir(uln->uln_Lock);
D(("deleting '%s'",uln->uln_Name));
old_dir = CurrentDir(uln->uln_Lock);
DeleteFile(uln->uln_Name);
CurrentDir(old_dir);
UnLock(uln->uln_Lock);

View File

@ -1,5 +1,5 @@
/*
* $Id: unistd_unlink.c,v 1.10 2006-01-08 12:04:27 obarthel Exp $
* $Id: unistd_unlink.c,v 1.11 2006-09-27 09:40:06 obarthel Exp $
*
* :ts=4
*
@ -53,7 +53,6 @@
/****************************************************************************/
/* ZZZ unlink() must be reentrant according to POSIX.1 */
int
unlink(const char * path_name)
{
@ -120,13 +119,13 @@ unlink(const char * path_name)
{
#if defined(UNIX_PATH_SEMANTICS)
{
struct UnlinkNode * uln = NULL;
struct UnlinkNode * node;
struct UnlinkNode * uln;
BOOL found = FALSE;
assert( UtilityBase != NULL );
if(IoErr() != ERROR_OBJECT_IN_USE)
if(NOT __unlink_retries || IoErr() != ERROR_OBJECT_IN_USE)
{
__set_errno(__translate_access_io_error_to_errno(IoErr()));
goto out;
@ -149,6 +148,8 @@ unlink(const char * path_name)
PROFILE_OFF();
ObtainSemaphore(&__unlink_semaphore);
assert( __unlink_list.mlh_Head != NULL );
for(node = (struct UnlinkNode *)__unlink_list.mlh_Head ;
@ -167,16 +168,24 @@ unlink(const char * path_name)
if(NOT found)
{
uln = malloc(sizeof(*uln) + strlen(path_name) + 1);
if(uln == NULL)
goto out;
if(uln != NULL)
{
uln->uln_Lock = current_dir;
uln->uln_Name = (char *)(uln + 1);
uln->uln_Lock = current_dir;
uln->uln_Name = (char *)(uln + 1);
strcpy(uln->uln_Name,path_name);
AddTail((struct List *)&__unlink_list,(struct Node *)uln);
strcpy(uln->uln_Name,path_name);
AddTail((struct List *)&__unlink_list,(struct Node *)uln);
current_dir = ZERO;
}
}
current_dir = ZERO;
ReleaseSemaphore(&__unlink_semaphore);
if(NOT found && uln == NULL)
{
__set_errno(ENOMEM);
goto out;
}
}
#else

View File

@ -0,0 +1,40 @@
/*
* $Id: unistd_unlink_retries.c,v 1.1 2006-09-27 09:40:06 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 _UNISTD_HEADERS_H
#include "unistd_headers.h"
#endif /* _UNISTD_HEADERS_H */
/****************************************************************************/
BOOL NOCOMMON __unlink_retries = TRUE;