1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
28 Functions used by OpenFOAM 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
54 //- Return the parent PID of this process
57 //- Return the group PID of this process
60 //- Return true if environment variable of given name is defined
61 bool env(const word&);
63 //- Return environment variable of given name
64 // Return string() if the environment is undefined
65 string getEnv(const word&);
67 //- Set an environment variable
68 bool setEnv(const word& name, const std::string& value, const bool overwrite);
70 //- Return the system's host name, as per hostname(1)
71 // Optionally with the full name (as per the '-f' option)
72 word hostName(const bool full=false);
74 //- Return the system's domain name, as per hostname(1) with the '-d' option
77 //- Return the user's login name
80 //- Is user administrator
81 bool isAdministrator();
83 //- Return home directory path name for the current user
86 //- Return home directory path name for a particular user
87 fileName home(const word& userName);
89 //- Return current working directory path name
92 //- Change the current directory to the one given and return true,
94 bool chDir(const fileName& dir);
96 //- Search for a file from user/group/shipped directories.
97 // The search scheme allows for version-specific and
98 // version-independent files using the following hierarchy:
99 // - \b user settings:
100 // - ~/.OpenFOAM/\<VERSION\>
102 // - \b group (site) settings (when $WM_PROJECT_SITE is set):
103 // - $WM_PROJECT_SITE/\<VERSION\>
104 // - $WM_PROJECT_SITE
105 // - \b group (site) settings (when $WM_PROJECT_SITE is not set):
106 // - $WM_PROJECT_INST_DIR/site/\<VERSION\>
107 // - $WM_PROJECT_INST_DIR/site/
108 // - \b other (shipped) settings:
109 // - $WM_PROJECT_DIR/etc/
111 // \return The full path name or fileName() if the name cannot be found
112 // Optionally abort if the file cannot be found
113 fileName findEtcFile(const fileName&, bool mandatory=false);
115 //- Make a directory and return an error if it could not be created
116 // and does not already exist
117 bool mkDir(const fileName&, mode_t=0777);
119 //- Set the file mode
120 bool chMod(const fileName&, const mode_t);
122 //- Return the file mode
123 mode_t mode(const fileName&);
125 //- Return the file type: DIRECTORY or FILE
126 fileName::Type type(const fileName&);
128 //- Does the name exist (as DIRECTORY or FILE) in the file system?
129 // Optionally enable/disable check for gzip file.
130 bool exists(const fileName&, const bool checkGzip=true);
132 //- Does the name exist as a DIRECTORY in the file system?
133 bool isDir(const fileName&);
135 //- Does the name exist as a FILE in the file system?
136 // Optionally enable/disable check for gzip file.
137 bool isFile(const fileName&, const bool checkGzip=true);
139 //- Return size of file
140 off_t fileSize(const fileName&);
142 //- Return time of last file modification
143 time_t lastModified(const fileName&);
145 //- Read a directory and return the entries as a string list
149 const fileName::Type=fileName::FILE,
150 const bool filtergz=true
153 //- Copy, recursively if necessary, the source to the destination
154 bool cp(const fileName& src, const fileName& dst);
156 //- Create a softlink. dst should not exist. Returns true if successful.
157 bool ln(const fileName& src, const fileName& dst);
159 //- Rename src to dst
160 bool mv(const fileName& src, const fileName& dst);
162 //- Rename to a corresponding backup file
163 // If the backup file already exists, attempt with "01" .. "99" suffix
164 bool mvBak(const fileName&, const std::string& ext = "bak");
166 //- Remove a file, returning true if successful otherwise false
167 bool rm(const fileName&);
169 //- Remove a dirctory and its contents
170 bool rmDir(const fileName&);
172 //- Sleep for the specified number of seconds
173 unsigned int sleep(const unsigned int);
175 //- Close file descriptor
176 void fdClose(const int);
178 //- Check if machine is up by pinging given port
179 bool ping(const word&, const label port, const label timeOut);
181 //- Check if machine is up by pinging port 22 (ssh) and 222 (rsh)
182 bool ping(const word&, const label timeOut=10);
184 //- Execute the specified command
185 int system(const std::string& command);
187 //- open a shared library. Return handle to library
188 void* dlOpen(const fileName& lib);
190 //- Close a dlopened library using handle. Return true if successful
193 //- Lookup a symbol in a dlopened library using handle to library
194 void* dlSym(void* handle, const std::string& symbol);
196 //- Report if symbol in a dlopened library could be found
197 bool dlSymFound(void* handle, const std::string& symbol);
199 //- Return all loaded libraries
200 fileNameList dlLoaded();
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 } // End namespace Foam
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 // ************************************************************************* //