annotate util.c @ 792:724bbec47f86

Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
author Michael Pavone <pavone@retrodev.com>
date Sat, 25 Jul 2015 18:22:07 -0700
parents 13d3744b170e
children 792be135d3af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <string.h>
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <stdlib.h>
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include <stdio.h>
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include <ctype.h>
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 762
diff changeset
5 #include <stdint.h>
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
7 #include <sys/types.h>
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
8 #include <sys/stat.h>
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
9 #include <unistd.h>
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
10
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
11 #include "blastem.h" //for headless global
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
12 #include "render.h" //for render_errorbox
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
13
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 char * alloc_concat(char * first, char * second)
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15 {
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16 int flen = strlen(first);
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 int slen = strlen(second);
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18 char * ret = malloc(flen + slen + 1);
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 memcpy(ret, first, flen);
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20 memcpy(ret+flen, second, slen+1);
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
21 return ret;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
22 }
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24 char * alloc_concat_m(int num_parts, char ** parts)
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
25 {
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
26 int total = 0;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
27 for (int i = 0; i < num_parts; i++) {
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
28 total += strlen(parts[i]);
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
29 }
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
30 char * ret = malloc(total + 1);
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
31 *ret = 0;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
32 for (int i = 0; i < num_parts; i++) {
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
33 strcat(ret, parts[i]);
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
34 }
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
35 return ret;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
36 }
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
37
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
38 long file_size(FILE * f)
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
39 {
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
40 fseek(f, 0, SEEK_END);
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
41 long fsize = ftell(f);
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
42 fseek(f, 0, SEEK_SET);
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
43 return fsize;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
44 }
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
45
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
46 char * strip_ws(char * text)
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
47 {
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
48 while (*text && (!isprint(*text) || isblank(*text)))
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
49 {
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
50 text++;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
51 }
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 char * ret = text;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
53 text = ret + strlen(ret) - 1;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
54 while (text > ret && (!isprint(*text) || isblank(*text)))
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
55 {
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
56 *text = 0;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
57 text--;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
58 }
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
59 return ret;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
60 }
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
61
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
62 char * split_keyval(char * text)
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
63 {
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
64 while (*text && !isblank(*text))
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
65 {
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
66 text++;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 }
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 if (!*text) {
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 return text;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
70 }
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71 *text = 0;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
72 return text+1;
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
73 }
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
74
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 762
diff changeset
75 uint32_t nearest_pow2(uint32_t val)
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 762
diff changeset
76 {
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 762
diff changeset
77 uint32_t ret = 1;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 762
diff changeset
78 while (ret < val)
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 762
diff changeset
79 {
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 762
diff changeset
80 ret = ret << 1;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 762
diff changeset
81 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 762
diff changeset
82 return ret;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 762
diff changeset
83 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 762
diff changeset
84
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
85 static char * exe_str;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
86
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
87 void set_exe_str(char * str)
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
88 {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
89 exe_str = str;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
90 }
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
91
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
92 void fatal_error(char *format, ...)
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
93 {
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
94 va_list args;
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
95 va_start(args, format);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
96 if (!headless) {
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
97 //take a guess at the final size
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
98 size_t size = strlen(format) * 2;
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
99 char *buf = malloc(size);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
100 size_t actual = vsnprintf(buf, size, format, args);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
101 if (actual >= size) {
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
102 actual++;
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
103 free(buf);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
104 buf = malloc(actual);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
105 va_end(args);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
106 va_start(args, format);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
107 vsnprintf(buf, actual, format, args);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
108 }
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
109 fputs(buf, stderr);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
110 render_errorbox("Fatal Error", buf);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
111 free(buf);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
112 } else {
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
113 vfprintf(stderr, format, args);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
114 }
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
115 va_end(args);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
116 exit(1);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
117 }
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
118
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
119 void info_message(char *format, ...)
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
120 {
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
121 va_list args;
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
122 va_start(args, format);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
123 #ifndef _WIN32
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
124 if (headless || (isatty(STDOUT_FILENO) && isatty(STDIN_FILENO))) {
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
125 vprintf(format, args);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
126 } else {
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
127 #endif
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
128 size_t size = strlen(format) * 2;
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
129 char *buf = malloc(size);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
130 size_t actual = vsnprintf(buf, size, format, args);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
131 if (actual >= size) {
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
132 actual++;
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
133 free(buf);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
134 buf = malloc(actual);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
135 va_end(args);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
136 va_start(args, format);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
137 vsnprintf(buf, actual, format, args);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
138 }
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
139 fputs(buf, stdout);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
140 render_infobox("BlastEm Info", buf);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
141 free(buf);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
142 #ifndef _WIN32
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
143 }
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
144 #endif
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
145 va_end(args);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
146 }
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 773
diff changeset
147
742
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
148 #ifdef _WIN32
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
149 #include "Shlobj.h"
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
150 #include "Windows.h"
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
151
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
152 char * get_home_dir()
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
153 {
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
154 static char path[MAX_PATH];
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
155 SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, path);
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
156 return path;
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
157 }
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
158
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
159 char * get_exe_dir()
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
160 {
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
161 static char path[MAX_PATH];
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
162 HMODULE module = GetModuleHandleA(NULL);
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
163 GetModuleFileNameA(module, path, MAX_PATH);
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
164
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
165 int pathsize = strlen(path);
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
166 for(char * cur = path + pathsize - 1; cur != path; cur--)
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
167 {
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
168 if (*cur == '\\') {
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
169 *cur = 0;
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
170 break;
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
171 }
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
172 }
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
173 return path;
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
174 }
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
175
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
176 #else
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
177
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
178 char * get_home_dir()
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
179 {
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
180 return getenv("HOME");
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
181 }
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
182
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
183 char * readlink_alloc(char * path)
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
184 {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
185 char * linktext = NULL;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
186 ssize_t linksize = 512;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
187 ssize_t cursize = 0;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
188 do {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
189 if (linksize > cursize) {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
190 cursize = linksize;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
191 if (linktext) {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
192 free(linktext);
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
193 }
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
194 }
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
195 linktext = malloc(cursize);
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
196 linksize = readlink(path, linktext, cursize-1);
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
197 if (linksize == -1) {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
198 perror("readlink");
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
199 free(linktext);
559
6b248602ab84 blastem builds and almost works on OS X now
Mike Pavone <pavone@retrodev.com>
parents: 549
diff changeset
200 return NULL;
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
201 }
549
32da1e0d5e55 Properly null terminate string returned by readlink in util.c
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
202 } while ((linksize+1) > cursize);
32da1e0d5e55 Properly null terminate string returned by readlink in util.c
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
203 linktext[linksize] = 0;
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
204 return linktext;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
205 }
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
206
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
207 char * get_exe_dir()
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
208 {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
209 static char * exe_dir;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
210 if (!exe_dir) {
762
206c449eaa81 Get "portable" builds working on Linux and add a build time check for whether /proc exists
Michael Pavone <pavone@retrodev.com>
parents: 744
diff changeset
211 char * cur;
763
2a25ea5d94f7 Fix sense of HAS_PROC check
Michael Pavone <pavone@retrodev.com>
parents: 762
diff changeset
212 #ifdef HAS_PROC
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
213 char * linktext = readlink_alloc("/proc/self/exe");
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
214 if (!linktext) {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
215 goto fallback;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
216 }
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
217 int linksize = strlen(linktext);
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
218 for(cur = linktext + linksize - 1; cur != linktext; cur--)
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
219 {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
220 if (*cur == '/') {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
221 *cur = 0;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
222 break;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
223 }
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
224 }
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
225 if (cur == linktext) {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
226 free(linktext);
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
227 fallback:
762
206c449eaa81 Get "portable" builds working on Linux and add a build time check for whether /proc exists
Michael Pavone <pavone@retrodev.com>
parents: 744
diff changeset
228 #endif
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
229 if (!exe_str) {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
230 fputs("/proc/self/exe is not available and set_exe_str was not called!", stderr);
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
231 }
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
232 int pathsize = strlen(exe_str);
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
233 for(cur = exe_str + pathsize - 1; cur != exe_str; cur--)
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
234 {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
235 if (*cur == '/') {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
236 exe_dir = malloc(cur-exe_str+1);
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
237 memcpy(exe_dir, exe_str, cur-exe_str);
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
238 exe_dir[cur-exe_str] = 0;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
239 break;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
240 }
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
241 }
763
2a25ea5d94f7 Fix sense of HAS_PROC check
Michael Pavone <pavone@retrodev.com>
parents: 762
diff changeset
242 #ifdef HAS_PROC
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
243 } else {
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
244 exe_dir = linktext;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
245 }
762
206c449eaa81 Get "portable" builds working on Linux and add a build time check for whether /proc exists
Michael Pavone <pavone@retrodev.com>
parents: 744
diff changeset
246 #endif
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
247 }
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
248 return exe_dir;
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
249 }
742
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
250
741
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 549
diff changeset
251 #endif