handle no home and buf overflow

This commit is contained in:
notaz 2013-10-10 02:41:45 +03:00
parent 62e581e179
commit af7e50060f

View file

@ -78,17 +78,19 @@ int plat_get_skin_dir(char *dst, int len)
#endif #endif
int plat_get_root_dir(char *dst, int len) int plat_get_root_dir(char *dst, int len)
{ {
#if defined(__GP2X__) || defined(PANDORA) #if !defined(__GP2X__) && !defined(PANDORA)
return plat_get_data_dir(dst, len); const char *home = getenv("HOME");
#else int ret;
char *home = getenv("HOME");
size_t nb = strlen(home);
memcpy(dst, home, nb); if (home != NULL) {
memcpy(dst + nb, PICO_HOME_DIR, sizeof PICO_HOME_DIR); ret = snprintf(dst, len, "%s%s", home, PICO_HOME_DIR);
mkdir(dst, 0755); if (ret >= len)
return nb + sizeof(PICO_HOME_DIR) - 1; ret = len - 1;
mkdir(dst, 0755);
return ret;
}
#endif #endif
return plat_get_data_dir(dst, len);
} }
#ifdef __GP2X__ #ifdef __GP2X__