src/filesystem/unix/SDL_sysfilesystem.c
changeset 7713 6074c53b0cda
parent 7697 678f71df2c6b
child 7714 1c227c5f5d8d
equal deleted inserted replaced
7712:66b5b8446275 7713:6074c53b0cda
   154      *  in any case.
   154      *  in any case.
   155      *
   155      *
   156      * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
   156      * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
   157      */
   157      */
   158     const char *envr = SDL_getenv("XDG_DATA_HOME");
   158     const char *envr = SDL_getenv("XDG_DATA_HOME");
   159     const char *append = "/";
   159     const char *append;
   160     char *retval = NULL;
   160     char *retval = NULL;
   161     char *ptr = NULL;
   161     char *ptr = NULL;
   162     size_t len = 0;
   162     size_t len = 0;
   163 
   163 
   164     if (!envr) {
   164     if (!envr) {
   167         if (!envr) {
   167         if (!envr) {
   168             /* we could take heroic measures with /etc/passwd, but oh well. */
   168             /* we could take heroic measures with /etc/passwd, but oh well. */
   169             SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
   169             SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
   170             return NULL;
   170             return NULL;
   171         }
   171         }
   172         if (envr[SDL_strlen(envr) - 1] == '/') {
   172         append = "/.local/share/";
   173             append = ".local/share/";
       
   174         } else {
       
   175             append = "/.local/share/";
       
   176         }
       
   177     } else {
   173     } else {
   178         if (envr[SDL_strlen(envr) - 1] == '/') {
   174         append = "/";
   179             append = "";
       
   180         }
       
   181     } /* if */
   175     } /* if */
   182 
   176 
   183     len = SDL_strlen(envr) + SDL_strlen(append) + SDL_strlen(app) + 2;
   177     len = SDL_strlen(envr);
       
   178     if (envr[len - 1] == '/')
       
   179         append += 1;
       
   180 
       
   181     len += SDL_strlen(append) + SDL_strlen(app) + 2;
   184     retval = (char *) SDL_malloc(len);
   182     retval = (char *) SDL_malloc(len);
   185     if (!retval) {
   183     if (!retval) {
   186         SDL_OutOfMemory();
   184         SDL_OutOfMemory();
   187         return NULL;
   185         return NULL;
   188     }
   186     }