Clean up util;

This commit is contained in:
bjorn 2016-11-07 22:20:39 -08:00
parent 91f46929fe
commit be13d761e7
2 changed files with 0 additions and 37 deletions

View File

@ -1,14 +1,7 @@
#include "util.h"
#include <stdarg.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#ifdef __APPLE__
#include <unistd.h>
#else
#include <io.h>
#endif
void error(const char* format, ...) {
va_list args;
@ -19,34 +12,6 @@ void error(const char* format, ...) {
exit(EXIT_FAILURE);
}
int fileExists(char* filename) {
return access(filename, 0) != -1;
}
char* loadFile(char* filename) {
struct stat info;
if (stat(filename, &info)) {
error("Could not stat '%s'", filename);
}
int size = (int)info.st_size;
char* buffer = malloc(size + 1);
int fd = open(filename, O_RDONLY);
if (fd < 0) {
error("Could not open '%s'", filename);
}
if (read(fd, buffer, size) < 0) {
error("Could not read '%s'", filename);
}
buffer[size] = '\0';
return buffer;
}
int luaPreloadModule(lua_State* L, const char* key, lua_CFunction f) {
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");

View File

@ -12,8 +12,6 @@ typedef vec_t(unsigned int) vec_uint_t;
#endif
void error(const char* format, ...);
int fileExists(char* filename);
char* loadFile(char* filename);
void luaRegisterModule(lua_State* L, const char* name, const luaL_Reg* module);
void luaRegisterType(lua_State* L, const char* name, const luaL_Reg* functions, lua_CFunction gc);
int luaPreloadModule(lua_State* L, const char* key, lua_CFunction f);