summaryrefslogtreecommitdiff
path: root/sal/osl/unx/system.c
diff options
context:
space:
mode:
authorRĂ¼diger Timm <rt@openoffice.org>2006-05-04 07:47:57 +0000
committerRĂ¼diger Timm <rt@openoffice.org>2006-05-04 07:47:57 +0000
commitcd9c1d24b9fd52fd6c6f66e9868c4e98ba1d038b (patch)
treefe1a950b5645793b8c88de1a1a6a02302ae03ab2 /sal/osl/unx/system.c
parentc677a5012103941e64586ff69d87946dcb3df5b0 (diff)
INTEGRATION: CWS pj54 (1.10.6); FILE MERGED
2006/04/25 10:53:57 pjanik 1.10.6.1: #i64399#: Remove macxp_tempnam.
Diffstat (limited to 'sal/osl/unx/system.c')
-rw-r--r--sal/osl/unx/system.c127
1 files changed, 2 insertions, 125 deletions
diff --git a/sal/osl/unx/system.c b/sal/osl/unx/system.c
index 12c66810b..54facd98f 100644
--- a/sal/osl/unx/system.c
+++ b/sal/osl/unx/system.c
@@ -4,9 +4,9 @@
*
* $RCSfile: system.c,v $
*
- * $Revision: 1.10 $
+ * $Revision: 1.11 $
*
- * last change: $Author: vg $ $Date: 2006-04-07 08:06:25 $
+ * last change: $Author: rt $ $Date: 2006-05-04 08:47:57 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -499,129 +499,6 @@ char *asctime_r( const struct tm *tm, char *buffer )
}
/*
- * Default tempnam() on MacOS X and Darwin 10.1 and before is broken.
- * This implementation of tempnam() emulates normal tempnam() behavior. It tries
- * the normal hierarchy of temporary directories, and if all fail, uses
- * kLastResortTempDir. A file prefix may also be specified, but if one is not,
- * kDefaultFilePrefix is used instead. The randomness of the last part of the file
- * name is maximum 10 characters long, composed of numbers and letters. The returned
- * name is guarunteed to be unique at the time of invocation, in the directory
- * used from the hierarchy. In any error case, NULL is also returned. errno
- * is set to any value that may be returned by malloc() or stat().
- */
-
-#define kLastResortTempDir "/tmp"
-#define kDefaultFilePrefix "temp"
-#define kRandomnessLength 10
-
-/*******************************************************************************/
-char *macxp_tempnam( const char *tmpdir, const char *prefix )
-{
- char *tempFileName = NULL;
- char *tempFilePathAndPrefix = NULL;
- char *envTempDir = NULL;
- size_t tempDirLen = 0;
- size_t prefixLen = 0;
- size_t tempFileNameSize = 0;
- struct stat fileStatus;
- int staterr = 0;
- char randString[ kRandomnessLength+1 ];
- struct timeval timeOfDay;
-
- pthread_mutex_lock(&getrtl_mutex);
-
- /* There are a number of temp paths to choose from... The order
- * from the MacOS X man page is:
- * 1) the environment variable TMPDIR
- * 2) tmpdir argument
- * 3) P_tmpdir (defined in stdio.h)
- * 4) /tmp
- */
-
- /* Get the length of whatever temp dir we are going to use. */
- if ( (envTempDir=getenv("TMPDIR")) != NULL )
- tempDirLen = strlen( envTempDir );
- else if ( tmpdir != NULL )
- tempDirLen = strlen( tmpdir );
- #ifdef P_tmpdir
- else if ( P_tmpdir != NULL )
- tempDirLen = strlen( P_tmpdir );
- #endif
- else
- tempDirLen = strlen( kLastResortTempDir );
- tempDirLen++;
-
- /* Get the length of the prefix of the file, if any. */
- prefixLen = strlen( (prefix != NULL) ? prefix : kDefaultFilePrefix ) + 1;
-
- /* Allocate memory to store final temp file name, plus
- * extra for the randomness and a little more for good measure. */
- tempFileNameSize = tempDirLen + prefixLen + kRandomnessLength + 4;
- if ( (tempFileName=malloc(tempFileNameSize)) != NULL )
- {
- *tempFileName = '\0';
- if ( (tempFilePathAndPrefix=malloc(tempFileNameSize)) != NULL )
- {
- *tempFilePathAndPrefix = '\0';
-
- /* Get the actual path of the temp dir to use. */
- if ( (envTempDir=getenv("TMPDIR")) != NULL )
- strncpy( tempFilePathAndPrefix, envTempDir, tempDirLen );
- else if ( tmpdir != NULL )
- strncpy( tempFilePathAndPrefix, tmpdir, tempDirLen );
- #ifdef P_tmpdir
- else if ( P_tmpdir != NULL )
- strncpy( tempFilePathAndPrefix, P_tmpdir, tempDirLen );
- #endif
- else
- strncpy( tempFilePathAndPrefix, kLastResortTempDir, tempDirLen );
-
- /* Make sure there's a '/' trailing the temp directory path. */
- if ( *(tempFilePathAndPrefix+(strlen(tempFilePathAndPrefix)-1)) != '/' )
- strncat( tempFilePathAndPrefix, "/", 2 );
-
- /* Append the file prefix if any. */
- strncat( tempFilePathAndPrefix, (prefix!=NULL) ? prefix : kDefaultFilePrefix, prefixLen );
-
- /* Now generate the randomness and make sure the file isn't already there. */
- /* Make sure our seed is fairly random too */
- do
- {
- gettimeofday( &timeOfDay, NULL );
- srandom( timeOfDay.tv_usec );
-
- randString[ 0 ] = '\0';
-
- gettimeofday( &timeOfDay, NULL );
- snprintf( randString, kRandomnessLength+1, "%05x%05x", getpid(), (random()*timeOfDay.tv_usec) );
- strcpy( tempFileName, tempFilePathAndPrefix );
- strncat( tempFileName, randString, kRandomnessLength+1 );
- }
- while ( (staterr=stat(tempFileName, &fileStatus)) == 0 );
-
- /* If stat returned anything other than an error (-1) and that
- * error was anything other than ENOENT (ie file does not exist)
- * then we return NULL. */
- if ( (staterr!=-1) || (errno!=ENOENT) )
- *tempFileName = '\0';
-
- free( tempFilePathAndPrefix );
- }
-
- /* If there was an error in any case, free memory and return NULL. */
- if ( *tempFileName == '\0' )
- {
- free( tempFileName );
- tempFileName = NULL;
- }
- }
-
- pthread_mutex_unlock(&getrtl_mutex);
- return( tempFileName );
-}
-
-
-/*
* Return the system version. Currently, we only differentiate between
* Darwin and OS X.
*/