|
|
|
OSspecific.HGo 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-2009 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 the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 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, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 InNamespace 00026 Foam 00027 00028 Description 00029 Functions used by OpenFOAM that are specific to POSIX compliant 00030 operating systems and need to be replaced or emulated on other systems. 00031 00032 SourceFiles 00033 POSIX.C 00034 00035 \*---------------------------------------------------------------------------*/ 00036 00037 #ifndef OSspecific_H 00038 #define OSspecific_H 00039 00040 #include "fileNameList.H" 00041 #include "long.H" 00042 00043 #include <sys/types.h> 00044 00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00046 00047 namespace Foam 00048 { 00049 00050 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00051 00052 //- Return the PID of this process 00053 pid_t pid(); 00054 00055 //- Return the parent PID of this process 00056 pid_t ppid(); 00057 00058 //- Return the group PID of this process 00059 pid_t pgid(); 00060 00061 //- Return true if environment variable of given name is defined 00062 bool env(const word&); 00063 00064 //- Return environment variable of given name 00065 // Return string() if the environment is undefined 00066 string getEnv(const word&); 00067 00068 //- Set an environment variable 00069 bool setEnv(const word& name, const string& value, const bool overwrite); 00070 00071 //- Return the system's host name 00072 word hostName(); 00073 00074 //- Return the user's login name 00075 word userName(); 00076 00077 //- Return home directory path name for the current user 00078 fileName home(); 00079 00080 //- Return home directory path name for a particular user 00081 fileName home(const word& userName); 00082 00083 //- Return current working directory path name 00084 fileName cwd(); 00085 00086 //- Change the current directory to the one given and return true, 00087 // else return false 00088 bool chDir(const fileName& dir); 00089 00090 //- Search for @em name in the following hierarchy: 00091 // -# personal settings: 00092 // - ~/.OpenFOAM/<VERSION>/ 00093 // <em>for version-specific files</em> 00094 // - ~/.OpenFOAM/ 00095 // <em>for version-independent files</em> 00096 // -# site-wide settings: 00097 // - $WM_PROJECT_INST_DIR/site/<VERSION> 00098 // <em>for version-specific files</em> 00099 // - $WM_PROJECT_INST_DIR/site/ 00100 // <em>for version-independent files</em> 00101 // -# shipped settings: 00102 // - $WM_PROJECT_DIR/etc/ 00103 // 00104 // @return the full path name or fileName() if the name cannot be found 00105 // Optionally abort if the file cannot be found 00106 fileName findEtcFile(const fileName&, bool mandatory=false); 00107 00108 //- Make a directory and return an error if it could not be created 00109 // and does not already exist 00110 bool mkDir(const fileName&, mode_t=0777); 00111 00112 //- Set the file mode 00113 bool chMod(const fileName&, const mode_t); 00114 00115 //- Return the file mode 00116 mode_t mode(const fileName&); 00117 00118 //- Return the file type: DIRECTORY or FILE 00119 fileName::Type type(const fileName&); 00120 00121 //- Does the name exist (as DIRECTORY or FILE) in the file system? 00122 // Optionally enable/disable check for gzip file. 00123 bool exists(const fileName&, const bool checkGzip=true); 00124 00125 //- Does the name exist as a DIRECTORY in the file system? 00126 bool isDir(const fileName&); 00127 00128 //- Does the name exist as a FILE in the file system? 00129 // Optionally enable/disable check for gzip file. 00130 bool isFile(const fileName&, const bool checkGzip=true); 00131 00132 //- Return size of file 00133 off_t fileSize(const fileName&); 00134 00135 //- Return time of last file modification 00136 time_t lastModified(const fileName&); 00137 00138 //- Read a directory and return the entries as a string list 00139 fileNameList readDir 00140 ( 00141 const fileName&, 00142 const fileName::Type=fileName::FILE, 00143 const bool filtergz=true 00144 ); 00145 00146 //- Copy, recursively if necessary, the source to the destination 00147 bool cp(const fileName& src, const fileName& dst); 00148 00149 //- Create a softlink. dst should not exist. Returns true if successful. 00150 bool ln(const fileName& src, const fileName& dst); 00151 00152 //- Rename src to dst 00153 bool mv(const fileName& src, const fileName& dst); 00154 00155 //- Rename to a corresponding backup file 00156 // If the backup file already exists, attempt with "01" .. "99" suffix 00157 bool mvBak(const fileName&, const std::string& ext = "bak"); 00158 00159 //- Remove a file, returning true if successful otherwise false 00160 bool rm(const fileName&); 00161 00162 //- Remove a dirctory and its contents 00163 bool rmDir(const fileName&); 00164 00165 //- Sleep for the specified number of seconds 00166 unsigned int sleep(const unsigned int); 00167 00168 //- Close file descriptor 00169 void fdClose(const int); 00170 00171 //- Check if machine is up by pinging given port 00172 bool ping(const word&, const label port, const label timeOut); 00173 00174 //- Check if machine is up by pinging port 22 (ssh) and 222 (rsh) 00175 bool ping(const word&, const label timeOut=10); 00176 00177 //- Execute the specified command 00178 int system(const string& command); 00179 00180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00181 00182 } // End namespace Foam 00183 00184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00185 00186 #endif 00187 00188 // ************************************************************************* // |