本文整理汇总了C++中safe_snprintf函数的典型用法代码示例。如果您正苦于以下问题:C++ safe_snprintf函数的具体用法?C++ safe_snprintf怎么用?C++ safe_snprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safe_snprintf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: open_chat_log
void open_chat_log() {
char starttime[200], sttime[200];
struct tm *l_time;
time_t c_time;
char chat_log_file[100];
char srv_log_file[100];
time(&c_time);
l_time = localtime(&c_time);
if (get_rotate_chat_log())
{
char logsuffix[7];
strftime(logsuffix, sizeof(logsuffix), "%Y%m", l_time);
safe_snprintf (chat_log_file, sizeof (chat_log_file), "chat_log_%s.txt", logsuffix);
safe_snprintf (srv_log_file, sizeof (srv_log_file), "srv_log_%s.txt", logsuffix);
}
else
{
safe_strncpy(chat_log_file, "chat_log.txt", sizeof(chat_log_file));
safe_strncpy(srv_log_file, "srv_log.txt", sizeof(srv_log_file));
}
chat_log = open_file_config (chat_log_file, "a");
if (log_chat == LOG_SERVER || log_chat == LOG_SERVER_SEPERATE)
srv_log = open_file_config (srv_log_file, "a");
if (chat_log == NULL)
{
LOG_TO_CONSOLE(c_red3, "Unable to open log file to write. We will NOT be recording anything.");
log_chat = LOG_NONE;
return;
}
else if ((log_chat == LOG_SERVER || log_chat == LOG_SERVER_SEPERATE) && srv_log == NULL)
{
LOG_TO_CONSOLE(c_red3, "Unable to open server log file to write. We will fall back to recording everything in chat_log.txt.");
log_chat = LOG_CHAT;
return;
}
strftime(sttime, sizeof(sttime), "\n\nLog started at %Y-%m-%d %H:%M:%S localtime", l_time);
safe_snprintf(starttime, sizeof(starttime), "%s (%s)\n\n", sttime, tzname[l_time->tm_isdst>0]);
fwrite (starttime, strlen(starttime), 1, chat_log);
}
示例2: ResetLog
void ResetLog()
{
if (g_log)
{
char logfilename[_MAX_PATH];
safe_snprintf(logfilename, _MAX_PATH, "%s.log", g_Mapname);
_unlink(logfilename);
}
}
示例3: chilli_module_load
int chilli_module_load(void **ctx, char *name)
{
struct chilli_module *m;
char path[512];
void *lib_handle;
char *error;
void *sym;
int len;
safe_snprintf(path, sizeof(path), "%s/%s.so",
_options.moddir ? _options.moddir : DEFLIBDIR, name);
lib_handle = dlopen(path, RTLD_NOW | RTLD_LOCAL);
if (!lib_handle) {
log_err(errno, "chilli_module_load() %s", dlerror());
return -1;
}
safe_snprintf(path, sizeof(path), "%s_module", name);
len = strlen(path);
while (len-- > 0)
if (path[len] == '-')
path[len] = '_';
sym = dlsym(lib_handle, path);
if ((error = dlerror()) != NULL) {
dlclose(lib_handle);
log_err(errno, "%s", error);
return -1;
}
m = (struct chilli_module *)sym;
m->lib = lib_handle;
log_dbg("Loaded module %s", name);
*ctx = m;
return 0;
}
示例4: strlen
int redis_zset::zrangebyscore_get(const char* cmd, const char* key,
const char* min, const char* max, std::vector<string>* out,
const int* offset /* = NULL */, const int* count /* = NULL */)
{
const char* argv[8];
size_t lens[8];
size_t argc = 4;
argv[0] = cmd;
lens[0] = strlen(cmd);
argv[1] = key;
lens[1] = strlen(key);
argv[2] = min;
lens[2] = strlen(min);
argv[3] = max;
lens[3] = strlen(max);
char offset_s[INTLEN], count_s[INTLEN];
if (offset && count)
{
safe_snprintf(offset_s, sizeof(offset_s), "%d", *offset);
safe_snprintf(count_s, sizeof(count_s), "%d", *count);
argv[4] = "LIMIT";
lens[4] = sizeof("LIMIT") - 1;
argv[5] = offset_s;
lens[5] = strlen(offset_s);
argv[6] = count_s;
lens[6] = strlen(count_s);
argc += 3;
}
hash_slot(key);
build_request(argc, argv, lens);
return get_strings(out);
}
示例5: createAllHostsMap
void createAllHostsMap(void) {
HostTraffic *el;
int num_hosts = 0;
sendString((char*)map_head);
//sendString(googleMapsKey);
sendString((char*)map_head2);
sendString((char*)map_head3);
sendString((char*)map_head4);
for(el=getFirstHost(myGlobals.actualReportDeviceId);
el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) {
if(el->geo_ip) {
char buf[512];
#if 0
char buf1[256] = { 0 };
int showSymIp;
if((el->hostResolvedName[0] != '\0')
&& strcmp(el->hostResolvedName, el->hostNumIpAddress)
&& (!subnetPseudoLocalHost(el)))
showSymIp = 1;
else
showSymIp = 0;
#endif
safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf),
"createMarker(new google.maps.LatLng(%.2f, %.2f), \""
#if 0
"%s%s"
#endif
"<A HREF=/%s.html>%s</A><br>%s<br>%s\");\n",
el->geo_ip->latitude, el->geo_ip->longitude,
#if 0
showSymIp ? escape_string(el->hostResolvedName, buf1, sizeof(buf1)) : "", showSymIp ? "<br>" : "",
#endif
el->hostNumIpAddress, el->hostNumIpAddress,
el->geo_ip->city ? el->geo_ip->city : "",
el->geo_ip->country_name ? el->geo_ip->country_name : "");
sendString(buf);
num_hosts++;
if(num_hosts > MAX_NUM_MAP_HOSTS) break; /* Too many hosts */
}
}
sendString((char*)map_tail);
if(num_hosts > MAX_NUM_MAP_HOSTS)
sendString("<p><center><b><font color=red>WARNING:</font></b>You have more hosts to display than the number typically supported by Google maps. Some hosts have not been rendered.</center></p>");
// sendString("<p><center><b><font color=red>NOTE:</font></b> ");
// sendString("make sure you get your key <a href=http://code.google.com/apis/maps/>here</A>"
// " for using Google Maps from ntop and register it as \'google_maps.key\' key <A href=/"CONST_EDIT_PREFS"#google_maps.key>here</A>.</center></p>\n");
}
示例6: writePid
static int writePid( int fd, pid_t pid )
{
char achBuf[20];
int len = safe_snprintf( achBuf, 20, "%d\n", (int)pid );
if ( ftruncate( fd, 0 ) || (nio_write( fd, achBuf, len ) != len) )
{
nio_close( fd );
return -1;
}
return fd;
}
示例7: hlassume
// =====================================================================================
// hlassume
// my assume
// =====================================================================================
void hlassume(bool exp, assume_msgs msgid)
{
if (!exp)
{
char message[MAX_MESSAGE];
const MessageTable_t* msg = GetAssume(msgid);
safe_snprintf(message, MAX_MESSAGE, "%s\nDescription: %s\nHowto Fix: %s\n", msg->title, msg->text, msg->howto);
Error(message);
}
}
示例8: formatSeconds
char* formatSeconds(unsigned long sec, char* outStr, int outStrLen) {
u_int hour = 0, min = 0, days = 0;
if(sec >= 3600) {
hour = (u_int)(sec / 3600);
if(hour > 0) {
if(hour >= 24) {
days = (hour / 24);
hour = hour % 24;
sec -= days*86400;
}
sec -= hour*3600;
} else
hour = 0;
}
min = (u_int)(sec / 60);
if(min > 0) sec -= min*60;
if(days > 0) {
char yearStr[32];
if(days > 365) {
safe_snprintf(__FILE__, __LINE__, yearStr, sizeof(yearStr), "%d years, ", days/365);
days %= 365;
} else
yearStr[0] = '\0';
safe_snprintf(__FILE__, __LINE__, outStr, outStrLen, "%s%u day%s %u:%02u:%02lu",
yearStr, days, (days>1)?"s":"", hour, min, sec);
} else if(hour > 0) {
safe_snprintf(__FILE__, __LINE__, outStr, outStrLen, "%u:%02u:%02lu", hour, min, sec);
} else if(min > 0) {
safe_snprintf(__FILE__, __LINE__, outStr, outStrLen, "%u:%02lu", min, sec);
} else {
safe_snprintf(__FILE__, __LINE__, outStr, outStrLen, "%lu sec", sec);
}
return(outStr);
}
示例9: rtmon_print_ifaces
void rtmon_print_ifaces(struct rtmon_t *rtmon, int fd) {
char line[512];
int i;
safe_snprintf(line,512,"\nSystem Interfaces\n");
safe_write(fd, line, strlen(line));
for (i=0; i < rtmon->_iface_sz; i++) {
if (rtmon->_ifaces[i].has_data) {
unsigned char *u = rtmon->_ifaces[i].hwaddr;
safe_snprintf(line,512,"%d) %s (%d)",
i, rtmon->_ifaces[i].devname, rtmon->_ifaces[i].index);
safe_write(fd, line, strlen(line));
if (rtmon->_ifaces[i].address.s_addr) {
safe_snprintf(line,512," ip=%s", inet_ntoa(rtmon->_ifaces[i].address));
safe_write(fd, line, strlen(line));
}
safe_snprintf(line,512," net=%s", inet_ntoa(rtmon->_ifaces[i].network));
safe_write(fd, line, strlen(line));
safe_snprintf(line,512," mask=%s", inet_ntoa(rtmon->_ifaces[i].netmask));
safe_write(fd, line, strlen(line));
if (rtmon->_ifaces[i].broadcast.s_addr) {
safe_snprintf(line,512," bcase=%s", inet_ntoa(rtmon->_ifaces[i].broadcast));
safe_write(fd, line, strlen(line));
}
if (rtmon->_ifaces[i].gateway.s_addr) {
safe_snprintf(line,512," peer=%s", inet_ntoa(rtmon->_ifaces[i].gateway));
safe_write(fd, line, strlen(line));
}
safe_snprintf(line,512," mac=%2.2X-%2.2X-%2.2X-%2.2X-%2.2X-%2.2x",
u[0], u[1], u[2], u[3], u[4], u[5]);
safe_write(fd, line, strlen(line));
safe_snprintf(line,512," mtu=%u\n", rtmon->_ifaces[i].mtu);
safe_write(fd, line, strlen(line));
}
}
}
示例10: createHostMap
void createHostMap(HostTraffic *host) {
HostTraffic *el;
int num_hosts = 0;
sendString((char*)map_head);
//sendString(googleMapsKey);
sendString((char*)map_head2);
sendString((char*)map_head4);
for(el=getFirstHost(myGlobals.actualReportDeviceId);
el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) {
if((el->l2Host == host->l2Host) && (el->hostIpAddress.hostFamily == host->hostIpAddress.hostFamily)) {
if((CM_PointEst(host->sent_to_matrix, el->serialHostIndex) > 0)
|| (CM_PointEst(host->recv_from_matrix, el->serialHostIndex) > 0)) {
if(el->geo_ip) {
char buf[512];
#if 0
char buf1[256] = { 0 };
int showSymIp;
if((el->hostResolvedName[0] != '\0')
&& strcmp(el->hostResolvedName, el->hostNumIpAddress)
&& (!privateIPAddress(el)))
showSymIp = 1;
else
showSymIp = 0;
#endif
safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf),
"createMarker(new google.maps.LatLng(%.2f, %.2f), \""
#if 0
"%s%s"
#endif
"<A HREF=/%s.html>%s</A><br>%s<br>%s\");\n",
el->geo_ip->latitude, el->geo_ip->longitude,
#if 0
showSymIp ? escape_string(el->hostResolvedName, buf1, sizeof(buf1)) : "",
showSymIp ? "<br>" : "",
#endif
el->hostNumIpAddress, el->hostNumIpAddress,
el->geo_ip->city ? el->geo_ip->city : "",
el->geo_ip->country_name ? el->geo_ip->country_name : "");
sendString(buf);
num_hosts++;
if(num_hosts > MAX_NUM_MAP_HOSTS) break; /* Too many hosts */
}
}
}
}
sendString((char*)map_tail2);
}
示例11: safe_snprintf
char *datalinkname(int type)
{
static char name[TEXTSIZE];
int i;
for (i = 0; datalinktypes[i].name; i++)
if (datalinktypes[i].type == type)
return datalinktypes[i].name;
safe_snprintf(name, TEXTSIZE, "#%d", type);
return name;
}
示例12: chartohex
static int chartohex(unsigned char *src, char *dst, int len) {
char x[3];
int n;
for (n=0; n < len; n++) {
safe_snprintf(x, sizeof(x), "%.2x", src[n]);
dst[n*2+0] = x[0];
dst[n*2+1] = x[1];
}
dst[len*2] = 0;
return 0;
}
示例13: click_change_buddy_handler
static int click_change_buddy_handler(widget_list *w, int mx, int my, Uint32 flags)
{
char string[255];
int send_message = 1;
if(buddy_delete) {
safe_snprintf(string, sizeof(string), "%c#del_buddy %s", RAW_TEXT, buddy_to_change);
buddy_delete = 0;
} else if (buddy_type_input_id != -1) {
safe_snprintf(string, sizeof(string), "%c#change_buddy %s %i", RAW_TEXT, buddy_to_change, multiselect_get_selected(buddy_change_win, buddy_type_input_id));
} else {
send_message = 0;
}
if (send_message) {
my_tcp_send(my_socket, (Uint8*)string, strlen(string+1)+1);
}
destroy_window(buddy_change_win);
buddy_change_win = -1;
buddy_to_change = NULL;
return 1;
}
示例14: GetWadConfig
// =====================================================================================
bool GetWadConfig(FILE* wadcfg, wadconfig_t* wadconfig)
{
char TokenBuffer[MAX_TOKENBUFFER];
wadname_t* current;
wadname_t* previous;
while (!feof(wadcfg))
{
Safe_GetToken(wadcfg, TokenBuffer, MAX_TOKENBUFFER);
if (!strcmp(TokenBuffer, "}"))
return true; // no more work to do
if (!strcmp(TokenBuffer, ";"))
continue; // old seperator, no longer used but here for backwards compadibility
if (!strcmp(TokenBuffer, "{")) // wtf
{
WadCfgParseError("Expected wadpath (Nested blocks illegal)", g_wadcfglinecount, TokenBuffer);
return false;
}
// otherwise assume its a wadpath, make an entry in this configuration
current = (wadname_t*)malloc(sizeof(wadname_t));
wadconfig->entries++;
current->next = NULL;
current->wadinclude = false;
if (!strcmp(TokenBuffer, "include"))
{
current->wadinclude = true;
Safe_GetToken(wadcfg, TokenBuffer, MAX_TOKENBUFFER);
}
strcpy_s(current->wadname, TokenBuffer);
if (!wadconfig->firstentry)
{
wadconfig->firstentry = current;
}
else
{
previous->next = current;
}
previous = current;
previous->next = NULL;
}
safe_snprintf(TokenBuffer, MAX_TOKENBUFFER, "Unexptected end of file encountered while parsing configuration '%s'", wadconfig->name);
WadCfgParseError(TokenBuffer, g_wadcfglinecount, "(eof)");
return false;
}
示例15: floatingmessages_compare_stat
void floatingmessages_compare_stat(int actor_id, int value, int new_value, const unsigned char *skillname)
{
char str[50];
int diff=new_value-value;
safe_snprintf(str, sizeof(str), "%s: %c%d", skillname, diff<0?' ':'+', diff);
if(diff<0)
add_floating_message(actor_id, str, FLOATINGMESSAGE_SOUTH, 1.0, 0.3, 0.3,1500);
else
add_floating_message(actor_id, str, FLOATINGMESSAGE_NORTH, 0.3, 1.0, 0.3,1500);
}