2008-08-26 12:39:07 +00:00
|
|
|
#include "TestUtil.h"
|
|
|
|
#include "a2io.h"
|
2008-09-07 14:38:26 +00:00
|
|
|
#include "File.h"
|
|
|
|
#include "StringFormat.h"
|
|
|
|
#include "FatalException.h"
|
2008-08-26 12:39:07 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2008-09-07 14:38:26 +00:00
|
|
|
#include <cerrno>
|
|
|
|
#include <cstring>
|
2008-08-26 12:39:07 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
void createFile(const std::string& path, size_t length)
|
|
|
|
{
|
2008-09-07 14:38:26 +00:00
|
|
|
File(File(path).getDirname()).mkdirs();
|
2008-08-26 12:39:07 +00:00
|
|
|
int fd = creat(path.c_str(), OPEN_MODE);
|
2008-09-07 14:38:26 +00:00
|
|
|
if(fd == -1) {
|
|
|
|
throw FatalException(StringFormat("Could not create file=%s. cause:%s",
|
|
|
|
path.c_str(), strerror(errno)).str());
|
|
|
|
}
|
|
|
|
if(-1 == ftruncate(fd, length)) {
|
|
|
|
throw FatalException(StringFormat("ftruncate failed. cause:%s",
|
|
|
|
strerror(errno)).str());
|
|
|
|
}
|
|
|
|
close(fd);
|
2008-08-26 12:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|