WIP: NOT WORKING: read_file()
This commit is contained in:
parent
df294bd780
commit
0396f8039b
8
Makefile
8
Makefile
|
@ -42,7 +42,7 @@ NTHREADS= $(shell nproc)
|
|||
CC=gcc
|
||||
WARNINGS= -Wall
|
||||
DEBUG= -ggdb -fno-omit-frame-pointer -fdiagnostics-color=always
|
||||
OPTIMIZE= -O2
|
||||
OPTIMIZE= -O3
|
||||
INCLUDE= $(shell pkg-config --cflags glib-2.0 libxml-2.0 gtk4)
|
||||
LIBS= $(shell pkg-config --libs glib-2.0 libxml-2.0 gtk4) -lGL -lGLU -lm -lepoxy -lX11 -lGLEW
|
||||
|
||||
|
@ -121,6 +121,12 @@ run: build_system
|
|||
@$(BINDIR)/gem-graph-client
|
||||
@echo -e ${CL2}[$@] ${CL}done.${CL3}
|
||||
|
||||
debug: build_system
|
||||
@echo -e ${CL2}[$@] ${CL}executing...${CL3}
|
||||
@gdb $(BINDIR)/gem-graph-client
|
||||
@echo -e ${CL2}[$@] ${CL}done.${CL3}
|
||||
|
||||
all: build_system
|
||||
@echo -e ${CL2}[$@] ${CL}done.${CL3}
|
||||
|
||||
|
||||
|
|
|
@ -49,17 +49,19 @@ enum
|
|||
*/
|
||||
static inline bool read_file(char *filename, char **contents)
|
||||
{
|
||||
int fd = open(filename, O_RDONLY);
|
||||
int fd;
|
||||
int filesize;
|
||||
|
||||
fd = open(filename, O_RDONLY);
|
||||
if(fd < 0) {
|
||||
printf("Couldn't read file: %s\n",filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
int filesize = lseek(fd, 0, SEEK_END) +1 ;
|
||||
*contents = malloc(sizeof(char) * filesize);
|
||||
filesize = lseek(fd, 0, SEEK_END) +1 ;
|
||||
*contents = calloc(filesize, sizeof(char));
|
||||
|
||||
if (errno) {
|
||||
if (contents == NULL) {
|
||||
perror("Not enough memory to allocate file");
|
||||
return false;
|
||||
}
|
||||
|
@ -67,7 +69,7 @@ static inline bool read_file(char *filename, char **contents)
|
|||
lseek(fd, 0, SEEK_SET);
|
||||
read(fd,*contents,filesize);
|
||||
|
||||
*contents[filesize-1]='\0';
|
||||
*(contents+filesize-1)='\0';
|
||||
|
||||
close(fd);
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
"gcc-toolchain"
|
||||
"pkg-config"
|
||||
"findutils"
|
||||
"gdb"
|
||||
"make"
|
||||
"gtk"
|
||||
"libxml2"
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
/*
|
||||
* Dynamic array of ptr to dynamically allocated gl_area_entry
|
||||
*/
|
||||
static struct gl_area_entry **gl_area_array = NULL;
|
||||
struct gl_area_entry **gl_area_array = NULL;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -495,7 +495,8 @@ bool graphics_init(void *gl_area)
|
|||
gl_area_array = calloc(2, sizeof(struct gl_area_entry *));
|
||||
|
||||
// check if an error occured during allocation
|
||||
if (errno) {
|
||||
if (gl_area_array == NULL) {
|
||||
printf("gl_area_array : %p", gl_area_array);
|
||||
perror("Not enough memory to allocate gl_area_array");
|
||||
return false;
|
||||
}
|
||||
|
@ -505,16 +506,19 @@ bool graphics_init(void *gl_area)
|
|||
gl_area_array = realloc(gl_area_array,
|
||||
(array_size + 1)
|
||||
* sizeof(struct gl_area_entry *));
|
||||
if (errno) {
|
||||
if (gl_area_array == NULL) {
|
||||
perror("Not enough memory to allocate gl_area_array");
|
||||
return false;
|
||||
}
|
||||
|
||||
explicit_bzero(gl_area_array + array_size * sizeof(struct gl_area_entry *),
|
||||
sizeof(struct gl_area_entry *));
|
||||
}
|
||||
|
||||
// Alloc new entry
|
||||
gl_area_array[array_size] = calloc(1, sizeof(struct gl_area_entry));
|
||||
|
||||
if (errno) {
|
||||
if (gl_area_array[array_size] == NULL) {
|
||||
perror("Not enough memory to allocate gl_area_array entry");
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue