diff options
author | Martin Hollmichel <mh@openoffice.org> | 2002-07-11 07:53:35 +0000 |
---|---|---|
committer | Martin Hollmichel <mh@openoffice.org> | 2002-07-11 07:53:35 +0000 |
commit | ab110178330aa939e51c30b5081f3bf4b43a9ada (patch) | |
tree | 6b58e30b11ffb2d7980e41481edad2a7e4d40036 /dmake/unix | |
parent | ccff6eaf54aa7d576854bf02e63e2cc316d63492 (diff) |
join: from OOO_STABLE_1
Diffstat (limited to 'dmake/unix')
-rwxr-xr-x | dmake/unix/Makefile.am | 6 | ||||
-rw-r--r-- | dmake/unix/tempnam.c | 106 |
2 files changed, 110 insertions, 2 deletions
diff --git a/dmake/unix/Makefile.am b/dmake/unix/Makefile.am index 01d494d2155f..22285b6a9211 100755 --- a/dmake/unix/Makefile.am +++ b/dmake/unix/Makefile.am @@ -1,11 +1,13 @@ noinst_LIBRARIES = libunix.a -libunix_a_SOURCES = arlib.c dcache.c dirbrk.c rmprq.c ruletab.c runargv.c +libunix_a_SOURCES = arlib.c dcache.c dirbrk.c rmprq.c ruletab.c runargv.c tempnam.c -INCLUDES = -I$(top_srcdir) -I$(top_builddir) -I$(top_srcdir)/unix/@OS_VERSION@/gnu -I$(top_srcdir)/unix/@OS_VERSION@ -I$(top_srcdir)/unix +INCLUDES = -I$(top_srcdir) -I$(top_builddir) -I$(top_srcdir)/unix/@OS_VERSION@/gnu -I$(top_srcdir)/unix -I$(top_srcdir)/unix/@OS_VERSION@ +CFLAGS += -O + diff --git a/dmake/unix/tempnam.c b/dmake/unix/tempnam.c new file mode 100644 index 000000000000..4b143ed8d0d7 --- /dev/null +++ b/dmake/unix/tempnam.c @@ -0,0 +1,106 @@ +/* RCS $Id: tempnam.c,v 1.2 2002-07-11 08:53:35 mh Exp $ +-- +-- SYNOPSIS +-- tempnam +-- +-- DESCRIPTION +-- temp file name generation routines. +-- +-- AUTHOR +-- Dennis Vadura, dvadura@dmake.wticorp.com +-- +-- WWW +-- http://dmake.wticorp.com/ +-- +-- COPYRIGHT +-- Copyright (c) 1996,1997 by WTI Corp. All rights reserved. +-- +-- This program is NOT free software; you can redistribute it and/or +-- modify it under the terms of the Software License Agreement Provided +-- in the file <distribution-root>/readme/license.txt. +-- +-- LOG +-- Use cvs log to obtain detailed change logs. +*/ + +#ifdef __APPLE__ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#if defined(max) +# undef max +#endif +#define max(A,B) (((A)<(B))?(B):(A)) + +extern char *mktemp(); +extern int access(); +int d_access(); + +char * +dtempnam(dir, prefix) +char *dir; /* use this directory please (if non-NULL) */ +char *prefix; /* use this (if non-NULL) as filename prefix */ +{ + static int count = 0; + register char *p, *q, *tmpdir; + int tl=0, dl=0, pl; + char buf[30]; + + pl = strlen(P_tmpdir); + + if( (tmpdir = getenv("TMPDIR")) != NULL ) tl = strlen(tmpdir); + else if( (tmpdir = getenv("TMP")) != NULL ) tl = strlen(tmpdir); + if( dir != NULL ) dl = strlen(dir); + + if( (p = malloc((unsigned)(max(max(dl,tl),pl)+13))) == NULL ) + return(NULL); + + *p = '\0'; + + if( (tl == 0) || (d_access( strcpy(p, tmpdir), 0) != 0) ) + if( (dl == 0) || (d_access( strcpy(p, dir), 0) != 0) ) + if( d_access( strcpy(p, P_tmpdir), 0) != 0 ) + if( !prefix ) + prefix = "tp"; + + if(prefix) + { + *(p+strlen(p)+2) = '\0'; + (void)strncat(p, prefix, 2); + } + + sprintf( buf, "%08x", getpid() ); + buf[6]='\0'; + (void)strcat(p, buf ); + sprintf( buf, "%04d", count++ ); + q=p+strlen(p)-6; + *q++ = buf[0]; *q++ = buf[1]; + *q++ = buf[2]; *q++ = buf[3]; + + if( (q = strrchr(p,'.')) != NULL ) *q = '\0'; + + return(p); +} + + + +d_access( name, flag ) +char *name; +int flag; +{ + extern char *DirSepStr; + char *p; + int r; + + if( name == NULL || !*name ) return(1); /* NULL dir means current dir */ + r = access( name, flag ); + p = name+strlen(name)-1; + if(*p != '/' && *p != '\\') strcat( p, DirSepStr ); + + return( r ); +} + +#endif |