lib_t *lib_create(const char *dbfile, const char *libdir) { lib_t *lib=malloc(sizeof(lib_t)); if(!lib) return NULL; lib->watch=watch_create(lib); if(!lib->watch) { error(ll, "failed to create watcher."); goto err; } lib->watch->event=lib_watch_event; empty=string_create_unique(""); ll=get_logger("lib"); lib->entries=chunked_list_create(512, sizeof(lib_entry), &lib_entry_destructor); if(!lib->entries) { error(ll, "failed to allocate lib."); goto err; } int s=strlen(libdir); if(libdir[s-1]!='/') { char *tmp=malloc(s+2); strcpy(tmp, libdir); tmp[s++]='/'; tmp[s]=0; libdir=tmp; } else libdir=strdup(libdir); lib->base_path=libdir; lib->base_path_size=s; filecount=0; lib->dbfile=strdup(dbfile); lib_read(lib); // pthread_create(&lib->check_thread, NULL, check_lib, lib); // pthread_join(lib->check_thread, NULL); check_lib(lib); return lib; err: if(lib) { if(lib->entries) chunked_list_destroy(lib->entries); if(lib->watch) watch_destroy(lib->watch); free(lib); } return NULL; }
int map_lib_file(char *filename, struct fsex_libdata *lib) { char *idstr; struct fsex_id *id; lib->data = mapfile(filename); if (lib->data == NULL) { perror(filename); exit(1); } lib->model = MODEL_NONE; lib->filename = filename; printf("* %s: ", filename); id = find_id_by_libid(lib->data); if (id == NULL) { printf("unknown\n"); exit(1); } idstr = id->name; lib->model = id->model; lib->data += 32; lib->num_patch = val32_be(lib->data); lib->data += 128; if (check_lib(lib) < 0) { fprintf(stderr, "data seems to be corrupted\n"); exit(1); } printf("%s library file (%d patches)\n", idstr, lib->num_patch); lib->patch = malloc(lib->num_patch * sizeof(struct fsex_patch)); if (lib->patch == NULL) { perror("error"); exit(1); } load_patches(lib); return 0; }
int odbc_read_login_info(void) { static const char *PWD = "../../../PWD"; FILE *in = NULL; char line[512]; char *s1, *s2; #ifndef _WIN32 char path[1024]; int len; #endif setbuf(stdout, NULL); setbuf(stderr, NULL); s1 = getenv("TDSPWDFILE"); if (s1 && s1[0]) in = fopen(s1, "r"); if (!in) in = fopen(PWD, "r"); if (!in) in = fopen("PWD", "r"); if (!in) { fprintf(stderr, "Can not open PWD file\n\n"); return 1; } while (fgets(line, 512, in)) { s1 = strtok(line, "="); s2 = strtok(NULL, "\n"); if (!s1 || !s2) continue; if (!strcmp(s1, "UID")) { strcpy(odbc_user, s2); } else if (!strcmp(s1, "SRV")) { strcpy(odbc_server, s2); } else if (!strcmp(s1, "PWD")) { strcpy(odbc_password, s2); } else if (!strcmp(s1, "DB")) { strcpy(odbc_database, s2); } } fclose(in); #ifndef _WIN32 /* find our driver */ if (!getcwd(path, sizeof(path))) return 0; #ifdef __VMS { /* A hard-coded driver path has to be in unix syntax to be recognized as such. */ const char *unixspec = decc$translate_vms(path); if ( (int)unixspec != 0 && (int)unixspec != -1 ) strcpy(path, unixspec); } #endif len = strlen(path); if (len < 10 || strcmp(path + len - 10, "/unittests") != 0) return 0; path[len - 9] = 0; /* TODO this must be extended with all possible systems... */ if (!check_lib(path, ".libs/libtdsodbc.so") && !check_lib(path, ".libs/libtdsodbc.sl") && !check_lib(path, ".libs/libtdsodbc.dll") && !check_lib(path, ".libs/libtdsodbc.dylib") && !check_lib(path, "_libs/libtdsodbc.exe")) return 0; strcpy(odbc_driver, path); /* craft out odbc.ini, avoid to read wrong one */ in = fopen("odbc.ini", "w"); if (in) { fprintf(in, "[%s]\nDriver = %s\nDatabase = %s\nServername = %s\n", odbc_server, odbc_driver, odbc_database, odbc_server); fclose(in); setenv("ODBCINI", "./odbc.ini", 1); setenv("SYSODBCINI", "./odbc.ini", 1); } #endif return 0; }
int odbc_read_login_info(void) { static const char *PWD = "../../../PWD"; FILE *in = NULL; char line[512]; char *s1, *s2; const char *const *search_p; char path[1024]; int len; #ifdef _WIN32 UWORD old_config_mode; #endif setbuf(stdout, NULL); setbuf(stderr, NULL); s1 = getenv("TDSPWDFILE"); if (s1 && s1[0]) in = fopen(s1, "r"); if (!in) in = fopen(PWD, "r"); if (!in) in = fopen("PWD", "r"); if (!in) { fprintf(stderr, "Can not open PWD file\n\n"); return 1; } while (fgets(line, 512, in)) { s1 = strtok(line, "="); s2 = strtok(NULL, "\n"); if (!s1 || !s2) continue; if (!strcmp(s1, "UID")) { strcpy(odbc_user, s2); } else if (!strcmp(s1, "SRV")) { strcpy(odbc_server, s2); } else if (!strcmp(s1, "PWD")) { strcpy(odbc_password, s2); } else if (!strcmp(s1, "DB")) { strcpy(odbc_database, s2); } } fclose(in); /* find our driver */ #ifndef _WIN32 if (!getcwd(path, sizeof(path))) #else if (!_getcwd(path, sizeof(path))) #endif return 0; #ifdef __VMS { /* A hard-coded driver path has to be in unix syntax to be recognized as such. */ const char *unixspec = decc$translate_vms(path); if ( (int)unixspec != 0 && (int)unixspec != -1 ) strcpy(path, unixspec); } #endif len = strlen(path); if (len < 10 || (strcasecmp(path + len - 10, "/unittests") != 0 #ifdef _WIN32 && strcasecmp(path + len - 10, "\\unittests") != 0 #endif )) return 0; path[len - 9] = 0; for (search_p = search_driver; *search_p; ++search_p) { if (check_lib(path, *search_p)) break; } if (!*search_p) return 0; strcpy(odbc_driver, path); #ifndef _WIN32 /* craft out odbc.ini, avoid to read wrong one */ snprintf(path, sizeof(path), "odbc.ini.%d", (int) getpid()); in = fopen(path, "w"); if (in) { fprintf(in, "[%s]\nDriver = %s\nDatabase = %s\nServername = %s\n", odbc_server, odbc_driver, odbc_database, odbc_server); fclose(in); setenv("ODBCINI", "./odbc.ini", 1); setenv("SYSODBCINI", "./odbc.ini", 1); rename(path, "odbc.ini"); unlink(path); } #else if (SQLGetConfigMode(&old_config_mode)) { SQLSetConfigMode(ODBC_USER_DSN); SQLWritePrivateProfileString(odbc_server, "Driver", odbc_driver, "odbc.ini"); SQLWritePrivateProfileString(odbc_server, "Database", odbc_database, "odbc.ini"); SQLWritePrivateProfileString(odbc_server, "Servername", odbc_server, "odbc.ini"); SQLSetConfigMode(old_config_mode); } #endif return 0; }