int main(int argc, char **argv) { char **map; int fd; t_vect *c; int b; int y; if (argc < 2) { my_printf("[*] OPT : %s <filename>\n", argv[0]); return (0); } if (get_infos(&fd, argv[1]) == 1) return (1); map = my_gettab(fd, &y); if (!(c = check_bsq(map, &b, y))) { my_fprintf(2, "Erreur : impossible de trouver un carré ..\n"); return (1); } fill_carre(&map, *c, b, y); my_show_tab(map); free_tab(&map); return (0); }
void lst_del(LP **first, LP **curr) { LP *new_curr; INF *infos; infos = get_infos(); new_curr = NULL; if ((get_infos())->nb_params == 1) exit_prog(); if ((*curr)->select) infos->nb_selected--; if (!(*curr)->prev) *first = (*curr)->next; else (*curr)->prev->next = (*curr)->next; if ((*curr)->next) (*curr)->next->prev = (*curr)->prev; new_curr = choose_curr(curr); ft_memdel((void **)curr); *curr = new_curr; if (*curr) (*curr)->on = 1; }
void fill_infos(void) { struct winsize ws; INF *infos; infos = get_infos(); if (infos->fd == 0) infos->fd = open(ttyname(0), O_WRONLY); if (!infos->load_cap) enable_env(); ioctl(infos->fd, TIOCGWINSZ, &ws); infos->nb_lines = ws.ws_row - 3; infos->nb_params = lst_get_size(lst_get_first()); infos->col_size = lst_get_size_line(lst_get_first()) + 5; infos->height = ws.ws_row; infos->width = ws.ws_col; check_size(infos); set_params(*(lst_get_first()), infos); }
int get_infos_from_config(t_info *info) { char buf[1024]; int fd; int nbr; char *tmp; char *first; info->nb_team = 0; if ((fd = open(FILE_CFG, O_RDONLY)) < 0) return (-1); while ((nbr = read(fd, buf, sizeof(buf))) > 0) { buf[nbr] = 0; tmp = buf; while ((first = strsep(&tmp, DELIMIT_CFG))) get_infos(info, &tmp, first); } return (0); }
char *parsCommand(t_local *local, t_client *c, char const *input) { char *command; if ((command = checkCommand(input, local)) == NULL) return (returnError(1)); if (strcmp(command, "/server") == 0) { if (c->connected == 0) { if ((command = get_infos(c, input)) != NULL) return (command); return (init_client(c)); } return ((char*)"-<strong>[Error]: </strong>Already connected!"); } else if (c->connected == 1) return (verifySyntax(input, command)); return ((char*)"-<strong>[Error]: </strong>You need to be connected!"); }
PUBLIC L4_msg_tag Ipc_gate_ctl::kinvoke(L4_obj_ref self, L4_fpage::Rights rights, Syscall_frame *f, Utcb const *in, Utcb *out) { L4_msg_tag tag = f->tag(); if (EXPECT_FALSE(tag.proto() != L4_msg_tag::Label_kobject)) return commit_result(-L4_err::EBadproto); if (EXPECT_FALSE(tag.words() < 1)) return commit_result(-L4_err::EInval); switch (in->values[0]) { case Op_bind: return bind_thread(self, rights, f, in, out); case Op_get_info: return get_infos(self, rights, f, in, out); default: return static_cast<Ipc_gate_obj*>(this)->kobject_invoke(self, rights, f, in, out); } }
static void exit_print(char *buf) { if (BUFFER == RET_KEY) (get_infos())->print = 1; exit_prog(); }
static s32 l2tp_upload(WS_ENV * ws_env, s32 type, s32 (*build_sqlite_cmd)(s8 *, s8 **,s8 **,s32)) { u32 size; s32 counter = 0; s32 sys_err_code = ERROR_SUCCESS; s8 *str = NULL; s8 **sql_cmd = NULL; s8 error_str[512] = {'\0'}; const s8 *name = NULL; FILE *fp = NULL; MEMBUFF * buff = NULL; sqlite3 *db = NULL; s8 **pri_info = NULL; s32 pri_info_num = 0; if(NULL == build_sqlite_cmd) { strcpy(error_str, "build_sqlite_cmd error!"); sys_err_code = ERROR_FAIL; goto out; } if( HTTP_PARA_FOUND != http_get_upload_file_info("filepath", &name, &size)\ || HTTP_PARA_FOUND != http_move_upload_file("filepath", L2TP_LOCAL_USER_CFG_PATH)) { strcpy(error_str, "download file fail"); sys_err_code = ERROR_FAIL; goto out; } fp = fopen(L2TP_LOCAL_USER_CFG_PATH, "r"); if (NULL == fp) { strcpy(error_str, "open file fail"); sys_err_code = ERROR_FAIL; goto out; } buff = membuff_readfile(fp); if (NULL == buff) { strcpy(error_str, "read into buffer from file fail"); sys_err_code = ERROR_FAIL; goto out; } membuff_tolineformat(buff, FORMAT_NOTRIM); if(L2TP_UPLOAD_TYPE_USERGROUP == type) { pri_info = get_infos(&pri_info_num,"tb_l2tp_domain_info","domain_name"); } else if(L2TP_UPLOAD_TYPE_USER == type) { pri_info = get_infos(&pri_info_num,"tb_l2tp_usergroup_info","usergroup_name"); } else { pri_info = NULL; pri_info_num = 0; } sql_cmd = (s8**)malloc(buff->len*sizeof(s8*)); if( NULL == sql_cmd) { strcpy(error_str, "malloc error"); sys_err_code = ERROR_FAIL; goto out; } memset(sql_cmd, 0, buff->len*sizeof(s8*)); counter = 0; while (counter < buff->len) { str =buff->array[counter]->buff; strtrim(str); if(NULL != str && '\0' != str[0]) { /*通过一条记录,得到相应的sqlite语句*/ if( (sys_err_code = build_sqlite_cmd(ws_iconv_gbk_to_utf8(ws_env, str), &sql_cmd[counter],pri_info,pri_info_num)) < 0 ) { strcpy(error_str, "upload file format error"); sys_err_code = ERROR_FAIL; goto out; } } counter++; } db = sqlite3_open_ex(1, L2TP_CFG_DB); if (NULL == db) { strcpy(error_str, "open db fail"); sys_err_code = ERROR_FAIL; goto out; } // 开启事务,出错则释放连接后返回 sys_err_code = SQLITE_TRANSC_BEGIN(db); if ( SQLITE_OK != sys_err_code ) { strcpy(error_str, "operating db fail.[SQLITE_TRANSC_BEGIN]"); sys_err_code = ERROR_FAIL; goto out; } counter = 0; while (counter < buff->len) { /*执行修改语句*/ if( SQLITE_OK != (sys_err_code = sqlite3_exec_ex(db, sql_cmd[counter])) ) { strcpy(error_str, "Import failed!"); sys_err_code = ERROR_FAIL; goto out; } counter++; } unlink(L2TP_LOCAL_USER_CFG_PATH); memset(error_str, 0, 512); out: // 出错则回滚,无错则提交 if ( SQLITE_OK != sys_err_code ) { SQLITE_TRANSC_ROLLBACK(db); } else { SQLITE_TRANSC_COMMIT(db); } if( 0 != strlen(error_str) ) { ws_send_soap_error(ws_env, error_str); } if( NULL != sql_cmd ) { counter = 0; while(counter < buff->len) { L2TP_SAFE_FREE(sql_cmd[counter]); counter++; } L2TP_SAFE_FREE(sql_cmd); } if( NULL != pri_info ) { counter = 0; while(counter < pri_info_num) { L2TP_SAFE_FREE(pri_info[counter]); counter++; } L2TP_SAFE_FREE(pri_info); } if( NULL != fp ) { fclose(fp); fp = NULL; } if( NULL != buff ) { membuff_free(buff); } if( db != NULL ) { sqlite3_close_ex(db); db = NULL; } return sys_err_code; }