Fix File object.

This commit is contained in:
Brad Arant committed 2022-08-05 06:18:22 -07:00
1 parent d38b7f0c55
commit eb48a5180d
2 files changed
+16 -5

No files matched your search

+14 -5
View File
@@ -1,6 +1,7 @@
#include "File.h"
#include "Exception.h"
#include <sys/stat.h>
#include <iostream>
#include <sstream>
#include <fcntl.h>
#include <sys/types.h>
@@ -9,6 +10,14 @@
namespace coreutils {
File::File(std::string fileName, int mode, int authority) {
open(fileName, mode, authority);
}
File::File(coreutils::ZString &fileName, int mode, int authority) {
open(fileName.str(), mode, authority);
}
void File::open(std::string fileName, int mode, int authority) {
this->fileName = fileName;
@@ -19,7 +28,7 @@ namespace coreutils {
setBufferSize(status.st_size);
fd = open(fileName.c_str(), mode, authority);
fd = ::open(fileName.c_str(), mode, authority);
if(fd < 0) {
std::stringstream temp;
temp << "Error opening file " << fileName << ".";
@@ -27,10 +36,6 @@ namespace coreutils {
}
}
File::File(coreutils::ZString &fileName, int mode, int authority) {
File(fileName.str(), mode, authority);
}
File::~File() {
close(fd);
setBufferSize(0);
@@ -50,6 +55,10 @@ namespace coreutils {
::write(fd, data.c_str(), data.length());
}
void File::write(coreutils::ZString &data) {
int len = ::write(fd, data.getData(), data.getLength());
}
std::string File::asString() {
return std::string(buffer, size);
}