/*=export_func optionFileCheck * private: * * what: Decipher a boolean value * arg: + tOptions* + pOpts + program options descriptor + * arg: + tOptDesc* + pOptDesc + the descriptor for this arg + * arg: + teOptFileType + ftype + File handling type + * arg: + tuFileMode + mode + file open mode (if needed) + * * doc: * Make sure the named file conforms with the file type mode. * The mode specifies if the file must exist, must not exist or may * (or may not) exist. The mode may also specify opening the * file: don't, open just the descriptor (fd), or open as a stream * (FILE* pointer). =*/ void optionFileCheck(tOptions * pOpts, tOptDesc * pOD, teOptFileType ftype, tuFileMode mode) { if (pOpts <= OPTPROC_EMIT_LIMIT) { if (pOpts != OPTPROC_EMIT_USAGE) return; switch (ftype & FTYPE_MODE_EXIST_MASK) { case FTYPE_MODE_MUST_NOT_EXIST: fputs(zFileCannotExist + tab_skip_ct, option_usage_fp); break; case FTYPE_MODE_MUST_EXIST: fputs(zFileMustExist + tab_skip_ct, option_usage_fp); break; } return; } if ((pOD->fOptState & OPTST_RESET) != 0) { if (pOD->optCookie != NULL) AGFREE(pOD->optCookie); return; } check_existence(ftype, pOpts, pOD); switch (ftype & FTYPE_MODE_OPEN_MASK) { default: case FTYPE_MODE_NO_OPEN: break; case FTYPE_MODE_OPEN_FD: open_file_fd( pOpts, pOD, mode); break; case FTYPE_MODE_FOPEN_FP: fopen_file_fp(pOpts, pOD, mode); break; } }
int error_boss(char *map) { char *file; char **tab; int width; int height; if (check_existence(map) == -1 || (file = get_file_content(map)) == NULL || check_integer(file, "ibwsm.lg\n") == -1 || (file = put_return(file)) == NULL || (tab = my_str_to_wordtab(file, '\n')) == NULL || check_largest(tab) == -1 || is_present("i", file) != 1 || is_present("b", file) != 1 || check_tab(tab) == -1) return (puterror("One of Boss map isn't correct.\n")); width = my_strlen(tab[0]) * 29; height = tablen(tab) * 26; if (width > 1300 || height > 750) return (puterror("Error: Dimension are too big in Boss Map.\n")); free(file); free_tab(tab); return (0); }
/* Begins scanning for nearby bluetooth devices. If any, it checks the keystore whether they're valid or not. Locks/unlocks the screen appropriately. @param time_per_scan Time to wait for bluetooth devices to respond. @param store The keystore containing valid bluetooth key devices. */ void start_daemon(int time_per_scan, key_store* store) { discovered_dev_t* nearby = (discovered_dev_t*)malloc(sizeof(discovered_dev_t)*NR_MAX_DISCOVERED_DEVICES); state_history history; init_history(&history); bool unlock_status = TRUE; bool previous_status = TRUE; while(TRUE) { int found = scan_nearby(NR_MAX_DISCOVERED_DEVICES, TIME_PER_SCAN, nearby); int i; bool status = FALSE; key_device_t* found_device = NULL; for(i = 0; i < found; i++) { key_device_t* current = (key_device_t*)malloc(sizeof(key_device_t)); discovered_dev_t dev = nearby[i]; current -> device_id = (char*)malloc(sizeof(char)*ID_LEN); str2ba(dev.addr, &(current->addr)); int pos = -1; if((pos = check_existence(store,current)) >= 0) { status = TRUE; update_key(store, pos); found_device = fetch_key(store,pos); break; } free(current); } update_history(&history,status); update_lock_status(history,&unlock_status); previous_status = execute_status(unlock_status,previous_status, found_device); if(unlock_status == TRUE) { usleep(SLEEP_TIME*1000); continue; } usleep(250); } }
_nc_first_db(DBDIRS * state, int *offset) { bool cache_has_expired = FALSE; *state = dbdTIC; *offset = 0; T(("_nc_first_db")); /* build a blob containing all of the strings we will use for a lookup * table. */ if (my_blob == 0 || (cache_has_expired = cache_expired())) { size_t blobsize = 0; const char *values[dbdLAST]; struct stat *my_stat; int j, k; if (cache_has_expired) free_cache(); for (j = 0; j < dbdLAST; ++j) values[j] = 0; /* * This is the first item in the list, and is used only when tic is * writing to the database, as a performance improvement. */ values[dbdTIC] = TicDirectory; #if NCURSES_USE_DATABASE #ifdef TERMINFO_DIRS values[dbdCfgList] = TERMINFO_DIRS; #endif #ifdef TERMINFO values[dbdCfgOnce] = TERMINFO; #endif #endif #if NCURSES_USE_TERMCAP values[dbdCfgList2] = TERMPATH; #endif if (use_terminfo_vars()) { #if NCURSES_USE_DATABASE values[dbdEnvOnce] = cache_getenv("TERMINFO", dbdEnvOnce); values[dbdHome] = _nc_home_terminfo(); (void) cache_getenv("HOME", dbdHome); values[dbdEnvList] = cache_getenv("TERMINFO_DIRS", dbdEnvList); #endif #if NCURSES_USE_TERMCAP values[dbdEnvOnce2] = cache_getenv("TERMCAP", dbdEnvOnce2); /* only use $TERMCAP if it is an absolute path */ if (values[dbdEnvOnce2] != 0 && *values[dbdEnvOnce2] != '/') { values[dbdEnvOnce2] = 0; } values[dbdEnvList2] = cache_getenv("TERMPATH", dbdEnvList2); #endif /* NCURSES_USE_TERMCAP */ } for (j = 0; j < dbdLAST; ++j) { if (values[j] == 0) values[j] = ""; blobsize += 2 + strlen(values[j]); } my_blob = malloc(blobsize); if (my_blob != 0) { *my_blob = '\0'; for (j = 0; j < dbdLAST; ++j) { add_to_blob(values[j], blobsize); } /* Now, build an array which will be pointers to the distinct * strings in the blob. */ blobsize = 2; for (j = 0; my_blob[j] != '\0'; ++j) { if (my_blob[j] == NCURSES_PATHSEP) ++blobsize; } my_list = typeCalloc(char *, blobsize); my_stat = typeCalloc(struct stat, blobsize); if (my_list != 0 && my_stat != 0) { k = 0; my_list[k++] = my_blob; for (j = 0; my_blob[j] != '\0'; ++j) { if (my_blob[j] == NCURSES_PATHSEP) { my_blob[j] = '\0'; my_list[k++] = &my_blob[j + 1]; } } /* * Eliminate duplicates from the list. */ for (j = 0; my_list[j] != 0; ++j) { #ifdef TERMINFO if (*my_list[j] == '\0') my_list[j] = strdup(TERMINFO); #endif for (k = 0; k < j; ++k) { if (!strcmp(my_list[j], my_list[k])) { k = j - 1; while ((my_list[j] = my_list[j + 1]) != 0) { ++j; } j = k; break; } } } /* * Eliminate non-existent databases, and those that happen to * be symlinked to another location. */ for (j = 0; my_list[j] != 0; ++j) { bool found = check_existence(my_list[j], &my_stat[j]); #if HAVE_LINK if (found) { for (k = 0; k < j; ++k) { if (my_stat[j].st_dev == my_stat[k].st_dev && my_stat[j].st_ino == my_stat[k].st_ino) { found = FALSE; break; } } } #endif if (!found) { k = j; while ((my_list[k] = my_list[k + 1]) != 0) { ++k; } --j; } } my_size = j; my_time = time((time_t *) 0); } else { FreeAndNull(my_blob); } free(my_stat); }
// test that should not work bool test_not_work() { cppdb::statement existsRequest = sqliteDb.prepare( "SELECT 1 FROM users WHERE group_id = 42" ); return check_existence(existsRequest); }