mirror of https://github.com/bjornbytes/lovr.git
Clean up util;
This commit is contained in:
parent
91f46929fe
commit
be13d761e7
35
src/util.c
35
src/util.c
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue