Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

libgen_emu.cc

Go to the documentation of this file.
00001 #include "libgen_emu.h"
00002 #ifdef PLATFORM_APERIOS
00003 #include <sys/syslimits.h> // limits.h doesn't have PATH_MAX
00004 #else
00005 #include <limits.h>
00006 #endif
00007 #include <string.h>
00008 
00009 static char staticStorage[PATH_MAX];
00010 
00011 char* libgenEmu_basename(const char* path){
00012   char* buffer = staticStorage;
00013   if (path == '\0' || path[0] == '\0'){
00014     // NULL pointer or empty string
00015     strcpy(buffer, ".");
00016     return buffer;
00017   }else if (path[1] == '\0' && path[0] == '/'){
00018     // path is "/"
00019     strcpy(buffer, "/");
00020     return buffer;
00021   }else{
00022     strcpy(buffer, path);
00023     char* ptr = buffer + strlen(buffer);
00024     ptr--;
00025     // delete all trailing '/'
00026     while (ptr >= buffer && *ptr == '/'){
00027       *ptr = '\0';
00028       ptr--;
00029     }
00030     // scan backwards for '/'
00031     while (ptr >= buffer){
00032       if (*ptr == '/') return ++ptr;
00033       ptr--;
00034     }
00035     return buffer;
00036   }
00037 }

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:43 2016 by Doxygen 1.6.3