delete the file API
This commit is contained in:
@@ -1,56 +0,0 @@
|
|||||||
#include "gryphn_file.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
// #include "fstream"
|
|
||||||
// #include "iostream"
|
|
||||||
|
|
||||||
gnFile gnLoadFile(const gnString path, gnFileType type) {
|
|
||||||
gnFile new_file = {
|
|
||||||
.path = path,
|
|
||||||
.type = type
|
|
||||||
};
|
|
||||||
|
|
||||||
if (type == GN_FILE_TEXT) {
|
|
||||||
new_file.data = malloc(sizeof(gnString));
|
|
||||||
*((gnString*)new_file.data) = gnCreateEmptyString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == GN_FILE_TEXT) {
|
|
||||||
FILE *fptr;
|
|
||||||
fptr = fopen(path.value, "r");
|
|
||||||
|
|
||||||
int ch;
|
|
||||||
if (fptr != NULL) {
|
|
||||||
while ((ch = fgetc(fptr)) != EOF) {
|
|
||||||
putchar(ch); // or process the char
|
|
||||||
}
|
|
||||||
fclose(fptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type == GN_FILE_BINARY) {
|
|
||||||
FILE *file = fopen(path.value, "rb");
|
|
||||||
if (file) {
|
|
||||||
fseek(file, 0, SEEK_END);
|
|
||||||
long size = ftell(file);
|
|
||||||
rewind(file);
|
|
||||||
char *buffer = malloc(size);
|
|
||||||
if (buffer) {
|
|
||||||
fread(buffer, 1, size, file);
|
|
||||||
// use buffer here
|
|
||||||
free(buffer);
|
|
||||||
}
|
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
gnString gnGetFileData(const gnFile file) { return *(gnString*)file.data;}
|
|
||||||
// why I dont just return the file as a list of lines, cuz thats the easy way this way revealed so many errors in my string class,
|
|
||||||
// dont you love it when you dont actually copy a string and then the data gets lost and you dont know why because your an idiot
|
|
||||||
// thats never happened to me...... yea so im an idiot shouve actually copied the bytes over not just haphazardly asigned them to a string.
|
|
||||||
|
|
||||||
gnString gnGetFilePath(const gnFile file) {
|
|
||||||
return file.path;
|
|
||||||
}
|
|
||||||
|
|
||||||
gnChar* gnGetFileBytes(const gnFile file) { return (gnChar*)file.data; }
|
|
@@ -1,29 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../strings/gryphn_string.h"
|
|
||||||
#include "../lists/gryphn_array_list.h"
|
|
||||||
|
|
||||||
typedef enum gnFileType {
|
|
||||||
GN_FILE_TEXT, GN_FILE_BINARY
|
|
||||||
} gnFileType;
|
|
||||||
|
|
||||||
typedef struct gnFile {
|
|
||||||
void* data;
|
|
||||||
// GN_FILE_TEXT = gnString
|
|
||||||
// GN_FILE_BINARY = gnChar*
|
|
||||||
gnString path;
|
|
||||||
gnFileType type;
|
|
||||||
} gnFile;
|
|
||||||
|
|
||||||
#ifdef GN_UITLS_CPP
|
|
||||||
gnFile gnLoadFile(const gnString& path, gnFileType type = GN_FILE_TEXT);
|
|
||||||
#else
|
|
||||||
gnFile gnLoadFile(const gnString path, gnFileType type);
|
|
||||||
#endif
|
|
||||||
// gnFile gnCreateFile(const gnString path);
|
|
||||||
// gnFile gnWriteFile(const gnFile file);
|
|
||||||
|
|
||||||
gnString gnGetFilePath(const gnFile file);
|
|
||||||
gnString gnGetFileData(const gnFile file); // i should rename this
|
|
||||||
gnChar* gnGetFileBytes(const gnFile file); // fuck object oriented code
|
|
||||||
// and fuck error detection the user can get the bytes of a text file if they want to cuz its slow to do error checking, its also smart but im slow
|
|
||||||
// so me and this project are one in the same
|
|
Reference in New Issue
Block a user