mirror of https://gitee.com/bigwinds/arangodb
added TRI_WriteFile convenience function
This commit is contained in:
parent
6f988e7b67
commit
fb76008108
|
@ -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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue