Move set_dirent_name() to Utils.h

This commit is contained in:
Ingo Weinhold 2011-06-23 21:28:35 +02:00
parent b5ff7abcea
commit 3ad1037bcc
2 changed files with 20 additions and 15 deletions

View File

@ -6,6 +6,10 @@
#define UTILS_H
#include <dirent.h>
#include <string.h>
inline bool operator<(const timespec& a, const timespec& b)
{
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

View File

@ -22,6 +22,7 @@
#include "Directory.h"
#include "GlobalFactory.h"
#include "PackageFSRoot.h"
#include "Utils.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
check_access(Node* node, int mode)
{