FreeFOAM The Cross-Platform CFD Toolkit
OSspecific.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 InNamespace
25  Foam
26 
27 Description
28  Functions used by OpenFOAM that are specific to POSIX compliant
29  operating systems and need to be replaced or emulated on other systems.
30 
31 SourceFiles
32  POSIX.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef OSspecific_H
37 #define OSspecific_H
38 
39 #include <OpenFOAM/fileNameList.H>
40 #include <OpenFOAM/long.H>
41 
42 #include <sys/types.h>
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 //- Return the PID of this process
52 pid_t pid();
53 
54 //- Return the parent PID of this process
55 pid_t ppid();
56 
57 //- Return the group PID of this process
58 pid_t pgid();
59 
60 //- Return true if environment variable of given name is defined
61 bool env(const word&);
62 
63 //- Return environment variable of given name
64 // Return string() if the environment is undefined
65 string getEnv(const word&);
66 
67 //- Set an environment variable
68 bool setEnv(const word& name, const string& value, const bool overwrite);
69 
70 //- Return the system's host name
71 word hostName();
72 
73 //- Return the user's login name
74 word userName();
75 
76 //- Return home directory path name for the current user
77 fileName home();
78 
79 //- Return home directory path name for a particular user
80 fileName home(const word& userName);
81 
82 //- Return current working directory path name
83 fileName cwd();
84 
85 //- Change the current directory to the one given and return true,
86 // else return false
87 bool chDir(const fileName& dir);
88 
89 //- Search for @em name in the following hierarchy:
90 // -# Overridden settings:
91 // - $FREEFOAM_CONFIG_DIR/
92 // -# personal settings:
93 // - ~/.FreeFOAM/<VERSION>/
94 // <em>for version-specific files</em>
95 // - ~/.FreeFOAM/
96 // <em>for version-independent files</em>
97 // -# installed settings:
98 // - ${FOAM_INSTALL_CONFIG_PATH} as specified in the CMake build
99 // configuration (usually <prefix>/etc/FreeFOAM-<VERSION>/)
100 //
101 // @return the full path name or fileName() if the name cannot be found
102 // Optionally abort if the file cannot be found
103 fileName findEtcFile(const fileName&, bool mandatory=false);
104 
105 //- Make a directory and return an error if it could not be created
106 // and does not already exist
107 bool mkDir(const fileName&, mode_t=0777);
108 
109 //- Set the file mode
110 bool chMod(const fileName&, const mode_t);
111 
112 //- Return the file mode
113 mode_t mode(const fileName&);
114 
115 //- Return the file type: DIRECTORY or FILE
116 fileName::Type type(const fileName&);
117 
118 //- Does the name exist (as DIRECTORY or FILE) in the file system?
119 // Optionally enable/disable check for gzip file.
120 bool exists(const fileName&, const bool checkGzip=true);
121 
122 //- Does the name exist as a DIRECTORY in the file system?
123 bool isDir(const fileName&);
124 
125 //- Does the name exist as a FILE in the file system?
126 // Optionally enable/disable check for gzip file.
127 bool isFile(const fileName&, const bool checkGzip=true);
128 
129 //- Return size of file
130 off_t fileSize(const fileName&);
131 
132 //- Return time of last file modification
133 time_t lastModified(const fileName&);
134 
135 //- Read a directory and return the entries as a string list
137 (
138  const fileName&,
140  const bool filtergz=true
141 );
142 
143 //- Copy, recursively if necessary, the source to the destination
144 bool cp(const fileName& src, const fileName& dst);
145 
146 //- Create a softlink. dst should not exist. Returns true if successful.
147 bool ln(const fileName& src, const fileName& dst);
148 
149 //- Rename src to dst
150 bool mv(const fileName& src, const fileName& dst);
151 
152 //- Rename to a corresponding backup file
153 // If the backup file already exists, attempt with "01" .. "99" suffix
154 bool mvBak(const fileName&, const std::string& ext = "bak");
155 
156 //- Remove a file, returning true if successful otherwise false
157 bool rm(const fileName&);
158 
159 //- Remove a dirctory and its contents
160 bool rmDir(const fileName&);
161 
162 //- Sleep for the specified number of seconds
163 unsigned int sleep(const unsigned int);
164 
165 //- Close file descriptor
166 void fdClose(const int);
167 
168 //- Check if machine is up by pinging given port
169 bool ping(const word&, const label port, const label timeOut);
170 
171 //- Check if machine is up by pinging port 22 (ssh) and 222 (rsh)
172 bool ping(const word&, const label timeOut=10);
173 
174 //- Execute the specified command
175 int system(const string& command);
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 } // End namespace Foam
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #endif
184 
185 // ************************ vim: set sw=4 sts=4 et: ************************ //