FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

OSspecific.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 InNamespace
00025     Foam
00026 
00027 Description
00028     Functions used by OpenFOAM that are specific to POSIX compliant
00029     operating systems and need to be replaced or emulated on other systems.
00030 
00031 SourceFiles
00032     POSIX.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef OSspecific_H
00037 #define OSspecific_H
00038 
00039 #include <OpenFOAM/fileNameList.H>
00040 #include <OpenFOAM/long.H>
00041 
00042 #include <sys/types.h>
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 namespace Foam
00047 {
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 //- Return the PID of this process
00052 pid_t pid();
00053 
00054 //- Return the parent PID of this process
00055 pid_t ppid();
00056 
00057 //- Return the group PID of this process
00058 pid_t pgid();
00059 
00060 //- Return true if environment variable of given name is defined
00061 bool env(const word&);
00062 
00063 //- Return environment variable of given name
00064 //  Return string() if the environment is undefined
00065 string getEnv(const word&);
00066 
00067 //- Set an environment variable
00068 bool setEnv(const word& name, const string& value, const bool overwrite);
00069 
00070 //- Return the system's host name
00071 word hostName();
00072 
00073 //- Return the user's login name
00074 word userName();
00075 
00076 //- Return home directory path name for the current user
00077 fileName home();
00078 
00079 //- Return home directory path name for a particular user
00080 fileName home(const word& userName);
00081 
00082 //- Return current working directory path name
00083 fileName cwd();
00084 
00085 //- Change the current directory to the one given and return true,
00086 //  else return false
00087 bool chDir(const fileName& dir);
00088 
00089 //- Search for @em name in the following hierarchy:
00090 //  -# Overridden settings:
00091 //    - $FREEFOAM_CONFIG_DIR/
00092 //  -# personal settings:
00093 //    - ~/.FreeFOAM/<VERSION>/
00094 //      <em>for version-specific files</em>
00095 //    - ~/.FreeFOAM/
00096 //      <em>for version-independent files</em>
00097 //  -# installed settings:
00098 //    - ${FOAM_INSTALL_CONFIG_PATH} as specified in the CMake build
00099 //      configuration (usually <prefix>/etc/FreeFOAM-<VERSION>/)
00100 //
00101 //  @return the full path name or fileName() if the name cannot be found
00102 //  Optionally abort if the file cannot be found
00103 fileName findEtcFile(const fileName&, bool mandatory=false);
00104 
00105 //- Make a directory and return an error if it could not be created
00106 //  and does not already exist
00107 bool mkDir(const fileName&, mode_t=0777);
00108 
00109 //- Set the file mode
00110 bool chMod(const fileName&, const mode_t);
00111 
00112 //- Return the file mode
00113 mode_t mode(const fileName&);
00114 
00115 //- Return the file type: DIRECTORY or FILE
00116 fileName::Type type(const fileName&);
00117 
00118 //- Does the name exist (as DIRECTORY or FILE) in the file system?
00119 //  Optionally enable/disable check for gzip file.
00120 bool exists(const fileName&, const bool checkGzip=true);
00121 
00122 //- Does the name exist as a DIRECTORY in the file system?
00123 bool isDir(const fileName&);
00124 
00125 //- Does the name exist as a FILE in the file system?
00126 //  Optionally enable/disable check for gzip file.
00127 bool isFile(const fileName&, const bool checkGzip=true);
00128 
00129 //- Return size of file
00130 off_t fileSize(const fileName&);
00131 
00132 //- Return time of last file modification
00133 time_t lastModified(const fileName&);
00134 
00135 //- Read a directory and return the entries as a string list
00136 fileNameList readDir
00137 (
00138     const fileName&,
00139     const fileName::Type=fileName::FILE,
00140     const bool filtergz=true
00141 );
00142 
00143 //- Copy, recursively if necessary, the source to the destination
00144 bool cp(const fileName& src, const fileName& dst);
00145 
00146 //- Create a softlink. dst should not exist. Returns true if successful.
00147 bool ln(const fileName& src, const fileName& dst);
00148 
00149 //- Rename src to dst
00150 bool mv(const fileName& src, const fileName& dst);
00151 
00152 //- Rename to a corresponding backup file
00153 //  If the backup file already exists, attempt with "01" .. "99" suffix
00154 bool mvBak(const fileName&, const std::string& ext = "bak");
00155 
00156 //- Remove a file, returning true if successful otherwise false
00157 bool rm(const fileName&);
00158 
00159 //- Remove a dirctory and its contents
00160 bool rmDir(const fileName&);
00161 
00162 //- Sleep for the specified number of seconds
00163 unsigned int sleep(const unsigned int);
00164 
00165 //- Close file descriptor
00166 void fdClose(const int);
00167 
00168 //- Check if machine is up by pinging given port
00169 bool ping(const word&, const label port, const label timeOut);
00170 
00171 //- Check if machine is up by pinging port 22 (ssh) and 222 (rsh)
00172 bool ping(const word&, const label timeOut=10);
00173 
00174 //- Execute the specified command
00175 int system(const string& command);
00176 
00177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00178 
00179 } // End namespace Foam
00180 
00181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00182 
00183 #endif
00184 
00185 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines