tmpdir.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------------*/
00002 /* Scilab */
00003 /*-----------------------------------------------------------------------------------*/
00004 #include <stdio.h>
00005 #include "machine.h"
00006 #include "../../../io/includes/createdir.h"
00007 #include "MALLOC.h" /* MALLOC */
00008 
00009 #ifdef _MSC_VER
00010 #include <windows.h>
00011 #endif
00012 #if defined(__STDC__) || defined(_MSC_VER)
00013 #include <stdlib.h>
00014 #ifndef _MSC_VER
00015 #include <sys/types.h>
00016 #include <unistd.h>
00017 #endif
00018 #else 
00019 extern  char  *getenv();
00020 #endif
00021 
00022 #if (defined _MSC_VER)
00023 #define putenv(x) _putenv(x)
00024 #endif
00025 
00026 #if defined(_MSC_VER)
00027 #include <process.h>
00028 #endif
00029 #include "prompt.h"
00030 #include "tmpdir.h"
00031 /*-----------------------------------------------------------------------------------*/
00032 static char tmp_dir[256],buf[256];
00033 /*-----------------------------------------------------------------------------------*/
00038 void C2F(settmpdir)(void)
00039 {
00040 #ifdef _MSC_VER
00041         #define PATH_MAX 1024
00042         char TmpDirDefault[PATH_MAX];
00043 #endif
00044   static int first =0;
00045   if ( first == 0 ) 
00046     {
00047       first++;
00048 #ifdef _MSC_VER 
00049           if (!GetTempPath(PATH_MAX,TmpDirDefault))
00050           {
00051                   MessageBox(NULL,"Don''t find Windows temporary directory","Error",MB_ICONERROR);
00052                   exit(1);
00053           }
00054           else
00055           {
00056                   sprintf(tmp_dir,"%sSCI_TMP_%d_",TmpDirDefault,(int) _getpid());
00057           }
00058 
00059           if ( CreateDirectory(tmp_dir,NULL)==FALSE)
00060       {
00061                 DWORD attribs=GetFileAttributes (tmp_dir); 
00062 
00063                 if (attribs & FILE_ATTRIBUTE_DIRECTORY)
00064                 {
00065                   // Repertoire existant
00066                 }
00067                 else
00068                 {
00069                   #ifdef _DEBUG
00070                   char MsgErr[1024];
00071                   wsprintf(MsgErr,"Impossible to create : %s",tmp_dir);
00072                   MessageBox(NULL,MsgErr,"Error",MB_ICONERROR);
00073                   exit(1);
00074                   #else
00075                   GetTempPath(PATH_MAX,TmpDirDefault);
00076                   sprintf(tmp_dir,"%s",TmpDirDefault);
00077                   tmp_dir[strlen(tmp_dir)-1]='\0'; /* Remove last \ */
00078                   #endif
00079                 }
00080   }
00081 #else 
00082   sprintf(tmp_dir,"/tmp/SD_%d_",(int) getpid());
00083   CreateDir(tmp_dir) ;
00084 #endif 
00085   sprintf(buf,"TMPDIR=%s",tmp_dir);
00086   putenv(buf);
00087     }
00088 }
00089 /*-----------------------------------------------------------------------------------*/
00093 char *get_sci_tmp_dir(void)
00094 {
00095   /* just in case */
00096   C2F(settmpdir)();
00097   return tmp_dir;
00098 }
00099 /*-----------------------------------------------------------------------------------*/
00103 void C2F(tmpdirc)(void)
00104 {
00105   char *tmp_dir2 = get_sci_tmp_dir(); 
00106   RemoveDir(tmp_dir2);
00107 }
00108 /*-----------------------------------------------------------------------------------*/

Generated on Sun Mar 4 15:03:48 2007 for Scilab [trunk] by  doxygen 1.5.1