FAUST compiler  0.9.9.6b8
files.cpp
Go to the documentation of this file.
1 /************************************************************************
2  ************************************************************************
3  FAUST compiler
4  Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5  ---------------------------------------------------------------------
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  ************************************************************************
20  ************************************************************************/
21 
22 #include "files.hh"
23 #include "compatibility.hh"
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 #include <unistd.h>
30 #include <errno.h>
31 
32 using namespace std;
33 
34 static string gCurrentDir;
35 
40 int cholddir()
41 {
42  if (chdir(gCurrentDir.c_str()) == 0) {
43  return 0;
44  } else {
45  perror("cholddir");
46  exit(errno);
47  }
48 }
49 
55 int mkchdir(string dirname)
56 {
57  char buffer[FAUST_PATH_MAX];
58  gCurrentDir = getcwd(buffer, FAUST_PATH_MAX);
59 
60  if (gCurrentDir.c_str() != 0) {
61  int status = mkdir(dirname.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
62  if (status == 0 || errno == EEXIST) {
63  if (chdir(dirname.c_str()) == 0) {
64  return 0;
65  }
66  }
67  }
68  perror("mkchdir");
69  exit(errno);
70 }
71 
72 int makedir(string dirname)
73 {
74  char buffer[FAUST_PATH_MAX];
75  gCurrentDir = getcwd(buffer, FAUST_PATH_MAX);
76 
77  if (gCurrentDir.c_str() != 0) {
78  int status = mkdir(dirname.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
79  if (status == 0 || errno == EEXIST) {
80  return 0;
81  }
82  }
83  perror("makedir");
84  exit(errno);
85 }
86 
88 {
89  char buffer[FAUST_PATH_MAX];
90  gCurrentDir = getcwd(buffer, FAUST_PATH_MAX);
91 }
92 
int mkchdir(string dirname)
Create a new directory in the current one to store the diagrams.
Definition: files.cpp:55
void getCurrentDir()
Definition: files.cpp:87
int makedir(string dirname)
Definition: files.cpp:72
static string gCurrentDir
Room to save current directory name.
Definition: files.cpp:34
#define FAUST_PATH_MAX
int cholddir()
Switch back to the previously stored current directory.
Definition: files.cpp:40