Move set_dirent_name() to Utils.h

This commit is contained in:
Ingo Weinhold
2011-11-25 06:17:54 +01:00
parent 0e0e9b4575
commit 4ac4d15c3a
2 changed files with 20 additions and 15 deletions
@@ -6,6 +6,10 @@
#define UTILS_H #define UTILS_H
#include <dirent.h>
#include <string.h>
inline bool operator<(const timespec& a, const timespec& b) inline bool operator<(const timespec& a, const timespec& b)
{ {
return a.tv_sec < b.tv_sec return a.tv_sec < b.tv_sec
@@ -19,4 +23,19 @@ inline bool operator>(const timespec& a, const timespec& b)
} }
static inline bool
set_dirent_name(struct dirent* buffer, size_t bufferSize, const char* name,
size_t nameLen)
{
size_t length = (buffer->d_name + nameLen + 1) - (char*)buffer;
if (length > bufferSize)
return false;
memcpy(buffer->d_name, name, nameLen);
buffer->d_name[nameLen] = '\0';
buffer->d_reclen = length;
return true;
}
#endif // UTILS_H #endif // UTILS_H
@@ -22,6 +22,7 @@
#include "Directory.h" #include "Directory.h"
#include "GlobalFactory.h" #include "GlobalFactory.h"
#include "PackageFSRoot.h" #include "PackageFSRoot.h"
#include "Utils.h"
#include "Volume.h" #include "Volume.h"
@@ -45,21 +46,6 @@ is_user_in_group(gid_t gid)
} }
static bool
set_dirent_name(struct dirent* buffer, size_t bufferSize, const char* name,
size_t nameLen)
{
size_t length = (buffer->d_name + nameLen + 1) - (char*)buffer;
if (length > bufferSize)
return false;
memcpy(buffer->d_name, name, nameLen);
buffer->d_name[nameLen] = '\0';
buffer->d_reclen = length;
return true;
}
static status_t static status_t
check_access(Node* node, int mode) check_access(Node* node, int mode)
{ {