File: tmpdir.c

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (72 lines) | stat: -rw-r--r-- 1,609 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Copyright INRIA */

#include "../machine.h"
#include <stdio.h>

#ifdef __STDC__
#include <stdlib.h>
#ifndef WIN32
#include <sys/types.h>
#include <unistd.h>
#endif
#else 
extern  char  *getenv();
#endif

#ifdef __MSC__
#include <stdlib.h> 
#ifdef __MINGW32__
/** XXXXX missing in mingw32 **/
#define putenv(x) 
#else 
#define putenv(x) _putenv(x)
#endif 
#endif 

static char tmp_dir[20],buf[128];

/****************************
 * creates a tmp dir for a scilab session 
 * and fixes the TMPDIR env variable
 ****************************/

void C2F(settmpdir)()
{
#ifdef WIN32 
  if (!getenv("TEMP")) {
    sprintf(tmp_dir,"C:/tmp/SD_%d_",(int) getpid());
  } else {
    sprintf(tmp_dir,"%s\\SD_%d_",getenv("TEMP"),(int) getpid());
  }
  SciCreateDirectory(tmp_dir);
#else 
  sprintf(tmp_dir,"/tmp/SD_%d_",(int) getpid());
  sprintf(buf,"umask 000;if test ! -d %s; then mkdir %s; fi ",tmp_dir,tmp_dir);
  system(buf);
#endif 
  sprintf(buf,"TMPDIR=%s",tmp_dir);
  putenv(buf);
}

/*************************************************
 * remove TMPDIR and dynamic link temporary files 
 *************************************************/

void C2F(tmpdirc)()
{
#ifdef WIN32 
  if (!getenv("TEMP")) {
    sprintf(tmp_dir,"C:/tmp/SD_%d_",(int) getpid());
  } else {
    sprintf(tmp_dir,"%s\\SD_%d_",getenv("TEMP"),(int) getpid());
  }
  SciRemoveDirectory(tmp_dir);
#else 
  sprintf(tmp_dir,"/tmp/S*_%d_*",(int) getpid());
  sprintf(buf,"rm -f -r %s >/dev/null  2>/dev/null",tmp_dir);
  system(buf);
  sprintf(buf,"rm -f -r /tmp/%d.metanet.* > /dev/null  2>/dev/null",(int) getpid());
  system(buf);
#endif 
}