src/log.c: refactor code by using log_open()
This commit is contained in:
parent
b849bcfd8f
commit
dad8bd370a
1 changed files with 5 additions and 14 deletions
19
src/log.c
19
src/log.c
|
@ -74,16 +74,10 @@ FILE *log_open_default(const char*default_filename, const int mode)
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
path = getenv("HOMEPATH");
|
path = getenv("HOMEPATH");
|
||||||
if(path == NULL)
|
if(path == NULL)
|
||||||
{
|
return log_open(default_filename, mode);
|
||||||
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 */
|
/* Check to avoid buffer overflow may not be 100% bullet proof */
|
||||||
if(strlen(path)+strlen(default_filename)+2 > 4096)
|
if(strlen(path)+strlen(default_filename)+2 > 4096)
|
||||||
{
|
return log_open(default_filename, mode);
|
||||||
log_handle=fopen(default_filename,(mode==TD_LOG_CREATE?"w":"a"));
|
|
||||||
return log_handle;
|
|
||||||
}
|
|
||||||
filename=(char*)MALLOC(4096);
|
filename=(char*)MALLOC(4096);
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
/* FIXME */
|
/* FIXME */
|
||||||
|
@ -93,7 +87,7 @@ FILE *log_open_default(const char*default_filename, const int mode)
|
||||||
#endif
|
#endif
|
||||||
strcat(filename, "/");
|
strcat(filename, "/");
|
||||||
strcat(filename, default_filename);
|
strcat(filename, default_filename);
|
||||||
log_handle=fopen(filename,(mode==TD_LOG_CREATE?"w":"a"));
|
log_open(filename, mode);
|
||||||
free(filename);
|
free(filename);
|
||||||
return log_handle;
|
return log_handle;
|
||||||
}
|
}
|
||||||
|
@ -104,15 +98,12 @@ FILE *log_open_default(const char*default_filename, const int mode)
|
||||||
char *path;
|
char *path;
|
||||||
path = getenv("HOME");
|
path = getenv("HOME");
|
||||||
if(path == NULL)
|
if(path == NULL)
|
||||||
{
|
return log_open(default_filename, mode);
|
||||||
log_handle=fopen(default_filename,(mode==TD_LOG_CREATE?"w":"a"));
|
|
||||||
return log_handle;
|
|
||||||
}
|
|
||||||
filename=(char*)MALLOC(strlen(path)+strlen(default_filename)+2);
|
filename=(char*)MALLOC(strlen(path)+strlen(default_filename)+2);
|
||||||
strcpy(filename, path);
|
strcpy(filename, path);
|
||||||
strcat(filename, "/");
|
strcat(filename, "/");
|
||||||
strcat(filename, default_filename);
|
strcat(filename, default_filename);
|
||||||
log_handle=fopen(filename,(mode==TD_LOG_CREATE?"w":"a"));
|
log_open(default_filename, mode);
|
||||||
free(filename);
|
free(filename);
|
||||||
return log_handle;
|
return log_handle;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue