-/* Copyright (c) 2012-2014, Bastien Dejean
+/* Copyright (c) 2012, Bastien Dejean
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those
- * of the authors and should not be interpreted as representing official policies,
- * either expressed or implied, of the FreeBSD Project.
*/
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
#include <math.h>
#include "bspwm.h"
exit(EXIT_FAILURE);
}
+char *read_string(const char *file_path, size_t *tlen)
+{
+ if (file_path == NULL) {
+ return NULL;
+ }
+
+ int fd = open(file_path, O_RDONLY);
+
+ if (fd == -1) {
+ perror("Read file: open");
+ return NULL;
+ }
+
+ char buf[BUFSIZ], *content;
+ size_t len = sizeof(buf);
+
+ if ((content = malloc(len * sizeof(char))) == NULL) {
+ perror("Read file: malloc");
+ return NULL;
+ }
+
+ int nb;
+ *tlen = 0;
+
+ while (true) {
+ nb = read(fd, buf, sizeof(buf));
+ if (nb < 0) {
+ perror("Restore tree: read");
+ free(content);
+ return NULL;
+ } else if (nb == 0) {
+ break;
+ } else {
+ *tlen += nb;
+ if (*tlen > len) {
+ len *= 2;
+ char *rcontent = realloc(content, len * sizeof(char));
+ if (rcontent == NULL) {
+ perror("Read file: realloc");
+ free(content);
+ return NULL;
+ } else {
+ content = rcontent;
+ }
+ }
+ strncpy(content + (*tlen - nb), buf, nb);
+ }
+ }
+
+ return content;
+}
+
bool get_color(char *col, xcb_window_t win, uint32_t *pxl)
{
xcb_colormap_t map = screen->default_colormap;
{
return hypot(a.x - b.x, a.y - b.y);
}
-
-void center_rectangle(xcb_rectangle_t *src, xcb_rectangle_t dst)
-{
- src->x = dst.x + (dst.width - src->width) / 2;
- src->y = dst.y + (dst.height - src->height) / 2;
-}