diff --git a/include/base.h b/include/base.h index 744aa22..0fae9da 100644 --- a/include/base.h +++ b/include/base.h @@ -76,43 +76,3 @@ struct arrow_t { uint load; uint site; uint x; uint y; uint z; }; #define SOUTH 4 // + z blue #define NORTH 5 // - z yellow - -/******************************************************************************/ -/* U T I L I T I E S */ -/******************************************************************************/ - -/* - * char *read_file(char *filename) - * reads a file from filename into a provided buffer - * - * @param filename, file name - * contents, target ptr - * - * @return void - */ -static inline char *read_file(char *filename) -{ - int fd; - int filesize; - char *contents; - - fd = open(filename, O_RDONLY); - if (fd < 0) { - printf("Couldn't read file: %s\n",filename); - return NULL; - } - - filesize = lseek(fd, 0, SEEK_END) + 1 ; - contents = g_malloc(filesize * sizeof(char)); - assert (contents); - - lseek(fd, 0, SEEK_SET); - read(fd,contents,filesize); - - contents[filesize-1] = '\0'; - - close(fd); - - return contents; -} - diff --git a/include/util.h b/include/util.h index 6087a3c..26c7666 100644 --- a/include/util.h +++ b/include/util.h @@ -78,3 +78,5 @@ void View(pile *); //------------------------------------------------------------------------------ void util_pile_test(); // def: scr/util/tests + +char *read_file(char *filename); diff --git a/src/graphics/init.c b/src/graphics/init.c index dca3d5a..7175222 100644 --- a/src/graphics/init.c +++ b/src/graphics/init.c @@ -28,6 +28,8 @@ #include "../../include/graphics.h" #include "../../include/parse.h" +#include "../../include/util.h" + #define TEST 0 diff --git a/src/util/io.c b/src/util/io.c new file mode 100644 index 0000000..1eb8d33 --- /dev/null +++ b/src/util/io.c @@ -0,0 +1,85 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * +* * +* Gem-graph client * +* * +* Base header * +* * +* Copyright © 2021 Libre en Communs * +* Copyright © 2021 Adrien Bourmault * +* Copyright © 2021 Jean Sirmai * +* * +* This file is part of Gem-graph. * +* * +* This program is free software: you can redistribute it and/or modify it * +* under the terms of the GNU Affero General Public License * +* as published by the Free Software Foundation, * +* either version 3 of the License, * +* or (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; * +* without even the implied warranty of MERCHANTABILITY * +* or FITNESS FOR A PARTICULAR PURPOSE. * +* See the GNU Affero General Public License for more details. * +* * +* You should have received a copy of the GNU Affero General Public License * +* along with this program. If not, see . * +* * +* * * * * * * * * * * * * * * * * * * * * * * * * * */ + + + +#include +#include +#include +#include +#include +#include +#include // Defines NULL. +#include +#include +#include +#include +#include + +//#include +//#include + +#include "../../include/util.h" + + +/* + * char *read_file(char *filename) + * reads a file from filename into a provided buffer + * + * @param filename, file name + * contents, target ptr + * + * @return void + */ +char *read_file(char *filename) +{ + int fd; + int filesize; + char *contents; + + fd = open(filename, O_RDONLY); + if (fd < 0) { + printf("Couldn't read file: %s\n",filename); + return NULL; + } + + filesize = lseek(fd, 0, SEEK_END) + 1 ; + contents = g_malloc(filesize * sizeof(char)); + assert (contents); + + lseek(fd, 0, SEEK_SET); + read(fd,contents,filesize); + + contents[filesize-1] = '\0'; + + close(fd); + + return contents; +} + diff --git a/src/widget/topbar/polytext.c b/src/widget/topbar/polytext.c index 6edd1a6..3c082f3 100644 --- a/src/widget/topbar/polytext.c +++ b/src/widget/topbar/polytext.c @@ -28,7 +28,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "../../../include/base.h" +#include "../../../include/util.h" #include "../../../include/signal.h" #include "../../../include/widget.h"