blob: ff57c9e50365f7c2504aab31ec18e3e1e1743218 (
plain) (
tree)
|
|
#include "vfile.h"
vfile::vfile(node* parent, char* d, size_t s) : node(parent, FT_FILE) {
size = 0;
own_data = false;
data = d;
if (d != 0) size = s;
}
vfile::~vfile() {
if (own_data) kfree(data);
}
int vfile::read(size_t offset, size_t len, char* buffer) {
if (offset + len > size) len = size - offset;
memcpy(buffer, data + offset, len);
return len;
}
int vfile::write(size_t offset, size_t len, char* buffer) {
size_t new_size = MAX(offset + len, size);
if (!own_data || new_size > size) {
char* new_data = (char*)kmalloc(new_size);
memcpy(new_data, data, size);
if (new_size > size) memset(new_data + size, 0, new_size - size);
if (own_data) kfree(data);
data = new_data;
size = new_size;
own_data = true;
}
memcpy(data + offset, buffer, len);
return len;
}
|