git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

SDL/utils.c

      1 #include <SDL.h>
      2 #include <stdio.h>
      3 #include <string.h>
      4 #include <unistd.h>
      5 #include <limits.h>
      6 #include "utils.h"
      7 
      8 static const char *resource_folder(void)
      9 {
     10     static const char *ret = NULL;
     11     if (!ret) {
     12         ret = SDL_GetBasePath();
     13         if (!ret) {
     14             ret = "./";
     15         }
     16     }
     17     return ret;
     18 }
     19 
     20 char *resource_path(const char *filename)
     21 {
     22     static char path[PATH_MAX + 1];
     23    
     24     snprintf(path, sizeof(path), "%s%s", resource_folder(), filename);
     25 #ifdef DATA_DIR
     26     if (access(path, F_OK) == 0) {
     27         return path;
     28     }
     29     snprintf(path, sizeof(path), "%s%s", DATA_DIR, filename);
     30 #endif
     31     return path;
     32 }
     33 
     34 
     35 void replace_extension(const char *src, size_t length, char *dest, const char *ext)
     36 {
     37     memcpy(dest, src, length);
     38     dest[length] = 0;
     39 
     40     /* Remove extension */
     41     for (size_t i = length; i--;) {
     42         if (dest[i] == '/') break;
     43         if (dest[i] == '.') {
     44             dest[i] = 0;
     45             break;
     46         }
     47     }
     48 
     49     /* Add new extension */
     50     strcat(dest, ext);
     51 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.