ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
makesub.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include <fvar.hpp>
12 #include <adstring.hpp>
13 //#include <fstream.h>
14 #include <stdlib.h>
15 #if !defined(_MSC_VER)
16  #include <dirent.h>
17  #include <sys/stat.h>
18 #endif
19 #if defined(__BORLANDC__)
20 # include <dir.h>
21 #endif
22 #if defined(_WIN32)
23 # include <windows.h>
24 #else
25 # include <unistd.h>
26 #endif
27 
28 #if !defined(_MSC_VER)
29 #include <iostream>
30 #include <memory.h>
31 #include <fcntl.h>
32 #include <sys/stat.h>
33 #include <sys/types.h>
34 #include <unistd.h>
35 #endif
36 
37 #include <cassert>
38 
43 int ad_chdir(const char * s)
44 {
45 #if defined(_WIN32)
46  return SetCurrentDirectory(s);
47 #else
48  return chdir(s);
49 #endif
50 }
51 
56 void ad_getcd(const adstring& _s)
57 {
58  adstring& s=(adstring&) (_s);
59 #if defined(_WIN32)
60  char tmp[301];
61  tmp[0]='\0';
62  GetCurrentDirectory(300,tmp);
63  s=tmp;
64 #else
65  char tmp[301];
66  tmp[0]='\0';
67  #ifdef __GNUC__
68  char* ret = getcwd(tmp,300);
69  assert(ret != 0);
70  #else
71  getcwd(tmp,300);
72  #endif
73  s=adstring(tmp);
74 #endif
75 }
76 
82 int ad_mkdir(const char* s)
83 {
84 #if defined(_WIN32)
85  return CreateDirectory(s, NULL) != 0;
86 #else
87  return mkdir(s, S_IRUSR | S_IWUSR) == 0;
88 #endif
89 }
95 int make_sub_directory(const char* s)
96 {
97  adstring currdir;
98  adstring currdir1;
99  ad_getcd(currdir);
100 #if defined(_WIN32)
101  int ierr = SetCurrentDirectory(s);
102  if (!ierr) // zero means failed
103 #else
104  DIR* dirp = opendir(s);
105  if (!dirp) // NULL means failed
106 #endif
107  {
108  ad_getcd(currdir);
109  return ad_mkdir(s);
110  }
111  else
112  {
113  ad_getcd(currdir1);
114  ad_chdir(currdir);
115  ad_getcd(currdir1);
116  }
117 #if defined(_WIN32)
118  return ierr != 0;
119 #else
120  return closedir(dirp) != -1;
121 #endif
122 }
int ad_chdir(const char *s)
Description not yet available.
Definition: makesub.cpp:43
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void ad_getcd(const adstring &s)
Description not yet available.
Definition: makesub.cpp:56
int ad_mkdir(const char *s)
Make directory s.
Definition: makesub.cpp:82
int make_sub_directory(const char *s)
Create a sub directory s.
Definition: makesub.cpp:95