comparison util.c @ 1140:4490c9c12272

Detect system type from filename if header based methods fail. Allow overriding system type from command line.
author Michael Pavone <pavone@retrodev.com>
date Mon, 02 Jan 2017 21:46:26 -0800
parents 160e3f597cec
children a344885e7c79
comparison
equal deleted inserted replaced
1139:160e3f597cec 1140:4490c9c12272
145 char *barename = malloc(lastdot-lastslash+1); 145 char *barename = malloc(lastdot-lastslash+1);
146 memcpy(barename, lastslash, lastdot-lastslash); 146 memcpy(barename, lastslash, lastdot-lastslash);
147 barename[lastdot-lastslash] = 0; 147 barename[lastdot-lastslash] = 0;
148 148
149 return barename; 149 return barename;
150 }
151
152 char *path_extension(char *path)
153 {
154 char *lastdot = NULL;
155 char *lastslash = NULL;
156 char *cur;
157 for (cur = path; *cur; cur++)
158 {
159 if (*cur == '.') {
160 lastdot = cur;
161 } else if (is_path_sep(*cur)) {
162 lastslash = cur + 1;
163 }
164 }
165 if (!lastdot || (lastslash && lastslash > lastdot)) {
166 //no extension
167 return NULL;
168 }
169 return strdup(lastdot+1);
150 } 170 }
151 171
152 uint32_t nearest_pow2(uint32_t val) 172 uint32_t nearest_pow2(uint32_t val)
153 { 173 {
154 uint32_t ret = 1; 174 uint32_t ret = 1;
522 } 542 }
523 543
524 #ifdef __ANDROID__ 544 #ifdef __ANDROID__
525 545
526 #include <SDL.h> 546 #include <SDL.h>
527 char *read_bundled_file(char *name, long *sizeret) 547 char *read_bundled_file(char *name, uint32_t *sizeret)
528 { 548 {
529 SDL_RWops *rw = SDL_RWFromFile(name, "rb"); 549 SDL_RWops *rw = SDL_RWFromFile(name, "rb");
530 if (!rw) { 550 if (!rw) {
531 if (sizeret) { 551 if (sizeret) {
532 *sizeret = -1; 552 *sizeret = -1;
562 return SDL_AndroidGetInternalStoragePath(); 582 return SDL_AndroidGetInternalStoragePath();
563 } 583 }
564 584
565 #else 585 #else
566 586
567 char *read_bundled_file(char *name, long *sizeret) 587 char *read_bundled_file(char *name, uint32_t *sizeret)
568 { 588 {
569 char *exe_dir = get_exe_dir(); 589 char *exe_dir = get_exe_dir();
570 if (!exe_dir) { 590 if (!exe_dir) {
571 if (sizeret) { 591 if (sizeret) {
572 *sizeret = -1; 592 *sizeret = -1;