comparison util.c @ 2215:a8af8d898a7c

Fix windows build for real
author Michael Pavone <pavone@retrodev.com>
date Tue, 30 Aug 2022 00:13:55 -0700
parents bdd83b47d78a
children 1a3991ada927
comparison
equal deleted inserted replaced
2214:7591c67b8d1e 2215:a8af8d898a7c
26 #define info_printf(msg, args) vprintf(msg, args) 26 #define info_printf(msg, args) vprintf(msg, args)
27 #define warning_printf(msg, args) vfprintf(stderr, msg, args) 27 #define warning_printf(msg, args) vfprintf(stderr, msg, args)
28 #define fatal_printf(msg, args) vfprintf(stderr, msg, args) 28 #define fatal_printf(msg, args) vfprintf(stderr, msg, args)
29 #endif 29 #endif
30 30
31 #include "blastem.h" //for headless global
32 #include "render.h" //for render_errorbox
33 #include "util.h" 31 #include "util.h"
32
33 void render_errorbox(char *title, char *message);
34 void render_warnbox(char *title, char *message);
35 void render_infobox(char *title, char *message);
36 extern int headless;
34 37
35 char * alloc_concat(char const * first, char const * second) 38 char * alloc_concat(char const * first, char const * second)
36 { 39 {
37 int flen = strlen(first); 40 int flen = strlen(first);
38 int slen = strlen(second); 41 int slen = strlen(second);
347 lastslash = path; 350 lastslash = path;
348 } 351 }
349 char *barename = malloc(lastdot-lastslash+1); 352 char *barename = malloc(lastdot-lastslash+1);
350 memcpy(barename, lastslash, lastdot-lastslash); 353 memcpy(barename, lastslash, lastdot-lastslash);
351 barename[lastdot-lastslash] = 0; 354 barename[lastdot-lastslash] = 0;
352 355
353 return barename; 356 return barename;
354 } 357 }
355 358
356 char *path_extension(char const *path) 359 char *path_extension(char const *path)
357 { 360 {
405 return NULL; 408 return NULL;
406 } 409 }
407 char *dir = malloc(lastslash-path+1); 410 char *dir = malloc(lastslash-path+1);
408 memcpy(dir, path, lastslash-path); 411 memcpy(dir, path, lastslash-path);
409 dir[lastslash-path] = 0; 412 dir[lastslash-path] = 0;
410 413
411 return dir; 414 return dir;
412 } 415 }
413 416
414 uint32_t nearest_pow2(uint32_t val) 417 uint32_t nearest_pow2(uint32_t val)
415 { 418 {
628 if (numret) { 631 if (numret) {
629 *numret = 0; 632 *numret = 0;
630 } 633 }
631 return NULL; 634 return NULL;
632 } 635 }
633 636
634 size_t storage = 64; 637 size_t storage = 64;
635 ret = malloc(sizeof(dir_entry) * storage); 638 ret = malloc(sizeof(dir_entry) * storage);
636 size_t pos = 0; 639 size_t pos = 0;
637 640
638 if (path[1] == ':' && (!path[2] || (path[2] == PATH_SEP[0] && !path[3]))) { 641 if (path[1] == ':' && (!path[2] || (path[2] == PATH_SEP[0] && !path[3]))) {
639 //we are in the root of a drive, add a virtual .. entry 642 //we are in the root of a drive, add a virtual .. entry
640 //for navigating to the virtual root directory 643 //for navigating to the virtual root directory
641 ret[pos].name = strdup(".."); 644 ret[pos].name = strdup("..");
642 ret[pos++].is_dir = 1; 645 ret[pos++].is_dir = 1;
643 } 646 }
644 647
645 do { 648 do {
646 if (pos == storage) { 649 if (pos == storage) {
647 storage = storage * 2; 650 storage = storage * 2;
648 ret = realloc(ret, sizeof(dir_entry) * storage); 651 ret = realloc(ret, sizeof(dir_entry) * storage);
649 } 652 }
650 ret[pos].name = strdup(file.cFileName); 653 ret[pos].name = strdup(file.cFileName);
651 ret[pos++].is_dir = (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; 654 ret[pos++].is_dir = (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
652 } while (FindNextFile(dir, &file)); 655 } while (FindNextFile(dir, &file));
653 656
654 FindClose(dir); 657 FindClose(dir);
655 if (numret) { 658 if (numret) {
656 *numret = pos; 659 *numret = pos;
657 } 660 }
658 } 661 }
1072 char const *get_config_dir() 1075 char const *get_config_dir()
1073 { 1076 {
1074 static char* confdir; 1077 static char* confdir;
1075 if (!confdir) { 1078 if (!confdir) {
1076 char const *base = get_userdata_dir(); 1079 char const *base = get_userdata_dir();
1077 if (base) { 1080 if (base) {
1078 confdir = alloc_concat(base, PATH_SEP "blastem"); 1081 confdir = alloc_concat(base, PATH_SEP "blastem");
1079 } 1082 }
1080 } 1083 }
1081 return confdir; 1084 return confdir;
1082 } 1085 }