1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Functions used by OpenFOAM that are specific to POSIX compliant
30 operating systems and need to be replaced or emulated on other systems.
35 \*---------------------------------------------------------------------------*/
40 #include <OpenFOAM/fileNameList.H>
41 #include <OpenFOAM/long.H>
43 #include <sys/types.h>
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 //- Return the PID of this process
55 //- Return the parent PID of this process
58 //- Return the group PID of this process
61 //- Return true if environment variable of given name is defined
62 bool env(const word&);
64 //- Return environment variable of given name
65 // Return string() if the environment is undefined
66 string getEnv(const word&);
68 //- Set an environment variable
69 bool setEnv(const word& name, const string& value, const bool overwrite);
71 //- Return the system's host name
74 //- Return the user's login name
77 //- Return home directory path name for the current user
80 //- Return home directory path name for a particular user
81 fileName home(const word& userName);
83 //- Return current working directory path name
86 //- Change the current directory to the one given and return true,
88 bool chDir(const fileName& dir);
90 //- Search for @em name in the following hierarchy:
91 // -# Overridden settings:
92 // - $FREEFOAM_CONFIG_DIR/
93 // -# personal settings:
94 // - ~/.FreeFOAM/\<VERSION\>/
95 // <em>for version-specific files</em>
97 // <em>for version-independent files</em>
98 // -# installed settings:
99 // - ${FF_INSTALL_CONFIG_PATH} as specified in the CMake build
100 // configuration (usually <prefix>/etc/FreeFOAM-\<VERSION\>/)
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 } // End namespace Foam
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 // ************************ vim: set sw=4 sts=4 et: ************************ //