libgen_emu.cc
Go to the documentation of this file.00001 #include "libgen_emu.h"
00002 #ifdef PLATFORM_APERIOS
00003 #include <sys/syslimits.h>
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
00015 strcpy(buffer, ".");
00016 return buffer;
00017 }else if (path[1] == '\0' && path[0] == '/'){
00018
00019 strcpy(buffer, "/");
00020 return buffer;
00021 }else{
00022 strcpy(buffer, path);
00023 char* ptr = buffer + strlen(buffer);
00024 ptr--;
00025
00026 while (ptr >= buffer && *ptr == '/'){
00027 *ptr = '\0';
00028 ptr--;
00029 }
00030
00031 while (ptr >= buffer){
00032 if (*ptr == '/') return ++ptr;
00033 ptr--;
00034 }
00035 return buffer;
00036 }
00037 }