1
0
Fork 0

added TRI_WriteFile convenience function

This commit is contained in:
Jan Steemann 2013-08-27 12:17:19 +02:00
parent 6f988e7b67
commit fb76008108
2 changed files with 31 additions and 0 deletions

View File

@ -842,6 +842,31 @@ bool TRI_WritePointer (int fd, void const* buffer, size_t length) {
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief saves data to a file
////////////////////////////////////////////////////////////////////////////////
int TRI_WriteFile (const char* filename, const char* data, size_t length) {
int fd;
bool result;
fd = TRI_CREATE(filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
if (fd == -1) {
return TRI_set_errno(TRI_ERROR_SYS_ERROR);
}
result = TRI_WritePointer(fd, data, length);
TRI_CLOSE(fd);
if (! result) {
return TRI_errno();
}
return TRI_ERROR_NO_ERROR;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief fsyncs a file
////////////////////////////////////////////////////////////////////////////////

View File

@ -171,6 +171,12 @@ bool TRI_ReadPointer (int fd, void* buffer, size_t length);
bool TRI_WritePointer (int fd, void const* buffer, size_t length);
////////////////////////////////////////////////////////////////////////////////
/// @brief saves data to a file
////////////////////////////////////////////////////////////////////////////////
int TRI_WriteFile (const char*, const char*, size_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief fsyncs a file
////////////////////////////////////////////////////////////////////////////////