41#include "blocxx/BLOCXX_config.h"
71 static unsigned long MapPosixPermissionsMask( PACCESS_ALLOWED_ACE pAce,
int PermissionMask )
74 pAce->Mask |= ((PermissionMask & S_IROTH) == S_IROTH) ? BLOCXX_WIN32_ACCESSMASK_GENERIC_READ : 0;
75 pAce->Mask |= ((PermissionMask & S_IWOTH) == S_IWOTH) ? BLOCXX_WIN32_ACCESSMASK_GENERIC_WRITE : 0;
76 pAce->Mask |= ((PermissionMask & S_IXOTH) == S_IXOTH) ? BLOCXX_WIN32_ACCESSMASK_GENERIC_EXEC : 0;
86 static int posix_chmod(
const char* path,
int mode)
88 int result, nLenghtNeeded;
89 PSID ppOwnerSid = NULL, ppGroupSid = NULL, pSecurityDescriptor = NULL;
91 if ( (result = GetNamedSecurityInfo( (LPTSTR)path,
93 DACL_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION,
98 &pSecurityDescriptor) ) )
106 for (
unsigned short aceIdx = 0; aceIdx < pAcl->AceCount; aceIdx++)
109 if (!::GetAce(pAcl, aceIdx, (
void**)&pAce))
113 switch( pAce->AceType )
115 case ACCESS_ALLOWED_ACE_TYPE:
117 PACCESS_ALLOWED_ACE pAllowedAce = (PACCESS_ALLOWED_ACE) pAce;
118 unsigned long sNameLen, sDNameLen = sNameLen = MAX_PATH;
119 char sName[MAX_PATH] = {0}, sDName[MAX_PATH] = {0};
122 if ( !::LookupAccountSid( NULL, &(pAllowedAce->SidStart), sName, &sNameLen, sDName, &sDNameLen, &eUse) )
127 if ( EqualSid( ppOwnerSid, &pAllowedAce->SidStart ) || (eUse == SidTypeWellKnownGroup && !strcmp(sName,
"CREATOR OWNER")) )
130 int hundreds = mode / 100;
131 MapPosixPermissionsMask( pAllowedAce, (hundreds - (hundreds/10)*10) );
134 if ( EqualSid( ppGroupSid, &pAllowedAce->SidStart ) || eUse == WinCreatorGroupSid )
137 int decimals = mode / 10;
138 MapPosixPermissionsMask( pAllowedAce, (decimals - (decimals/10)*10) );
142 MapPosixPermissionsMask( pAllowedAce, (mode - (mode/10)*10) );
146 case ACCESS_DENIED_ACE_TYPE:
152 DeleteAce(pAcl, aceIdx);
162 result = SetNamedSecurityInfo((LPTSTR)path,
164 PROTECTED_DACL_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION,
170 if (pSecurityDescriptor) LocalFree((HLOCAL)pSecurityDescriptor);
176 static int posix_mkdir(
const char* path,
int mode)
179 if ( result = _mkdir(path) )
return result;
185 return ((mode!=-1) ? result = posix_chmod(path, mode) : result);
189 #define _ACCESS ::_access
193 #define _CHDIR _chdir
194 #define _MKDIR(a,b) posix_mkdir((a), (b))
195 #define _RMDIR _rmdir
196 #define _UNLINK _unlink
200 #ifdef BLOCXX_HAVE_UNISTD_H
203 #ifdef BLOCXX_HAVE_DIRENT_H
207 #define _ACCESS ::access
209 #define _MKDIR(a,b) mkdir((a),(b))
211 #define _UNLINK unlink
214#define MAXSYMLINKS 20
220#include <sys/types.h>
364 if (!
sfname.endsWith(
'/'))
373 sfname +=
"blocxxtmpfileXXXXXX";
408 if (!
sfname.endsWith(
'/'))
417 sfname +=
"blocxxtmpfileXXXXXX";
461 if (!
sfname.endsWith(
'/'))
525 if (!
sfname.endsWith(
'/'))
1006 return ::fsync(hdl);
1016 std::ifstream in(filename.
c_str());
1059 else if (
static_cast<unsigned>(
rc) ==
buf.size())
1061 buf.resize(
buf.size() * 2);
1066 buf.push_back(
'\0');
1120 if (
path.startsWith(
"/"))
1139 if (filename.
length() == 0)
1177 if (filename.
length() == 0)
1181 size_t end = filename.
length() -1;
1191 if (end == filename.
length() -1)
1224 buf.resize(
buf.size() * 2);
#define BLOCXX_DEFINE_EXCEPTION_WITH_ID(NAME)
Define a new exception class named <NAME>Exception that derives from Exception.
#define BLOCXX_THROW(exType, msg)
Throw an exception using FILE and LINE.
#define BLOCXX_THROW_ERRNO(exType)
Throw an exception using FILE, LINE, errno and strerror(errno)
#define BLOCXX_THROW_ERRNO_MSG(exType, msg)
Throw an exception using FILE, LINE, errno and strerror(errno)
#define BLOCXX_GLOBAL_MUTEX_INIT()
#define BLOCXX_GLOBAL_PTR_INIT
This macro is provided to abstract the details of GlobalPtr.
#define BLOCXX_GLOBAL_STRING_INIT(str)
#define BLOCXX_LOG_ERROR(logger, message)
Log message to logger with the Error level.
#define BLOCXX_FILENAME_SEPARATOR
#define BLOCXX_FILENAME_SEPARATOR_C
The AutoPtrVec class provides a simple class for smart pointers to a dynamically allocated array of o...
The purpose of the File class is to provide an abstraction layer over the platform dependant function...
This class can be used to store a global pointer.
This class can be used to store a global variable that is lazily initialized in a thread safe manner.
This String class is an abstract data type that represents as NULL terminated string of characters.
const char * c_str() const
String substring(size_t beginIndex, size_t length=npos) const
Create another String object that is comprised of a substring of this String object.
StringArray tokenize(const char *delims=" \n\r\t\v", EReturnDelimitersFlag returnDelimitersAsTokens=E_DISCARD_DELIMITERS, EEmptyTokenReturnFlag returnEmptyTokens=E_SKIP_EMPTY_TOKENS) const
Tokenize this String object using the given delimeters.
size_t lastIndexOf(char ch, size_t fromIndex=npos) const
Find the last occurence of a character in this String object.
BLOCXX_COMMON_API String basename(const String &filename)
Take a string that contains a pathname, and return a string that is the filename with the path remove...
BLOCXX_COMMON_API String realPath(const String &path)
BLOCXX_COMMON_API std::pair< ESecurity, String > security(String const &path, UserId uid)
BLOCXX_COMMON_API String dirname(const String &filename)
Take a string that contains a pathname, and return a string that is a pathname of the parent director...
BLOCXX_COMMON_API String getCurrentWorkingDirectory()
Get the process's current working directory.
BLOCXX_COMMON_API int changeFileOwner(const String &filename, const UserId &userId)
Change the given file ownership.
GlobalString COMPONENT_NAME
BLOCXX_COMMON_API void rewind(const FileHandle &hdl)
Position the file pointer associated with the given file handle to the beginning of the file.
BLOCXX_COMMON_API File createFile(const String &path)
Create the file for the given name.
BLOCXX_COMMON_API File openForAppendOrCreateFile(const String &path)
Opens the file for the given name to append data or create if it does not exist.
BLOCXX_COMMON_API size_t read(const FileHandle &hdl, void *bfr, size_t numberOfBytes, Int64 offset=-1L)
Read data from file.
BLOCXX_COMMON_API bool canRead(const String &path)
BLOCXX_COMMON_API bool isLink(const String &path)
Tests if a file is a symbolic link.
BLOCXX_COMMON_API bool exists(const String &path)
BLOCXX_COMMON_API bool removeFile(const String &path)
Remove the given file.
BLOCXX_COMMON_API bool getFileSize(const String &path, Int64 &size)
Get the size of the file in bytes.
BLOCXX_COMMON_API bool getDirectoryContents(const String &path, StringArray &dirEntries)
Get the names of the files (and directories) in the given directory.
BLOCXX_COMMON_API File createAutoDeleteTempFile(const String &dir=String())
Create a tempororary file that will be removed when the returned File object is closed.
BLOCXX_COMMON_API String readSymbolicLink(const String &path)
Read the value of a symbolic link.
BLOCXX_COMMON_API Int64 seek(const FileHandle &hdl, Int64 offset, int whence)
Seek to a given offset within the file.
BLOCXX_COMMON_API int close(const FileHandle &hdl)
Close file handle.
BLOCXX_COMMON_API size_t write(FileHandle hdl, const void *bfr, size_t numberOfBytes, Int64 offset=-1L)
Write data to a file.
BLOCXX_COMMON_API bool renameFile(const String &oldFileName, const String &newFileName)
Rename the given file to the new name.
BLOCXX_COMMON_API bool isExecutable(const String &path)
Tests if a file is executable.
BLOCXX_COMMON_API bool canWrite(const String &path)
BLOCXX_COMMON_API File openOrCreateFile(const String &path)
Opens or creates the file for the given name.
FileSystemMockObject_t g_fileSystemMockObject
BLOCXX_COMMON_API File createTempFile(String &filePath, const String &dir=String())
Create a tempororary file in an optional directory.
BLOCXX_COMMON_API Int64 tell(const FileHandle &hdl)
BLOCXX_COMMON_API UInt64 fileSize(FileHandle fh)
Get the size of a file from the file handle.
BLOCXX_COMMON_API bool isDirectory(const String &path)
BLOCXX_COMMON_API int flush(FileHandle &hdl)
Flush any buffered data to the file if buffering supported.
BLOCXX_COMMON_API StringArray getFileLines(const String &filename)
Read and return the lines of a test file.
GlobalPtr< FileSystemMockObject, NullFactory > FileSystemMockObject_t
BLOCXX_COMMON_API bool changeDirectory(const String &path)
Change to the given directory.
BLOCXX_COMMON_API File openFile(const String &path)
Open a file for read/write and return an File object that can be used for reading and writing.
BLOCXX_COMMON_API String getFileContents(const String &filename)
Read and return the contents of a text file.
BLOCXX_COMMON_API bool removeDirectory(const String &path)
Remove the given directory.
BLOCXX_COMMON_API bool makeDirectory(const String &path, int mode=0777)
Create a directory.
char * strcpy_check(char *dst, std::size_t dstsize, char const *src)
PROMISE: copies the first n = min(strlen(src), dstsize - 1) chars of the C-string src to dst and appe...
bool operator==(const Array< T > &x, const Array< T > &y)