/* * Half-Life Linux dedicated server liblist.gam redirector * Part of dedtools * Code by Tomas Janousek * This is GPL code. */ #include #include #include #include #include #include #include static FILE *(*old_f)(const char *path, const char *mode) = 0; static int (*old_stat)(int ver, const char *file_name, struct stat *buf) = 0; static const char str1[] = "liblist.gam"; static int str1sz = sizeof(str1)/sizeof(*str1) - 1; static const char *getpath(const char *path) { const char *newpath = 0; if (path && strlen(path) >= str1sz && !strcmp(path + strlen(path) - str1sz, str1)) { newpath = getenv("HLDS_LIBLIST_GAM"); if (newpath) path = newpath; } return path; } int __xstat(int ver, const char *file_name, struct stat *buf) { if (!old_stat) { old_stat = dlsym(RTLD_NEXT,"__xstat"); if (!old_stat) exit(-1); } return old_stat(ver, getpath(file_name), buf); } FILE *fopen(const char *path, const char *mode) { if (!old_f) { old_f = dlsym(RTLD_NEXT,"fopen"); if (!old_f) exit(-1); } return old_f(getpath(path), mode); }