Improve log file creation
This commit is contained in:
parent
3ddcd18b95
commit
885e306eef
1 changed files with 15 additions and 5 deletions
20
src/log.c
20
src/log.c
|
@ -74,12 +74,19 @@ FILE *log_open_default(const char*default_filename, const int mode)
|
|||
if (path == NULL)
|
||||
path = getenv("HOMEPATH");
|
||||
if(path == NULL)
|
||||
return NULL;
|
||||
{
|
||||
log_handle=fopen(default_filename,(mode==TD_LOG_CREATE?"w":"a"));
|
||||
return log_handle;
|
||||
}
|
||||
/* Check to avoid buffer overflow may not be 100% bullet proof */
|
||||
if(strlen(path)+strlen(default_filename)+2 > 2048)
|
||||
return NULL;
|
||||
filename=(char*)MALLOC(2048);
|
||||
if(strlen(path)+strlen(default_filename)+2 > 4096)
|
||||
{
|
||||
log_handle=fopen(default_filename,(mode==TD_LOG_CREATE?"w":"a"));
|
||||
return log_handle;
|
||||
}
|
||||
filename=(char*)MALLOC(4096);
|
||||
#ifdef __CYGWIN__
|
||||
/* FIXME */
|
||||
cygwin_conv_to_posix_path(path, filename);
|
||||
#else
|
||||
strcpy(filename, path);
|
||||
|
@ -97,7 +104,10 @@ FILE *log_open_default(const char*default_filename, const int mode)
|
|||
char *path;
|
||||
path = getenv("HOME");
|
||||
if(path == NULL)
|
||||
return NULL;
|
||||
{
|
||||
log_handle=fopen(default_filename,(mode==TD_LOG_CREATE?"w":"a"));
|
||||
return log_handle;
|
||||
}
|
||||
filename=(char*)MALLOC(strlen(path)+strlen(default_filename)+2);
|
||||
strcpy(filename, path);
|
||||
strcat(filename, "/");
|
||||
|
|
Loading…
Reference in a new issue