(file) Return to SystemUnix.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 mike  1.1 //BEGIN_LICENSE
  2           //
  3           // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
  4           //
  5           // Permission is hereby granted, free of charge, to any person obtaining a
  6           // copy of this software and associated documentation files (the "Software"),
  7           // to deal in the Software without restriction, including without limitation
  8           // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9           // and/or sell copies of the Software, and to permit persons to whom the
 10           // Software is furnished to do so, subject to the following conditions:
 11           //
 12           // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 13           // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 14           // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 15           // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 16           // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 17           // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 18           // DEALINGS IN THE SOFTWARE.
 19           //
 20           //END_LICENSE
 21           //BEGIN_HISTORY
 22 mike  1.1 //
 23           // Author: Michael E. Brasher
 24           //
 25 mike  1.3 // $Log: SystemUnix.cpp,v $
 26           // Revision 1.2  2001/04/11 07:03:02  mike
 27           // Port to Unix
 28           //
 29 mike  1.1 //
 30           //END_HISTORY
 31           
 32 mike  1.3 #include <unistd.h>
 33           #include <dirent.h>
 34 mike  1.1 #include "System.h"
 35 mike  1.3 #include <sys/stat.h>
 36           #include <sys/types.h>
 37           #include <cstdio>
 38 mike  1.1 
 39           PEGASUS_NAMESPACE_BEGIN
 40           
 41 mike  1.2 #include <sys/time.h>
 42           #include <unistd.h>
 43           
 44           inline void sleep_wrapper(Uint32 seconds)
 45           {
 46               sleep(seconds);
 47           }
 48 mike  1.1 
 49           void System::getCurrentTime(Uint32& seconds, Uint32& milliseconds)
 50           {
 51               timeval tv;
 52               gettimeofday(&tv, 0);
 53               seconds = int(tv.tv_sec);
 54 mike  1.2     milliseconds = int(tv.tv_usec);
 55 mike  1.1 }
 56           
 57           void System::sleep(Uint32 seconds)
 58           {
 59 mike  1.2     sleep_wrapper(seconds);
 60 mike  1.3 }
 61           
 62           Boolean System::exists(const char* path)
 63           {
 64               return access(path, F_OK) == 0;
 65           }
 66           
 67           Boolean FileSystem::canRead(const char* path)
 68           {
 69               return access(path, R_OK) == 0;
 70           }
 71           
 72           Boolean System::canWrite(const char* path)
 73           {
 74               return _access(path, W_OK) == 0;
 75           }
 76           
 77           Boolean System::getCurrentDirectory(char* path, Uint32 size)
 78           {
 79               return getcwd(path, size) != NULL;
 80           }
 81 mike  1.3 
 82           Boolean System::isDirectory(const char* path)
 83           {
 84               struct stat st;
 85           
 86               if (stat(p.getPointer(), &st) != 0)
 87           	return false;
 88           
 89               return S_ISDIR(st.st_mode);
 90           }
 91           
 92           Boolean System::changeDirectory(const char* path)
 93           {
 94               return chdir(path) == 0;
 95           }
 96           
 97           Boolean System::makeDirectory(const char* path)
 98           {
 99               return mkdir(path, 0777) == 0;
100           }
101           
102 mike  1.3 Boolean System::getFileSize(const char* path, Uint32& size)
103           {
104               struct stat st;
105           
106               if (stat(path, &st) != 0)
107           	return false;
108           
109               size = st.st_size;
110               return true;
111           }
112           
113           Boolean System::removeDirectory(const char* path)
114           {
115               return rmdir(path) == 0;	
116           }
117           
118           Boolean System::removeFile(const char* path)
119           {
120               return unlink(path) == 0;	
121           }
122           
123 mike  1.3 Boolean System::renameFile(const char* oldPath, const char* newPath)
124           {
125               if (link(oldPath, newPath) != 0)
126           	return false;
127           
128               return unlink(oldPath) == 0;
129 mike  1.1 }
130           
131 mike  1.4 DynamicLibraryHandle System::loadDynamicLibrary(const char* fileName)
132           {
133               return DynamicLibraryHandle(dlopen(fileName, 0));
134           }
135           
136           DynamicSymbolHandle System::loadDynamicSymbol(
137               DynamicLibraryHandle libraryHandle,
138               const char* symbolName)
139           {
140               return DynamicSymbolHandle(dlsym(libraryHandle, (char*)symbolName));
141           }
142           
143 mike  1.1 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2