Under Windows, if log file can't be created in current directory, try to create it in home directory.

This commit is contained in:
Christophe Grenier 2008-11-10 08:15:10 +01:00
parent 58a7f8b4bf
commit b1c51833ac

View file

@ -22,7 +22,13 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <stdio.h>
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <stdarg.h>
#ifdef HAVE_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;
if(mode!=TD_LOG_CREATE && mode!=TD_LOG_APPEND)
return mode;
do
{
log_handle=fopen(filename,(mode==TD_LOG_CREATE?"w":"a"));
if(log_handle==NULL && ncurses_interface==0)
{
printf("Can't create %s file\n", filename);
}
#if defined(__CYGWIN__) || defined(__MINGW32__)
if(log_handle==NULL)
{
if(ncurses_interface==0)
char *path;
path = getenv("USERPROFILE");
if (path == NULL)
path = getenv("HOMEPATH");
if(path!=NULL)
{
FILE*handle;
filename=(char*)MALLOC(strlen(path)+strlen(default_filename)+2);
strcpy(filename, path);
strcat(filename, "\\");
strcat(filename, default_filename);
handle=fopen(filename,(mode==TD_LOG_CREATE?"w":"a"));
/* WARN: filename: memory leak */
}
}
#endif
if(log_handle==NULL && ncurses_interface==0)
{
printf("Can't create %s file\n", default_filename);
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"));
}
} while(log_handle==NULL);
{
int i;
time_t my_time;