1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Functions used by FOAM that are specific to POSIX compliant
29 operating systems and need to be replaced or emulated on other systems.
34 \*---------------------------------------------------------------------------*/
39 #include "fileNameList.H"
42 #include <sys/types.h>
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 //- Return the PID of this process
58 //- Return the parent PID of this process
61 //- Return the group PID of this process
64 //- Return true if environment variable of given name is defined
65 bool env(const word&);
67 //- Return environment variable of given name
68 // Return string() if the environment is undefined
69 string getEnv(const word&);
71 //- Set an environment variable
72 bool setEnv(const word& name, const string& value, const bool overwrite);
74 //- Return the system's host name
77 //- Return the user's login name
80 //- Return home directory path name for the current user
83 //- Return home directory path name for a particular user
84 fileName home(const word& userName);
86 //- Return current working directory path name
89 //- Change the current directory to the one given and return true,
91 bool chDir(const fileName& dir);
93 //- Search for @em name in the following hierarchy:
94 // -# site-wide settings:
95 // - $WM_PROJECT_INST_DIR/site/\<VERSION\>
96 // <em>for version-specific files</em>
97 // - $WM_PROJECT_INST_DIR/site/
98 // <em>for version-independent files</em>
99 // -# shipped settings:
100 // - $WM_PROJECT_DIR/etc/
102 // @return the full path name or fileName() if the name cannot be found
103 // Optionally abort if the file cannot be found
104 fileName findEtcFile(const fileName&, bool mandatory = false);
106 //- Make a directory and return an error if it could not be created
107 // and does not already exist
108 bool mkDir(const fileName&, mode_t = 0777);
110 //- Set the file mode
111 bool chMod(const fileName&, const mode_t);
113 //- Return the file mode
114 mode_t mode(const fileName&);
116 //- Return the file type: DIRECTORY or FILE
117 fileName::Type type(const fileName&);
119 //- Does the name exist (as DIRECTORY or FILE) in the file system?
120 // Optionally enable/disable check for gzip file.
121 bool exists(const fileName&, const bool checkGzip = true);
123 //- Does the name exist as a DIRECTORY in the file system?
124 bool isDir(const fileName&);
126 //- Does the name exist as a FILE in the file system?
127 // Optionally enable/disable check for gzip file.
128 bool isFile(const fileName&, const bool checkGzip = true);
130 //- Return size of file
131 off_t fileSize(const fileName&);
133 //- Return time of last file modification
134 time_t lastModified(const fileName&);
136 //- Read a directory and return the entries as a string list
140 const fileName::Type = fileName::FILE,
141 const bool filtergz = true
144 //- Copy, recursively if necessary, the source to the destination
145 bool cp(const fileName& src, const fileName& dst);
147 //- Create a softlink. dst should not exist. Returns true if successful.
148 bool ln(const fileName& src, const fileName& dst);
150 //- Rename src to dst
151 bool mv(const fileName& src, const fileName& dst);
153 //- Rename to a corresponding backup file
154 // If the backup file already exists, attempt with "01" .. "99" suffix
155 bool mvBak(const fileName&, const std::string& ext = "bak");
157 //- Remove a file, returning true if successful otherwise false
158 bool rm(const fileName&);
160 //- Remove a dirctory and its contents
161 bool rmDir(const fileName&);
163 //- Sleep for the specified number of seconds
164 unsigned int sleep(const unsigned int);
166 //- Close file descriptor
167 void fdClose(const int);
169 //- Check if machine is up by pinging given port
170 bool ping(const word&, const label port, const label timeOut);
172 //- Check if machine is up by pinging port 22 (ssh) and 222 (rsh)
173 bool ping(const word&, const label timeOut = 10);
175 //- Execute the specified command
176 int system(const string& command);
178 // Low level random numbers. Use Random class instead.
180 //- Seed random number generator.
181 void osRandomSeed(const label seed);
183 //- Return random integer (uniform distribution between 0 and 2^31)
184 label osRandomInteger();
186 //- Return random double precision (uniform distribution between 0 and 1)
187 scalar osRandomDouble();
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 } // End namespace Foam
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 // ************************************************************************* //