void guiSave( void ) { int i = ( guiMenu ? IupGetInt ( guiMenu, "MEDIT_I" ) : guiMenu_Org ); char path[ PATH_MAX ] = {0}; char opath[ PATH_MAX ] = {0}; if ( !appMethods.OnDefPath || !appMethods.OnDefExt ) { return; } copystri ( path, ipGetUsrDir(), PATH_MAX ); appendstr ( path, DIR_SEP ".medit" DIR_SEP "data", PATH_MAX ); copystri ( opath, path, PATH_MAX ); appMethods.OnDefPath ( opath ); appMethods.OnApply(); appMethods.OnDefPath ( path ); // Rename Directory if ( _access( opath, 0 ) == 0 && istrcmp( opath, path ).i ) { rename( opath, path ); } if ( i >= guiMenu_Hacks ) { appendstr ( opath, "*.", PATH_MAX ); appendstr ( path, "*.", PATH_MAX ); } else { appendstr ( opath, ".", PATH_MAX ); appendstr ( path, ".", PATH_MAX ); } appMethods.OnDefExt ( path ); appMethods.OnDefExt ( opath ); // Rename File if ( i < guiMenu_Hacks && _access( opath, 0 ) == 0 && istrcmp( opath, path ).i ) { rename( opath, path ); } if ( i >= guiMenu_Hacks ) { if ( IupGetFile ( path ) == -1 ) { return; } } if ( _access( path, 0 ) != 0 ) { _creat( path, _S_IREAD | _S_IWRITE ); } appMethods.OnSave ( path ); }
oval_result_t oval_binary_cmp(const char *state, const char *syschar, oval_operation_t operation) { // I'm going to use case insensitive compare here - don't know if it's necessary switch (operation) { case OVAL_OPERATION_EQUALS: return istrcmp(state, syschar) == 0 ? OVAL_RESULT_TRUE : OVAL_RESULT_FALSE; case OVAL_OPERATION_NOT_EQUAL: return istrcmp(state, syschar) != 0 ? OVAL_RESULT_TRUE : OVAL_RESULT_FALSE; default: oscap_seterr(OSCAP_EFAMILY_OVAL, "Invalid type of operation in binary evaluation: %d.", operation); } return OVAL_RESULT_ERROR; }
int main() { char *str1 = istring_mk(NULL); char *str2 = istring_mk("Anders"); char *str3 = istring_mk("Alander"); char *str4 = istring_mk(" "); char *str9 = istring_to_string(str2); char *str5 = istrcat(str9,str4); char *str11 = istring_to_string(str5); char *str6 = istrcat(str11, str3); char *str7 = istring_to_string(str6); char *str8 = istring_mk("Erik"); char *str10 = istring_to_string(str5); char *str12 = "Anders Ålander"; char *str13 = istrncat(str9, str3,2); printf("An empty istring has length %zu\n", istrlen(str1)); printf("My first name is %s\n",str2); printf("My last name is %s\n",str3); printf("My name concatenated is %s\n", str6); printf("%s concatenated with the first %d chars from %s is %s\n", str2, 2, str3, str13); printf("%s has length %zu\n", str6, istrlen(str6)); printf("%s is my name stored as normal string, it also has length %zu\n", str7, strlen(str7)); printf("An istring's length can be changed without touching the string itself. %s has length %zu\n", str2, istrlen(str2)); str2 = istrslen(str2, 15); printf("but we can change it to %zu\n", istrlen(str2)); printf("Returns a pointer to the first given character in %s, for example a pointer to 's'gives %s\n", str2, istrchr(str2,'s')); printf("Same as above but from the end of %s. Pointer to 's' gives %s\n", str2, istrrchr(str2, 's')); printf("Are the strings %s and %s equal? %s\n", str2, str3, istrcmp(str2,str3)?"no":"yes"); printf("Which one of %s and %s is greatest? %s\n", str2, str3, istrcmp(str2,str3)<0?str2:str3); printf("Compares the first %d characters in %s and %s. The substring of %s is greatest\n", 3, str2, str3, istrncmp(str2, str3, 3) > 0?str3:str2); printf("The result of copying %s into %s is %s\n", str8, str12, istrcpy(str7, str8)); printf("The result of copying %d chars from %s into %s is %s\n", 3, str8, str12, istrncpy(str7,str8,3)); istring_rm(str1); istring_rm(str2); istring_rm(str3); istring_rm(str4); istring_rm(str5); istring_rm(str6); free(str7); istring_rm(str8); free(str9); free(str10); free(str11); istring_rm(str13); return 0; }
oval_result_t oval_string_cmp(const char *state, const char *syschar, oval_operation_t operation) { syschar = syschar ? syschar : ""; switch (operation) { case OVAL_OPERATION_EQUALS: return oscap_strcmp(state, syschar) ? OVAL_RESULT_FALSE : OVAL_RESULT_TRUE; case OVAL_OPERATION_CASE_INSENSITIVE_EQUALS: return istrcmp(state, syschar) ? OVAL_RESULT_FALSE : OVAL_RESULT_TRUE; case OVAL_OPERATION_NOT_EQUAL: return oscap_strcmp(state, syschar) ? OVAL_RESULT_TRUE : OVAL_RESULT_FALSE; case OVAL_OPERATION_CASE_INSENSITIVE_NOT_EQUAL: return istrcmp(state, syschar) ? OVAL_RESULT_TRUE : OVAL_RESULT_FALSE; case OVAL_OPERATION_PATTERN_MATCH: return strregcomp(state, syschar); default: oscap_seterr(OSCAP_EFAMILY_OVAL, "Invalid type of operation in string evaluation: %d.", operation); } return OVAL_RESULT_ERROR; }
struct chanlist* user_get_chanlist(struct userNode *user, struct chanNode *chan) { struct chanlist *hChanList; if((user == NULL) || (chan == NULL)) return NULL; for(hChanList = user->chanlist_first;hChanList != NULL;hChanList = hChanList->next) { if(istrcmp(hChanList->chan->name, chan->name)) return hChanList; } return NULL; }
struct userNode* user_get_handle(char *nick) { struct userNode *user; if(blankstr(nick)) return NULL; for(user = user_first;user != NULL;user = user->next) { if(istrcmp(user->nick, nick)) return user; } return NULL; }
void pathserver() { mputs("THIS IS PATHSERVER\n"); uint paths[PIPE_NUM_LIMIT-TASK_NUM_LIMIT-PATH_NUM_RESERVED][PATH_NAME_MAX]; uint num=0; uint buff[PATH_NAME_MAX]; uint n = setbuff(buff,"/sys/pathserver"); imemcpy(paths[num++],buff,n); uint i; uint fd; uint len; while(1) { read(PATHSERVER_FD,&fd,1); read(PATHSERVER_FD,&len,1); read(PATHSERVER_FD,buff,len); if(fd==MKFIFO_FD) { imemcpy(paths[num++],buff,len); } else { for(i=0;i<num;i++) { if( *paths[i] && istrcmp(buff,paths[i])==0 ) { i = i + PATH_NUM_RESERVED +TASK_NUM_LIMIT; write(fd,&i,1); i=0; break; } if(i>=num) { i=-1; write(fd,&i,1); } } } } }
char* irc_subconftok(char *buf, unsigned char citem, char *subname, unsigned int tok) { unsigned long i = 0, lcount = 0; char **lines = NULL; char *conftok = (char*)callocm(CONF_MAX_ITEMLEN, sizeof(char)); lcount = get_confitem(&lines, citem); for(i = 0;i < lcount;i++) { if(istrcmp(get_itemtok(conftok, lines[i], 2), subname)) { get_itemtok(conftok, lines[i], tok); strncpy(buf, conftok, CONF_MAX_ITEMLEN); freem(conftok); free_2d_array(lines, lcount); return buf; } } freem(conftok); free_2d_array(lines, lcount); return NULL; }
struct userNode* user_adduser(char *nick) { struct userNode *user; if(blankstr(nick)) return NULL; if(user_get_handle(nick)) return NULL; user = (struct userNode*)mallocm(sizeof(struct userNode)); if(user == NULL) return NULL; init_user_struct(user); xstrcpy(user->nick, nick, MAX_MSGLEN); if(istrcmp(user->nick, bot.current_nick)) me = user; LL_ADDNODE(user, user_first, user_last) user_count++; return user; }
int alphasort(const struct dirent **d1, const struct dirent **d2) { return istrcmp((*d1)->d_name, (*d2)->d_name); }
bool string::iequals(const char *str) const { return !istrcmp(data, str); }
int main(int argc, char *argv[]) { char console[MAX_LEN]; unsigned int err = 0; extern unsigned long alloc_calls; extern unsigned long free_calls; handle_first = (struct handle_list*)mallocm(sizeof(struct handle_list)); if(handle_first == NULL) { make_error("Failed to allocate memory for internal handle list!"); getchar(); return 1; } handle_first->next = NULL; handle_first->handle = (void*)&handle_first; handle_last = handle_first; dispsplash(); printf("Initializing... "); stats.start_time = (long)time(NULL); if(!init()) { make_error("Initialization failed (init() is 0)."); free_xion_memory(); getchar(); return 1; } bot_cmd_init(); printf("Done.\n"); if(!log_clean()) make_warning("Failed to clear log file."); log_write("*** Program started. Executed as: %s", argv[0]); printf("Connecting to %s:%d... ", bot.servaddr, bot.servport); if((err = irc_connect(bot.servaddr, bot.servport)) != 0) { printf("Failed to connect. ERROR %d\n\n", err); log_write("Connecting failed with code: %d", err); printf("Press Enter key to continue."); getchar(); return 0; } printf("Connected.\n"); signal(SIGINT, extern_exit); while(1) { fgets(console, 512, stdin); if(console[0] == '\n') break; strrtok(console, "\r\n"); if(istrcmp(console, "exit")) break; else if(istrcmp(console, "rehash")) { printf("\nRehashing configuration...\n"); if(!rehashconfig()) printf("Failed."); else printf("Done."); } else irc_send(console, 1); } irc_quit(NULL); free_xion_memory(); event_call(EVENT_EXIT, 0); log_write("*** Program ended successfully. Allocation Calls: %d Free Calls: %d", stats.alloc_calls, stats.free_calls); return 0; }
unsigned int rehashconfig(void) { char **xlines; char *conftok = (char*)callocm(CONF_MAX_ITEMLEN, sizeof(char)); unsigned int i = 0, xcount = 0, acount = 0; /* Don't get this confused with the word "account" */ extern q_maxbytes; /*X:Line*/ xcount = get_confitem(&xlines, 'X'); if(!xcount) { make_error("No X:lines in configuration file."); freem(conftok); return 0; } /*nickname*/ xstrcpy(bot.nick, get_itemtok(conftok, xlines[0], 2), 32); if(!istrcmp(bot.current_nick, bot.nick)) irc_nick(bot.nick); /*altnick*/ xstrcpy(bot.altnick, get_itemtok(conftok, xlines[0], 3), 32); /*S:Lines*/ /*maxretry*/ irc_subconftok(conftok, 'S', "maxretry", 3); bot.maxretry = atoi(conftok); /*pingtimeout*/ irc_subconftok(conftok, 'S', "pingtimeout", 3); bot.ping_timeout = atoi(conftok); /*antiflood*/ irc_subconftok(conftok, 'S', "antiflood", 5); bot.floodcheck = (atoi(conftok) ? 1 : 0); irc_subconftok(conftok, 'S', "antiflood", 3); q_maxbytes = (unsigned int)atoi(conftok); /*ctrigger*/ irc_subconftok(conftok, 'S', "ctrigger", 3); conf_replace_alias(conftok); bot.ctrigger = conftok[0]; /*ptrigger*/ irc_subconftok(conftok, 'S', "ptrigger", 3); conf_replace_alias(conftok); bot.ptrigger = conftok[0]; /*A:Lines*/ if(bot.admin_array != NULL) free_2d_array(bot.admin_array, bot.admin_lines); acount = get_confitem(&bot.admin_array, 'A'); bot.admin_lines = acount; if(acount) { for(i = 0;i < bot.admin_lines;i++) { get_itemtok(conftok, bot.admin_array[i], 3); if((istrcmp(conftok, ";")) || (istrcmp(conftok, "*"))) adm_loginuser(get_itemtok(conftok, bot.admin_array[i], 2), get_itemtok(conftok, bot.admin_array[i], 4), atoi(get_itemtok(conftok, bot.admin_array[i], 5))); } } freem(conftok); free_2d_array(xlines, xcount); event_call(EVENT_REHASH, 0); return 1; }
/* This function should not be called more than once */ unsigned int init(void) { char **xlines, **clines; char *conftok = (char*)callocm(CONF_MAX_ITEMLEN, sizeof(char)); unsigned int i = 0, xcount = 0, ccount = 0, acount = 0; /* Don't get this confused with the word "account" */ extern q_maxbytes, q_maxqueue; /* For making sure when these variables are tested, they are set to NULL first. */ init_handle(&q_first); init_handle(&q_last); init_handle(&event_first); init_handle(&event_last); init_handle(&chan_first); init_handle(&chan_last); init_handle(&user_first); init_handle(&user_last); init_handle(&me); init_handle(&bc_first); init_handle(&bc_last); init_handle(&dcc_first); init_handle(&dcc_last); eventloop_running = 0; bot.cid = 0; bot.connected = 0; xstrcpy(bot.config, XION_CONFIG, 260); bot.admin_current_count = 0; bot.current_try = 1; q_first = NULL; /*X:Line*/ xcount = get_confitem(&xlines, 'X'); if(!xcount) { make_error("No X:lines in configuration file."); freem(conftok); return 0; } /*nickname*/ xstrcpy(bot.nick, get_itemtok(conftok, xlines[0], 2), 32); /*altnick*/ xstrcpy(bot.altnick, get_itemtok(conftok, xlines[0], 3), 32); /*username*/ xstrcpy(bot.username, get_itemtok(conftok, xlines[0], 4), 12); /*fullname*/ xstrcpy(bot.info, get_itemtok(conftok, xlines[0], 5), 256); xstrcpy(bot.info, conf_replace_alias(conftok), 256); /*C:Line*/ ccount = get_confitem(&clines, 'C'); if(!ccount) { make_error("No C:lines in configuration file."); freem(conftok); free_2d_array(xlines, xcount); return 0; } /*servaddr*/ xstrcpy(bot.servaddr, get_itemtok(conftok, clines[0], 2), 256); /*servport*/ bot.servport = atoi(get_itemtok(conftok, clines[0], 3)); /*servpass*/ xstrcpy(bot.servpass, get_itemtok(conftok, clines[0], 4), 256); /*S:Lines*/ /*maxretry*/ irc_subconftok(conftok, 'S', "maxretry", 3); bot.maxretry = atoi(conftok); /*pingtimeout*/ irc_subconftok(conftok, 'S', "pingtimeout", 3); bot.ping_timeout = atoi(conftok); /*freshlog*/ irc_subconftok(conftok, 'S', "freshlog", 3); bot.fresh_log = (atoi(conftok) ? 1 : 0); /*antiflood*/ irc_subconftok(conftok, 'S', "antiflood", 5); bot.floodcheck = (atoi(conftok) ? 1 : 0); irc_subconftok(conftok, 'S', "antiflood", 3); q_maxbytes = (unsigned int)atoi(conftok); irc_subconftok(conftok, 'S', "antiflood", 4); q_maxqueue = (unsigned int)atoi(conftok); /*ctrigger*/ irc_subconftok(conftok, 'S', "ctrigger", 3); conf_replace_alias(conftok); bot.ctrigger = conftok[0]; /*ptrigger*/ irc_subconftok(conftok, 'S', "ptrigger", 3); conf_replace_alias(conftok); bot.ptrigger = conftok[0]; /*A:Lines*/ if(bot.admin_array != NULL) free_2d_array(bot.admin_array, bot.admin_lines); acount = get_confitem(&bot.admin_array, 'A'); bot.admin_lines = acount; if(acount) { for(i = 0;i < bot.admin_lines;i++) { get_itemtok(conftok, bot.admin_array[i], 3); if((istrcmp(conftok, ";")) || (istrcmp(conftok, "*"))) adm_loginuser(get_itemtok(conftok, bot.admin_array[i], 2), get_itemtok(conftok, bot.admin_array[i], 4), atoi(get_itemtok(conftok, bot.admin_array[i], 5))); } } /* URL Module: mod-weburlcache.c */ urlmod_init(); freem(conftok); free_2d_array(xlines, xcount); free_2d_array(clines, ccount); event_call(EVENT_INIT, 0); return 1; }
signed string::icompare(rstring source) const { return istrcmp(data(), source.data()); }