Skip to content

Commit fc7cc10

Browse files
committed
chdir to BASE_DIR
Change to the base directory so that the installed program can find the data files.
1 parent 86a2135 commit fc7cc10

File tree

7 files changed

+34
-5
lines changed

7 files changed

+34
-5
lines changed

bot.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ int main(int argc,char **argv)
10951095
printf("Started WinSock version %X.%02X\n", wd.wVersion/0x100, wd.wVersion&0xFF);
10961096
#endif
10971097

1098-
1098+
chdir_to_data_files();
10991099
ERROR("Initialization...\n");
11001100

11011101
last_obj=&objects;

client.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2223,7 +2223,7 @@ int main(int argc,char **argv)
22232223
printf("Started WinSock version %X.%02X\n", wd.wVersion/0x100, wd.wVersion&0xFF);
22242224
#endif
22252225

2226-
2226+
chdir_to_data_files();
22272227
#ifdef XWINDOW
22282228
x_display_name=0;
22292229
x_font_name=0;

configure.in

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ AC_STRUCT_TM
3434
dnl Checks for library functions.
3535
AC_PROG_GCC_TRADITIONAL
3636
AC_TYPE_SIGNAL
37-
AC_CHECK_FUNCS(gettimeofday select strtol strtoul getopt)
38-
39-
AC_CHECK_FUNCS(psignal)
37+
AC_CHECK_FUNCS(gettimeofday select strtol strtoul getopt psignal access)
4038

4139
AC_CHECK_FUNC(random, cf_result=yes, cf_result=no)
4240
if test "$cf_result" = no; then

data.c

+28
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
#include "config.h"
77
#endif
88

9+
#ifdef HAVE_ACCESS
10+
# ifdef HAVE_UNISTD_H
11+
# include <unistd.h>
12+
# endif
13+
#endif
14+
915
#include "data.h"
1016
#include "cfg.h"
1117
#include "hash.h"
@@ -623,3 +629,25 @@ char* md5_level(int level_num)
623629
mem_free(result);
624630
return q;
625631
}
632+
633+
/* returns 1 if the file is readable */
634+
static int r_access(const char *filename)
635+
{
636+
#ifdef HAVE_ACCESS
637+
return !access(filename, R_OK);
638+
#else
639+
FILE *f = fopen(filename, "r");
640+
if (f) {
641+
fclose(f);
642+
return 1;
643+
}
644+
return 0;
645+
#endif
646+
}
647+
648+
/* changes the current dir to where the data files can be found */
649+
void chdir_to_data_files(void)
650+
{
651+
if (!r_access(DATA_PATH BANNER_FILE))
652+
chdir(BASE_DIR);
653+
}

data.h

+1
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,5 @@ void update_position(
252252
extern void _skip_ws(char**txt);
253253
extern int _convert_type(unsigned char c);
254254
extern char * load_level(int);
255+
extern void chdir_to_data_files(void);
255256
#endif

editor.c

+1
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ int main(int argc, char**argv)
361361
unsigned long_long last_time;
362362
char *LEVEL;
363363

364+
chdir_to_data_files();
364365
set_sigint();
365366

366367
while(1)

server.c

+1
Original file line numberDiff line numberDiff line change
@@ -3081,6 +3081,7 @@ int main(int argc, char **argv)
30813081
}
30823082
consoleApp=1;
30833083
#endif
3084+
chdir_to_data_files();
30843085
parse_command_line(argc,argv);
30853086

30863087
a=server();

0 commit comments

Comments
 (0)