Many additions and changes.

This commit is contained in:
barant committed 2019-09-13 10:29:36 -07:00
1 parent 50f6e972de
commit 08169b1c3d
30 files changed
+451 -63

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
#include "File.h"
#include "Exception.h"
namespace coreutils {
File::File(std::string fileName, int mode, int authority) {
this->fileName = fileName;
struct stat status;
stat(fileName.c_str(), &status);
buffer = NULL;
setBufferSize(status.st_size);
fd = open(fileName.c_str(), mode, authority);
if(fd < 0) {
std::stringstream temp;
temp << "Error opening file " << fileName << ".";
throw Exception(temp.str(), __FILE__, __LINE__);
}
}
File::~File() {
}
void File::setBufferSize(size_t size) {
buffer = (char *)realloc(buffer, size);
this->size = size;
}
void File::read() {
size = ::read(fd, buffer, size);
setBufferSize(size);
}
void File::write(std::string data) {
::write(fd, data.c_str(), data.length());
}
}