X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fos.c;h=0e850ca456c13d1dccb329760f9df53203663351;hb=80cc20b7784cccc9d8baf9839f9781db6bb6f539;hp=c8135f6626967c78ae5c4256187288cde0607d13;hpb=c516d8e596f5d4c6960b2af1f4b45bf5f08fe5b4;p=swftools.git diff --git a/lib/os.c b/lib/os.c index c8135f6..0e850ca 100755 --- a/lib/os.c +++ b/lib/os.c @@ -109,7 +109,7 @@ char* getInstallationPath() #endif } -char* concatPaths(char*base, char*add) +char* concatPaths(const char*base, const char*add) { int l1 = strlen(base); int l2 = strlen(add); @@ -127,11 +127,11 @@ char* concatPaths(char*base, char*add) return n; } -char* stripFilename(char*filename, char*newext) +char* stripFilename(const char*filename, const char*newext) { char*last1 = strrchr(filename, '/'); char*last2 = strrchr(filename, '\\'); - char*pos = filename; + const char*pos = filename; char*name; char*dot; if(last1>pos) pos = last1 + 1; @@ -147,3 +147,48 @@ char* stripFilename(char*filename, char*newext) return name; } +static char* getTempDir() +{ +#ifdef WIN32 + char*dir = getenv("TMP"); + if(!dir) dir = getenv("TEMP"); + if(!dir) dir = getenv("tmp"); + if(!dir) dir = getenv("temp"); + if(!dir) dir = "C:\\"; +#else + char* dir = "/tmp/"; +#endif + return dir; +} + +char* mktempname(const char*ptr) { + static char tmpbuf[128]; + char*dir = getTempDir(); + int l = strlen(dir); + char*sep = ""; + if(!ptr) + ptr = tmpbuf; + if(l && dir[l-1]!='/' && dir[l-1]!='\\') { +#ifdef WIN32 + sep = "\\"; +#else + sep = "/"; +#endif + } + + // used to be mktemp. This does remove the warnings, but + // It's not exactly an improvement. +#ifdef HAVE_LRAND48 + sprintf(ptr, "%s%s%08x%08x",dir,sep,lrand48(),lrand48()); +#else +# ifdef HAVE_RAND + sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand()); +# else + static int count = 1; + sprintf(ptr, "%s%s%08x%04x%04x",dir,sep,time(0),(unsigned int)tmpbuf^((unsigned int)tmpbuf)>>16,count); + count ++; +# endif +#endif + return ptr; +} +