Only allocate the necessary amount of memory

SVN revision: 17273
This commit is contained in:
sebastid 2005-10-07 17:32:31 +00:00 committed by sebastid
parent ef76553dc0
commit fb2ab4ef6c
1 changed files with 15 additions and 7 deletions

View File

@ -381,14 +381,22 @@ ecore_file_app_exe_get(const char *app)
char *
ecore_file_strip_ext(const char *path)
{
char *p, *file;
char *p, *file = NULL;
file = strdup(path);
if (!file) return NULL;
p = strrchr(file, '.');
if (p)
*p = 0;
p = strrchr(path, '.');
if (!p)
{
file = strdup(path);
}
else if (p != path)
{
file = malloc(((p - path) + 1) * sizeof(char));
if (file)
{
memcpy(file, path, (p - path));
file[p - path] = 0;
}
}
return file;
}