}
static Eina_Bool
-_screen_recorder_fullpath_make_with_ext(char *out, const char *filename)
+_screen_recorder_fullpath_make_with_ext(char out[PATH_MAX], const char *filename)
{
- char cwd[PATH_MAX], fname_with_ext[PATH_MAX] = {0,};
+ char cwd[PATH_MAX], fullname[PATH_MAX] = {0,};
char *dot;
const char *ext = ".mp4";
const char *prefix = "e-screen-record";
- int len;
+ int len_l, len;
+ len_l = PATH_MAX;
if (filename)
{
- dot = strrchr(filename, '.');
- if ((!dot) || (strlen(dot + 1) !=3) || (strncmp(dot, ext, strlen(ext)) != 0))
+ if (filename[0] != '/')
{
- /* concatenate file extention. */
- len = strnlen(filename, PATH_MAX - 4);
- strncat(fname_with_ext, filename, len);
- strncat(fname_with_ext, ext, 4);
+ if (!getcwd(cwd, sizeof(cwd)))
+ snprintf(cwd, sizeof(cwd), "/tmp");
+
+ len = snprintf(fullname, len_l, "%s/%s", cwd, filename);
}
else
+ len = snprintf(fullname, len_l, "%s", filename);
+
+ len_l -= len;
+ if (len_l <= 0)
{
- strncat(fname_with_ext, filename, (PATH_MAX - 1));
- fname_with_ext[PATH_MAX - 1] = '\0';
+ ERR("file name is too long");
+ return EINA_FALSE;
}
- if (fname_with_ext[0] != '/')
+ dot = strrchr(fullname, '.');
+ len = strlen(ext);
+ if ((!dot) ||
+ (strlen(dot) != len) ||
+ (strncmp(dot, ext, len) != 0))
{
- /* concatenate current working directory or '/tmp'. */
- if (!getcwd(cwd, sizeof(cwd)))
- snprintf(cwd, sizeof(cwd), "/tmp");
- snprintf(out, PATH_MAX, "%s/%s", cwd, fname_with_ext);
+ /* concatenate file extention. */
+ if (len_l < (len + 1))
+ {
+ ERR("file name is too long");
+ return EINA_FALSE;
+ }
+
+ strncat(fullname, ext, len);
}
- else
- strncpy(out, fname_with_ext, PATH_MAX);
+
+ strncpy(out, fullname, PATH_MAX);
}
else
{
if (!getcwd(cwd, sizeof(cwd)))
snprintf(cwd, sizeof(cwd), "/tmp");
- snprintf(out, PATH_MAX, "%s/%s-%04d%02d%02d.%02d%02d%02d%s",
- cwd, prefix,
- t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour,
- t->tm_min, t->tm_sec,
- ext);
- out[PATH_MAX - 1] = '\0';
+ len = snprintf(fullname, len_l, "%s/%s-%04d%02d%02d.%02d%02d%02d",
+ cwd, prefix,
+ t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour,
+ t->tm_min, t->tm_sec);
+ len_l -= len;
+
+ len = strlen(ext);
+ if ((len + 1) > len_l)
+ fullname[PATH_MAX - (len + 1)] = '\0';
+
+ strncat(fullname, ext, len);
+ strncpy(out, fullname, PATH_MAX);
}
return EINA_TRUE;