extern const char * uint64_to_nicestr(uint64_t value, enum nicestr_unit unit_min, enum nicestr_unit unit_max, bool always_also_bytes, uint32_t slot) { assert(unit_min <= unit_max); assert(unit_max <= NICESTR_TIB); assert(slot < ARRAY_SIZE(bufs)); check_thousand_sep(slot); enum nicestr_unit unit = NICESTR_B; char *pos = bufs[slot]; size_t left = sizeof(bufs[slot]); if ((unit_min == NICESTR_B && value < 10000) || unit_max == NICESTR_B) { // The value is shown as bytes. if (thousand == WORKS) my_snprintf(&pos, &left, "%'u", (unsigned int)value); else my_snprintf(&pos, &left, "%u", (unsigned int)value); } else { // Scale the value to a nicer unit. Unless unit_min and // unit_max limit us, we will show at most five significant // digits with one decimal place. double d = (double)(value); do { d /= 1024.0; ++unit; } while (unit < unit_min || (d > 9999.9 && unit < unit_max)); if (thousand == WORKS) my_snprintf(&pos, &left, "%'.1f", d); else my_snprintf(&pos, &left, "%.1f", d); } static const char suffix[5][4] = { "B", "KiB", "MiB", "GiB", "TiB" }; my_snprintf(&pos, &left, " %s", suffix[unit]); if (always_also_bytes && value >= 10000) { if (thousand == WORKS) snprintf(pos, left, " (%'" PRIu64 " B)", value); else snprintf(pos, left, " (%" PRIu64 " B)", value); } return bufs[slot]; }
/* {{{ mysql_local_infile_init */ static int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) { MYSQL_INFILE_INFO *info; DBUG_ENTER("mysql_local_infile_init"); info = (MYSQL_INFILE_INFO *)my_malloc(sizeof(MYSQL_INFILE_INFO), MYF(MY_ZEROFILL)); if (!info) { DBUG_RETURN(1); } *ptr = info; info->filename = filename; info->fd = my_open(info->filename, O_RDONLY, MYF(0)); if (info->fd < 0) { my_snprintf((char *)info->error_msg, sizeof(info->error_msg), "Can't open file '%-.64s'.", filename); info->error_no = EE_FILENOTFOUND; DBUG_RETURN(1); } DBUG_RETURN(0); }
/**************************************************************************** Send the request string to the metaserver. ****************************************************************************/ static void meta_send_request(struct server_scan *scan) { const char *capstr; char str[MAX_LEN_PACKET]; char machine_string[128]; my_uname(machine_string, sizeof(machine_string)); capstr = fc_url_encode(our_capability); my_snprintf(str, sizeof(str), "POST %s HTTP/1.1\r\n" "Host: %s:%d\r\n" "User-Agent: Freeciv/%s %s %s\r\n" "Connection: close\r\n" "Content-Type: application/x-www-form-urlencoded; charset=\"utf-8\"\r\n" "Content-Length: %lu\r\n" "\r\n" "client_cap=%s\r\n", scan->meta.urlpath, scan->meta.name, scan->meta.port, VERSION_STRING, client_string, machine_string, (unsigned long) (strlen("client_cap=") + strlen(capstr)), capstr); if (fc_writesocket(scan->sock, str, strlen(str)) != strlen(str)) { /* Even with non-blocking this shouldn't fail. */ scan->error_func(scan, fc_strerror(fc_get_errno())); return; } scan->meta.state = META_WAITING; }
void dbg_verify_failed(const char *format, ...) { int s; char buffer[1024*4]; va_list ap; if (!g_expr) g_expr="(none)"; s=my_snprintf(buffer, sizeof(buffer), "ASSERT FAILED in file %s, line %d:\n\t\"%s\"\n", g_file, g_line, g_expr); if (format) { va_start(ap, format); util_vsnprintf(buffer+s, sizeof(buffer)-s, format, ap); va_end(ap); } g_hand(g_level, buffer); /* [i_a] ALWAYS offer the user-def'able abort * handler (unittests depend on this) */ if (ham_test_abort) { ham_test_abort(); } else { #ifndef HAM_OS_WINCE abort(); #else ExitProcess(-1); #endif } }
/************************************************************************** Log player tech messages. **************************************************************************/ void TECH_LOG(int level, const struct player *pplayer, struct advance *padvance, const char *msg, ...) { char buffer[500]; char buffer2[500]; va_list ap; int minlevel = MIN(LOGLEVEL_TECH, level); if (!valid_advance(padvance) || advance_by_number(A_NONE) == padvance) { return; } if (BV_ISSET(pplayer->debug, PLAYER_DEBUG_TECH)) { minlevel = LOG_TEST; } else if (minlevel > fc_log_level) { return; } my_snprintf(buffer, sizeof(buffer), "%s::%s (want %d, dist %d) ", player_name(pplayer), advance_name_by_player(pplayer, advance_number(padvance)), pplayer->ai_data.tech_want[advance_index(padvance)], num_unknown_techs_for_goal(pplayer, advance_number(padvance))); va_start(ap, msg); my_vsnprintf(buffer2, sizeof(buffer2), msg, ap); va_end(ap); cat_snprintf(buffer, sizeof(buffer), "%s", buffer2); if (BV_ISSET(pplayer->debug, PLAYER_DEBUG_TECH)) { notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer); } freelog(minlevel, "%s", buffer); }
Ipp32u mfxSchedulerCore::scheduler_wakeup_thread_proc(void *pParam) { mfxSchedulerCore * const pSchedulerCore = (mfxSchedulerCore *) pParam; { char thread_name[30] = {0}; my_snprintf(thread_name, sizeof(thread_name)-1, "ThreadName=MSDKHWL#%d", 0); MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_SCHED, thread_name); } // main working cycle for threads while (false == pSchedulerCore->m_bQuitWakeUpThread) { vm_status vmRes; vmRes = vm_event_timed_wait(&pSchedulerCore->m_hwTaskDone, pSchedulerCore->m_timer_hw_event); // HW event is signaled. Reset all HW waiting tasks. if (VM_OK == vmRes|| VM_TIMEOUT == vmRes) { vmRes = vm_event_reset(&pSchedulerCore->m_hwTaskDone); //MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_SCHED, "HW Event"); pSchedulerCore->IncrementHWEventCounter(); pSchedulerCore->WakeUpThreads((mfxU32) MFX_INVALID_THREAD_ID, MFX_SCHEDULER_HW_BUFFER_COMPLETED); } } return 0x0ccedff; } // Ipp32u mfxSchedulerCore::scheduler_wakeup_thread_proc(void *pParam)
/* ----------------------------------------------------------------------------- Function: FS_FindNext -Continues a file search from a previous call to the FS_FindFirst function. Parameters: musthave -[in] File or directory must have these attributes. canthave- [in] File or directory can not have these attributes. Returns: On success string of file name or directory, otherwise NULL. Notes: ----------------------------------------------------------------------------- */ PUBLIC char *FS_FindNext( W32 musthave, W32 canthave ) { struct dirent *d; if( fdir == NULL ) { return NULL; } while( (d = readdir( fdir ) ) != NULL) { if( ! *findpattern || glob_match( findpattern, d->d_name ) ) { if( ! *findbase ) { my_strlcpy( findpath, d->d_name, sizeof( findpath ) ); } else { my_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, d->d_name ); } if( CompareAttributes( findpath, musthave, canthave ) ) { return findpath; } } } return NULL; }
void my_error(int nr, myf MyFlags, ...) { const char *format; struct my_err_head *meh_p; va_list args; char ebuff[ERRMSGSIZE]; DBUG_ENTER("my_error"); DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d", nr, MyFlags, errno)); /* Search for the error messages array, which could contain the message. */ for (meh_p= my_errmsgs_list; meh_p; meh_p= meh_p->meh_next) if (nr <= meh_p->meh_last) break; /* get the error message string. Default, if NULL or empty string (""). */ if (! (format= (meh_p && (nr >= meh_p->meh_first)) ? meh_p->meh_errmsgs[nr - meh_p->meh_first] : NULL) || ! *format) (void) my_snprintf(ebuff, sizeof(ebuff), "Unknown error %d", nr); else { va_start(args,MyFlags); (void) my_vsnprintf(ebuff, sizeof(ebuff), format, args); va_end(args); } (*error_handler_hook)(nr, ebuff, MyFlags); DBUG_VOID_RETURN; }
//CGI这个值得一看 int run_cgi(struct conn *c, const char *prog) { struct env_block blk; char dir[FILENAME_MAX], *p; int ret, pair[2]; prepare_environment(c, prog, &blk); /* CGI must be executed in its own directory */ (void) my_snprintf(dir, sizeof(dir), "%s", prog); for (p = dir + strlen(dir) - 1; p > dir; p--) if (*p == '/') { *p++ = '\0'; break; } if (my_socketpair(c, pair) != 0) { ret = -1; } else if (spawn_process(c, prog, blk.buf, blk.vars, pair[1], dir)) { ret = -1; (void) closesocket(pair[0]); (void) closesocket(pair[1]); } else { ret = 0; c->loc.chan.sock = pair[0]; } return (ret); }
/************************************************************************** return a unique guest name WARNING: do not pass pconn->username to this function: it won't return! **************************************************************************/ void get_unique_guest_name(char *name) { unsigned int i; /* first see if the given name is suitable */ if (is_guest_name(name) && !find_conn_by_user(name)) { return; } /* next try bare guest name */ mystrlcpy(name, GUEST_NAME, MAX_LEN_NAME); if (!find_conn_by_user(name)) { return; } /* bare name is taken, append numbers */ for (i = 1; ; i++) { my_snprintf(name, MAX_LEN_NAME, "%s%u", GUEST_NAME, i); /* attempt to find this name; if we can't we're good to go */ if (!find_conn_by_user(name)) { break; } } }
/**************************************************************** ... *****************************************************************/ void popup_rates_dialog(void) { Position x, y; Dimension width, height; char buf[64]; if (!can_client_issue_orders()) { return; } XtSetSensitive(main_form, FALSE); create_rates_dialog(); XtVaGetValues(toplevel, XtNwidth, &width, XtNheight, &height, NULL); XtTranslateCoords(toplevel, (Position) width/10, (Position) height/10, &x, &y); XtVaSetValues(rates_dialog_shell, XtNx, x, XtNy, y, NULL); my_snprintf(buf, sizeof(buf), _("%s max rate: %d%%"), government_name_for_player(client.conn.playing), get_player_bonus(client.conn.playing, EFT_MAX_RATES)); xaw_set_label(rates_gov_label, buf); XtPopup(rates_dialog_shell, XtGrabNone); }
my_bool check_drop(uint audit_class,MYSQL* mysql,char* table) { char* pfile,*pdate; char sql[FN_LEN] = {0}; if(!mysql || !table) return FALSE; my_snprintf(sql,FN_LEN,"DROP TABLE %s", table); pdate = get_current_datetime(audit_datetime); if(audit_class == 2) { opt_audit_class = 2; if(!execute_no_query(mysql,sql)) return FALSE; pfile = get_audit_file_name(audit_name,FILE_NAME_LEN); return check_file_result(pfile,pdate,AUDIT_CREATE_NAME.str,mysql->host,mysql->user,sql); } else{ opt_audit_class = 4; if(!execute_no_query(mysql,sql)) return FALSE; pfile = get_audit_table_name(audit_name,FILE_NAME_LEN); return check_table_result(pfile,pdate,"command",AUDIT_CREATE_NAME.str,"host",mysql->host,"user",mysql->user,"query",sql); } }
/* SSL error handling */ static void my_SSL_error(MYSQL *mysql) { ulong ssl_errno= ERR_get_error(); char ssl_error[MAX_SSL_ERR_LEN]; const char *ssl_error_reason; DBUG_ENTER("my_SSL_error"); if (mysql_errno(mysql)) DBUG_VOID_RETURN; if (!ssl_errno) { my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, "Unknown SSL error"); DBUG_VOID_RETURN; } if ((ssl_error_reason= ERR_reason_error_string(ssl_errno))) { my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, ER(CR_SSL_CONNECTION_ERROR), ssl_error_reason); DBUG_VOID_RETURN; } my_snprintf(ssl_error, MAX_SSL_ERR_LEN, "SSL errno=%lu", ssl_errno, mysql->charset); my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, ER(CR_SSL_CONNECTION_ERROR), ssl_error); DBUG_VOID_RETURN; }
void MADB_WIN_TestDsn(my_bool ShowSuccess) { MYSQL *mysql= mysql_init(NULL); SQLHANDLE Connection= NULL; SQLRETURN ret; MADB_Dsn *Dsn= (MADB_Dsn *)GetWindowLongPtr(GetParent(hwndTab[0]), DWLP_USER); GetDialogFields(); SQLAllocHandle(SQL_HANDLE_DBC, Environment, (SQLHANDLE *)&Connection); assert(Connection != NULL); ret= ((MADB_Dbc *)Connection)->Methods->ConnectDB((MADB_Dbc *)Connection, Dsn); if (ShowSuccess) { char Info[1024]; if (ret == SQL_SUCCESS) my_snprintf(Info, 1024, "Connection successfully established\n\nServer information: %s", mysql_get_server_info(((MADB_Dbc *)Connection)->mariadb)); MessageBox(hwndTab[CurrentPage], (ret == SQL_SUCCESS) ? Info : ((MADB_Dbc *)Connection)->Error.SqlErrorMsg, "Connection test",MB_ICONINFORMATION| MB_OK); } if (ret == SQL_SUCCESS) { ConnectionOK= TRUE; DSN_Set_CharacterSets(Connection); DSN_Set_Database(Connection); } SQLDisconnect(Connection); SQLFreeHandle(SQL_HANDLE_DBC, Connection); }
/// \brief Get a comma-separated list of Check names /// /// The check names are translated with gettext except when in robot mode. /// /// \param buf Buffer to hold the resulting string /// \param checks Bit mask of Checks to print /// \param space_after_comma /// It's better to not use spaces in table-like listings, /// but in more verbose formats a space after a comma /// is good for readability. static void get_check_names(char buf[CHECKS_STR_SIZE], uint32_t checks, bool space_after_comma) { // If we get called when there are no Checks to print, set checks // to 1 so that we print "None". This can happen in the robot mode // when printing the totals line if there are no valid input files. if (checks == 0) checks = 1; char *pos = buf; size_t left = CHECKS_STR_SIZE; const char *sep = space_after_comma ? ", " : ","; bool comma = false; for (size_t i = 0; i <= LZMA_CHECK_ID_MAX; ++i) { if (checks & (UINT32_C(1) << i)) { my_snprintf(&pos, &left, "%s%s", comma ? sep : "", opt_robot ? check_names[i] : _(check_names[i])); comma = true; } } return; }
/************************************************************************** Log city messages, they will appear like this 2: Polish Romenna(5,35) [s1 d106 u11 g1] must have Archers ... **************************************************************************/ void CITY_LOG(int level, const struct city *pcity, const char *msg, ...) { char buffer[500]; char buffer2[500]; va_list ap; int minlevel = MIN(LOGLEVEL_CITY, level); if (pcity->debug) { minlevel = LOG_TEST; } else if (minlevel > fc_log_level) { return; } my_snprintf(buffer, sizeof(buffer), "%s %s(%d,%d) [s%d d%d u%d g%d] ", nation_rule_name(nation_of_city(pcity)), city_name(pcity), TILE_XY(pcity->tile), pcity->size, pcity->ai->danger, pcity->ai->urgency, pcity->ai->grave_danger); va_start(ap, msg); my_vsnprintf(buffer2, sizeof(buffer2), msg, ap); va_end(ap); cat_snprintf(buffer, sizeof(buffer), "%s", buffer2); if (pcity->debug) { notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer); } freelog(minlevel, "%s", buffer); }
// context switch static unsigned formatter_ctx_switch(Tb_entry *tb, const char *tidstr, unsigned tidlen, char *buf, int maxlen) { char symstr[24], spcstr[16] = ""; Tb_entry_ctx_sw *e = static_cast<Tb_entry_ctx_sw*>(tb); Context *sctx = 0; Mword sctxid = ~0UL; Mword dst; Mword dst_orig; sctx = e->from_sched()->context(); sctxid = static_cast<Thread*>(sctx)->dbg_id(); dst = static_cast<Thread const *>(e->dst())->dbg_id(); dst_orig = static_cast<Thread const *>(e->dst_orig())->dbg_id(); Address addr = e->kernel_ip(); if (!Jdb_symbol::match_addr_to_symbol_fuzzy(&addr, 0 /*kernel*/, symstr, sizeof(symstr))) snprintf(symstr, sizeof(symstr), L4_PTR_FMT, e->kernel_ip()); my_snprintf(buf, maxlen, " %-*s%s '%02lx", tidlen, tidstr, spcstr, e->from_prio()); if (sctx != e->ctx()) my_snprintf(buf, maxlen, "(%lx)", sctxid); my_snprintf(buf, maxlen, " ==> %lx ", dst); if (dst != dst_orig || e->lock_cnt()) my_snprintf(buf, maxlen, "("); if (dst != dst_orig) my_snprintf(buf, maxlen, "want %lx", dst_orig); if (dst != dst_orig && e->lock_cnt()) my_snprintf(buf, maxlen, " "); if (e->lock_cnt()) my_snprintf(buf, maxlen, "lck %ld", e->lock_cnt()); if (dst != dst_orig || e->lock_cnt()) my_snprintf(buf, maxlen, ") "); my_snprintf(buf, maxlen, " krnl %s", symstr); return maxlen; }
/**************************************************************** Fills the buf with proper text which should be displayed on the helpbuild wonder button. *****************************************************************/ static void get_help_build_wonder_button_label(char* buf, int bufsize, bool* help_build_possible) { struct city* destcity = game_find_city_by_number(caravan_city_id); struct unit* caravan = game_find_unit_by_number(caravan_unit_id); if (destcity && caravan && unit_can_help_build_wonder(caravan, destcity)) { my_snprintf(buf, bufsize, _("Help build _Wonder (%d remaining)"), impr_build_shield_cost(destcity->production.value.building) - destcity->shield_stock); *help_build_possible = TRUE; } else { my_snprintf(buf, bufsize, _("Help build _Wonder")); *help_build_possible = FALSE; } }
/************************************************************************** Called by the GUI code when the user sets the ruleset. The ruleset passed in here should match one of the strings given to gui_set_rulesets. **************************************************************************/ void set_ruleset(const char *ruleset) { char buf[4096]; my_snprintf(buf, sizeof(buf), "/read %s%s", ruleset, RULESET_SUFFIX); freelog(LOG_DEBUG, "Executing '%s'", buf); send_chat(buf); }
int main (int argc, char *argv[]) { char buf[8]; int size; int retval; retval = my_snprintf (NULL, 0, "%d", 12345); ASSERT (retval == 5); for (size = 0; size <= 8; size++) { memcpy (buf, "DEADBEEF", 8); retval = my_snprintf (buf, size, "%d", 12345); ASSERT (retval == 5); if (size < 6) { if (size > 0) { ASSERT (memcmp (buf, "12345", size - 1) == 0); ASSERT (buf[size - 1] == '\0' || buf[size - 1] == '0' + size); } #if !CHECK_VSNPRINTF_POSIX if (size > 0) #endif ASSERT (memcmp (buf + size, &"DEADBEEF"[size], 8 - size) == 0); } else { ASSERT (memcmp (buf, "12345\0EF", 8) == 0); } } /* Test the support of the POSIX/XSI format strings with positions. */ { char result[100]; retval = my_snprintf (result, sizeof (result), "%2$d %1$d", 33, 55); ASSERT (strcmp (result, "55 33") == 0); ASSERT (retval == strlen (result)); } return 0; }
static const char* get_collation_name_alias(const char *name, char *buf, size_t bufsize) { if (!strncasecmp(name, "utf8mb3_", 8)) { my_snprintf(buf, bufsize, "utf8_%s", name + 8); return buf; } return NULL; }
/************************************************************************** Verifies that a password is valid. Does some [very] rudimentary safety checks. TODO: do we want to frown on non-printing characters? Fill the msg (length MAX_LEN_MSG) with any worthwhile information that the client ought to know. **************************************************************************/ static bool is_good_password(const char *password, char *msg) { int i, num_caps = 0, num_nums = 0; /* check password length */ if (strlen(password) < MIN_PASSWORD_LEN) { my_snprintf(msg, MAX_LEN_MSG, _("Your password is too short, the minimum length is %d. " "Try again."), MIN_PASSWORD_LEN); return FALSE; } my_snprintf(msg, MAX_LEN_MSG, _("The password must have at least %d capital letters, %d " "numbers, and be at minimum %d [printable] characters long. " "Try again."), MIN_PASSWORD_CAPS, MIN_PASSWORD_NUMS, MIN_PASSWORD_LEN); for (i = 0; i < strlen(password); i++) { if (my_isupper(password[i])) { num_caps++; } if (my_isdigit(password[i])) { num_nums++; } } /* check number of capital letters */ if (num_caps < MIN_PASSWORD_CAPS) { return FALSE; } /* check number of numbers */ if (num_nums < MIN_PASSWORD_NUMS) { return FALSE; } if (!is_ascii_name(password)) { return FALSE; } return TRUE; }
int64_t read_locations(const char *filename, const int64_t ntrees, struct locations *l, int *num_files, int *box_div) { char buffer[MAXBUFSIZE]; int max_fileid = 0; const char comment = '#'; /* By passing the comment character, getnumlines will return the actual number of lines, ignoring the first header line. */ struct locations *locations = l; int64_t ntrees_found = 0; FILE *fp = my_fopen(filename, "r"); while(fgets(buffer, MAXBUFSIZE, fp) != NULL) { if(buffer[0] == comment) { continue; } else { const int nitems_expected = 4; char linebuf[MAXLEN]; XASSERT(ntrees_found < ntrees, "ntrees=%"PRId64" should be less than ntrees_found=%"PRId64"\n", ntrees, ntrees_found); int nitems = sscanf(buffer, "%"SCNd64" %"SCNd64 " %"SCNd64 "%s", &(locations[ntrees_found].tree_root), &(locations[ntrees_found].fileid), &(locations[ntrees_found].offset), linebuf); /* The filename is separated out to save memory but I want to ensure that the actual filename does not get truncated. The filename field might actually be removed later. */ my_snprintf(locations[ntrees_found].filename, LOCATIONS_FILENAME_SIZE, "%s", linebuf); XASSERT(nitems == nitems_expected, "Expected to parse two long integers but found `%s' in the buffer\n", buffer); ntrees_found++; } } XASSERT(ntrees == ntrees_found, "ntrees=%"PRId64" should be equal to ntrees_found=%"PRId64"\n", ntrees, ntrees_found); fclose(fp); for(int i=0;i<ntrees_found;i++){ if (locations[i].fileid > max_fileid) { max_fileid = locations[i].fileid; } } /* number of files is one greater from 0 based indexing of C files */ *num_files = max_fileid + 1; const int box_divisions = (int) round(cbrt(*num_files)); const int box_cube = box_divisions * box_divisions * box_divisions; XASSERT( (box_cube) == (*num_files), "box_divisions^3=%d should be equal to nfiles=%d\n", box_cube, *num_files); *box_div = box_divisions; return ntrees_found; }
void dbg_log(const char *format, ...) { int s=0; char buffer[1024*4]; va_list ap; va_start(ap, format); #if HAM_DEBUG s=my_snprintf (buffer, sizeof(buffer), "%s[%d]: ", g_file, g_line); util_vsnprintf(buffer+s, sizeof(buffer)-s, format, ap); #else if (g_function) s=my_snprintf(buffer, sizeof(buffer), "%s: ", g_function); util_vsnprintf (buffer+s, sizeof(buffer)-s, format, ap); #endif va_end(ap); g_hand(g_level, buffer); }
/* ----------------------------------------------------------------------------- Function: FS_FindFirstFile() -Searches a directory for a file. Parameters: path -[in] Pointer to a NUL-terminated string that specifies a valid directory or path and file name. musthave -[in] File or directory must have these attributes. canthave- [in] File or directory can not have these attributes. Returns: On success string of file name or directory, otherwise NULL. Notes: ----------------------------------------------------------------------------- */ PUBLIC char *FS_FindFirst( const char *path, W32 musthave, W32 canthave ) { struct dirent *d; char *p; p; if( fdir ) { Com_Printf( "FS_FindFirst without close\n" ); return NULL; } FS_FilePath( (char *)path, findbase ); my_strlcpy( (char *)findpattern, FS_SkipPath( (char *)path ), sizeof( findpattern ) ); if( ! *findbase ) { if( (fdir = opendir( "." )) == NULL ) { return NULL; } } else { if( (fdir = opendir( findbase )) == NULL ) { return NULL; } } while( (d = readdir( fdir )) != NULL ) { if( ! *findpattern || glob_match( findpattern, d->d_name ) ) { if( ! *findbase ) { my_strlcpy( findpath, d->d_name, sizeof( findpath ) ); } else { my_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, d->d_name ); } if( CompareAttributes( findpath, musthave, canthave ) ) { return findpath; } } } return NULL; }
/* {{{ MADB_DsnToString */ SQLSMALLINT MADB_DsnToString(MADB_Dsn *Dsn, char *OutString, SQLSMALLINT OutLength) { int i= 0; SQLSMALLINT TotalLength= 0; char *p= OutString; unsigned long Options= 0; char *Value= NULL; char TmpStr[1024]; char IntVal[12]; int CpyLength; if (OutLength && OutString) OutString[0]= '\0'; while (DsnKeys[i].DsnKey) { Value= NULL; if (!DsnKeys[i].IsAlias) { switch (DsnKeys[i].Type) { case DSN_TYPE_STRING: case DSN_TYPE_COMBO: Value= *(char **)((char *)Dsn + DsnKeys[i].DsnOffset); break; case DSN_TYPE_INT: if (*(int *)((char *)Dsn + DsnKeys[i].DsnOffset)) { _itoa_s(*(int *)((char *)Dsn + DsnKeys[i].DsnOffset), IntVal, 12, 10); Value= IntVal; } break; case DSN_TYPE_OPTION: if(*(my_bool *)((char *)Dsn + DsnKeys[i].DsnOffset)) Options+= DsnKeys[i].FlagValue; /* we save all boolean values in options */ Value= NULL; break; } } if (Value) { my_bool isSpecial= (strchr(Value, ' ') || strchr(Value, ';') || strchr(Value, '@')); CpyLength= my_snprintf(TmpStr + TotalLength, 1024 - TotalLength, "%s%s=%s%s%s", (TotalLength) ? ";" : "", DsnKeys[i].DsnKey, isSpecial ? "{" : "", Value, isSpecial ? "}" : ""); TotalLength+= CpyLength; } ++i; } if (OutLength && OutString) strncpy_s(OutString, OutLength, TmpStr, TotalLength); return TotalLength; }
/************************************************************************** Log unit messages, they will appear like this 2: Polish Archers[139] (5,35)->(0,0){0,0} stays to defend city where [] is unit id, ()->() are coordinates present and goto, and {,} contains bodyguard and ferryboat ids. **************************************************************************/ void UNIT_LOG(int level, const struct unit *punit, const char *msg, ...) { char buffer[500]; char buffer2[500]; va_list ap; int minlevel = MIN(LOGLEVEL_UNIT, level); int gx, gy; bool messwin = FALSE; /* output to message window */ if (punit->debug) { minlevel = LOG_TEST; } else { /* Are we a virtual unit evaluated in a debug city?. */ if (punit->id == 0) { struct city *pcity = tile_city(punit->tile); if (pcity && pcity->debug) { minlevel = LOG_TEST; messwin = TRUE; } } if (minlevel > fc_log_level) { return; } } if (punit->goto_tile) { gx = punit->goto_tile->x; gy = punit->goto_tile->y; } else { gx = gy = -1; } my_snprintf(buffer, sizeof(buffer), "%s %s[%d] %s (%d,%d)->(%d,%d){%d,%d} ", nation_rule_name(nation_of_unit(punit)), unit_rule_name(punit), punit->id, get_activity_text(punit->activity), TILE_XY(punit->tile), gx, gy, punit->ai.bodyguard, punit->ai.ferryboat); va_start(ap, msg); my_vsnprintf(buffer2, sizeof(buffer2), msg, ap); va_end(ap); cat_snprintf(buffer, sizeof(buffer), "%s", buffer2); if (punit->debug || messwin) { notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer); } freelog(minlevel, "%s", buffer); }
/************************************************************************** Check if the password with length len matches the hashed one in pconn->server.password. ***************************************************************************/ static bool authdb_check_password(struct connection *pconn, const char *password, int len) { #ifdef HAVE_AUTH bool ok = FALSE; char buffer[512] = ""; const int bufsize = sizeof(buffer); char checksum[MD5_HEX_BYTES + 1]; MYSQL *sock, mysql; /* do the password checking right here */ create_md5sum((const unsigned char *)password, len, checksum); ok = (strncmp(checksum, pconn->server.password, MD5_HEX_BYTES) == 0) ? TRUE : FALSE; /* we don't really need the stuff below here to * verify password, this is just logging */ mysql_init(&mysql); /* attempt to connect to the server */ if ((sock = mysql_real_connect(&mysql, auth_config.host.value, auth_config.user.value, auth_config.password.value, auth_config.database.value, atoi(auth_config.port.value), NULL, 0))) { char *name_buffer = alloc_escaped_string(&mysql, pconn->username); int str_result; if (name_buffer != NULL) { /* insert an entry into our log */ str_result = my_snprintf(buffer, bufsize, "insert into %s (name, logintime, address, succeed) " "values ('%s',unix_timestamp(),'%s','%s')", auth_config.login_table.value, name_buffer, pconn->server.ipaddr, ok ? "S" : "F"); if (str_result < 0 || str_result >= bufsize || mysql_query(sock, buffer)) { freelog(LOG_ERROR, "check_pass insert loginlog failed for user: %s (%s)", pconn->username, mysql_error(sock)); } free_escaped_string(name_buffer); name_buffer = NULL; } mysql_close(sock); } else { freelog(LOG_ERROR, "Can't connect to server! (%s)", mysql_error(&mysql)); } return ok; #else /* HAVE_AUTH */ return TRUE; #endif /* HAVE_AUTH */ }
int mgmapi_error_string(int err_no, char *str, int size) { int i; for (i= 0; i < ndb_mgm_noOfErrorMsgs; i++) { if ((int)ndb_mgm_error_msgs[i].code == err_no) { my_snprintf(str, size-1, "%s", ndb_mgm_error_msgs[i].msg); str[size-1]= '\0'; return 0; } } return -1; }
// kernel event log binary data static unsigned formatter_ke_bin(Tb_entry *tb, const char *tidstr, unsigned tidlen, char *buf, int maxlen) { Tb_entry_ke_bin *e = static_cast<Tb_entry_ke_bin*>(tb); char ip_buf[32]; snprintf(ip_buf, sizeof(ip_buf), " @ "L4_PTR_FMT, e->ip()); my_snprintf(buf, maxlen, "ke: %-*s BINDATA %s", tidlen, tidstr, e->ip() ? ip_buf : ""); return maxlen; }