Under Windows, if log file can't be created in current directory, try to create it in home directory.
This commit is contained in:
parent
58a7f8b4bf
commit
b1c51833ac
1 changed files with 38 additions and 12 deletions
50
src/log.c
50
src/log.c
|
@ -22,7 +22,13 @@
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_STDLIB_H
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#ifdef HAVE_STRING_H
|
||||||
|
#include <string.h>
|
||||||
|
#endif
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#ifdef HAVE_TIME_H
|
#ifdef HAVE_TIME_H
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
@ -57,21 +63,41 @@ int log_open(const char*default_filename, const int mode, const int ncurses_inte
|
||||||
const char*filename=default_filename;
|
const char*filename=default_filename;
|
||||||
if(mode!=TD_LOG_CREATE && mode!=TD_LOG_APPEND)
|
if(mode!=TD_LOG_CREATE && mode!=TD_LOG_APPEND)
|
||||||
return mode;
|
return mode;
|
||||||
do
|
log_handle=fopen(filename,(mode==TD_LOG_CREATE?"w":"a"));
|
||||||
|
if(log_handle==NULL && ncurses_interface==0)
|
||||||
{
|
{
|
||||||
log_handle=fopen(filename,(mode==TD_LOG_CREATE?"w":"a"));
|
printf("Can't create %s file\n", filename);
|
||||||
if(log_handle==NULL)
|
}
|
||||||
|
#if defined(__CYGWIN__) || defined(__MINGW32__)
|
||||||
|
if(log_handle==NULL)
|
||||||
|
{
|
||||||
|
char *path;
|
||||||
|
path = getenv("USERPROFILE");
|
||||||
|
if (path == NULL)
|
||||||
|
path = getenv("HOMEPATH");
|
||||||
|
if(path!=NULL)
|
||||||
{
|
{
|
||||||
if(ncurses_interface==0)
|
FILE*handle;
|
||||||
{
|
filename=(char*)MALLOC(strlen(path)+strlen(default_filename)+2);
|
||||||
printf("Can't create %s file\n", default_filename);
|
strcpy(filename, path);
|
||||||
return mode;
|
strcat(filename, "\\");
|
||||||
}
|
strcat(filename, default_filename);
|
||||||
filename=ask_log_location(filename);
|
handle=fopen(filename,(mode==TD_LOG_CREATE?"w":"a"));
|
||||||
if(filename==NULL)
|
/* WARN: filename: memory leak */
|
||||||
return TD_LOG_REFUSED;
|
|
||||||
}
|
}
|
||||||
} while(log_handle==NULL);
|
}
|
||||||
|
#endif
|
||||||
|
if(log_handle==NULL && ncurses_interface==0)
|
||||||
|
{
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
while(log_handle==NULL)
|
||||||
|
{
|
||||||
|
filename=ask_log_location(filename);
|
||||||
|
if(filename==NULL)
|
||||||
|
return TD_LOG_REFUSED;
|
||||||
|
log_handle=fopen(filename,(mode==TD_LOG_CREATE?"w":"a"));
|
||||||
|
}
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
time_t my_time;
|
time_t my_time;
|
||||||
|
|
Loading…
Reference in a new issue