本文整理汇总了C++中safe_snprintf函数的典型用法代码示例。如果您正苦于以下问题:C++ safe_snprintf函数的具体用法?C++ safe_snprintf怎么用?C++ safe_snprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safe_snprintf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:eponymous,项目名称:Eternal-Lands,代码行数:43,代码来源:text.c
示例2: ResetLog
void ResetLog()
{
if (g_log)
{
char logfilename[_MAX_PATH];
safe_snprintf(logfilename, _MAX_PATH, "%s.log", g_Mapname);
_unlink(logfilename);
}
}
开发者ID:bmk10,项目名称:sing-engine,代码行数:10,代码来源:log.cpp
示例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;
}
开发者ID:kernel-digger,项目名称:coova-chilli,代码行数:42,代码来源:chilli_module.c
示例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);
}
开发者ID:LazyPlanet,项目名称:acl,代码行数:42,代码来源:redis_zset.cpp
示例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");
}
开发者ID:GabrielDiniz,项目名称:FluxNetControl,代码行数:54,代码来源:map.c
示例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;
}
开发者ID:DSpeichert,项目名称:OpenLiteSpeed,代码行数:11,代码来源:pidfile.cpp
示例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);
}
}
开发者ID:bmk10,项目名称:sing-engine,代码行数:15,代码来源:log.cpp
示例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);
}
开发者ID:nirmoy,项目名称:ntop-cassandra,代码行数:41,代码来源:dataFormat.c
示例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));
}
}
}
开发者ID:Nazninn,项目名称:coova-chilli,代码行数:46,代码来源:rtmon.c
示例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);
}
开发者ID:GabrielDiniz,项目名称:FluxNetControl,代码行数:53,代码来源:map.c
示例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;
}
开发者ID:ginggs,项目名称:maemo-tcptraceroute,代码行数:12,代码来源:datalink.c
示例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;
}
开发者ID:ebichu,项目名称:dd-wrt,代码行数:12,代码来源:main-response.c
示例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;
}
开发者ID:pjbroad,项目名称:other-life,代码行数:21,代码来源:buddy.c
示例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;
}
开发者ID:emileb,项目名称:XashXT,代码行数:54,代码来源:wadcfg.cpp
示例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);
}
开发者ID:Adamantinus,项目名称:Eternal-Lands,代码行数:12,代码来源:stats.c
示例16: memcpy
int StaticFileCacheData::buildFixedHeaders( int etag )
{
int size = 6 + 30 + 17 + RFC_1123_TIME_LEN
+ 20 + m_pMimeType->getMIME()->len() + 10 ;
const char * pCharset;
if ( m_pCharset && HttpMime::needCharset(m_pMimeType->getMIME()->c_str()) )
{
pCharset = m_pCharset->c_str();
size += m_pCharset->len();
}
else
pCharset = "";
if ( !m_sHeaders.resizeBuf( size ) )
return SC_500;
char * pEnd = m_sHeaders.buf() + size;
char *p = m_sHeaders.buf();
m_iFileETag = etag;
memcpy( p, "ETag: ", 6 );
m_pETag = p + 6;
m_iETagLen = safe_snprintf( m_pETag, pEnd - m_pETag,
"\"%lx-%lx-%lx\"",
(unsigned long)m_fileData.getFileSize(),
m_fileData.getLastMod(),
(long)m_fileData.getINode());
p = m_pETag + m_iETagLen;
memcpy( p, "\r\nLast-Modified: ", 17 );
p += 17;
DateTime::getRFCTime( m_fileData.getLastMod(), p );
p += RFC_1123_TIME_LEN;
p += safe_snprintf( p, pEnd - p ,
"\r\nContent-Type: %s%s\r\n",
m_pMimeType->getMIME()->c_str(), pCharset );
m_sHeaders.setLen( p - m_sHeaders.buf() );
m_iValidateHeaderLen = 6 + 17 + 2 + m_iETagLen + RFC_1123_TIME_LEN ;
return 0;
}
开发者ID:lsmichael,项目名称:openlitespeed,代码行数:40,代码来源:staticfilecachedata.cpp
示例17: rtmon_print_routes
void rtmon_print_routes(struct rtmon_t *rtmon, int fd) {
char line[512];
int i;
safe_snprintf(line,512,"\nSystem Routes\n");
safe_write(fd, line, strlen(line));
for (i=0; i < rtmon->_route_sz; i++) {
if (rtmon->_routes[i].has_data) {
safe_snprintf(line,512,"%d) dst=%s", i, inet_ntoa(rtmon->_routes[i].destination));
safe_write(fd, line, strlen(line));
safe_snprintf(line,512," mask=%s", inet_ntoa(rtmon->_routes[i].netmask));
safe_write(fd, line, strlen(line));
if (rtmon->_routes[i].gateway.s_addr) {
safe_snprintf(line,512," gw=%s", inet_ntoa(rtmon->_routes[i].gateway));
safe_write(fd, line, strlen(line));
}
safe_snprintf(line,512," dev=%s (%d)\n", idx2name(rtmon, rtmon->_routes[i].if_index), rtmon->_routes[i].if_index);
safe_write(fd, line, strlen(line));
}
}
}
开发者ID:Nazninn,项目名称:coova-chilli,代码行数:22,代码来源:rtmon.c
示例18: inet_addrtop
const char* DLLCALL inet_addrtop(union xp_sockaddr *addr, char *dest, size_t size)
{
#ifdef _WIN32
if(getnameinfo(&addr->addr, xp_sockaddr_len(addr), dest, size, NULL, 0, NI_NUMERICHOST))
safe_snprintf(dest, size, "<Error %u converting address, family=%u>", WSAGetLastError(), addr->addr.sa_family);
return dest;
#else
switch(addr->addr.sa_family) {
case AF_INET:
return inet_ntop(addr->in.sin_family, &addr->in.sin_addr, dest, size);
case AF_INET6:
return inet_ntop(addr->in6.sin6_family, &addr->in6.sin6_addr, dest, size);
case AF_UNIX:
strncpy(dest, addr->un.sun_path, size);
dest[size-1]=0;
return dest;
default:
safe_snprintf(dest, size, "<unknown address family: %u>", addr->addr.sa_family);
return NULL;
}
#endif
}
开发者ID:carriercomm,项目名称:syncfoss,代码行数:22,代码来源:sockwrap.c
示例19: read_local_book
void read_local_book (const char *data, int len)
{
char file_name[200];
book *b;
safe_snprintf (file_name, sizeof(file_name), "%.*s", len-3, data+3);
b = get_book (SDL_SwapLE16 (*((Uint16*)(data+1))));
if (b == NULL)
{
b = read_book (file_name, data[0], SDL_SwapLE16 (*((Uint16*)(data+1))));
if (b == NULL)
{
char str[200];
safe_snprintf (str, sizeof(str), book_open_err_str, file_name);
LOG_TO_CONSOLE(c_red1, str);
return;
}
}
display_book_window (b); // Otherwise there's no point...
}
开发者ID:sorlok,项目名称:Eternal-Lands,代码行数:22,代码来源:books.c
示例20: add_to_download
void add_to_download(const char *filename, const Uint8 *md5)
{
// lock the mutex
CHECK_AND_LOCK_MUTEX(download_mutex);
if(download_queue_size < MAX_UPDATE_QUEUE_SIZE){
// add the file to the list, and increase the count
download_queue[download_queue_size]= strdup(filename);
download_MD5s[download_queue_size]= calloc(1, 16);
memcpy(download_MD5s[download_queue_size], md5, 16);
download_queue_size++;
// start a thread if one isn't running
if(!download_cur_file){
char buffer[1024];
FILE *fp;
safe_snprintf(download_temp_file, sizeof(download_temp_file), "tmp/temp%03d.dat", ++temp_counter);
buffer[sizeof(buffer)-1]= '\0';
fp = open_file_config(download_temp_file, "wb+");
if(fp == NULL){
LOG_ERROR("%s: %s \"%s\": %s\n", reg_error_str, cant_open_file, download_temp_file, strerror(errno));
} else {
// build the proper URL to download
download_cur_file= download_queue[--download_queue_size];
download_cur_md5= download_MD5s[download_queue_size];
if(is_this_files_lst){
safe_snprintf(buffer, sizeof(buffer), "http://%s/updates%d%d%d/%s", update_server, VER_MAJOR, VER_MINOR, VER_RELEASE, download_cur_file);
} else {
safe_snprintf(buffer, sizeof(buffer), "http://%s/updates/%s", update_server, download_cur_file);
}
buffer[sizeof(buffer)-1]= '\0';
LOG_DEBUG("@@ %s %s",update_server,buffer);
http_threaded_get_file(update_server, buffer, fp, download_cur_md5, EVENT_DOWNLOAD_COMPLETE);
}
}
}
// unlock the mutex
CHECK_AND_UNLOCK_MUTEX(download_mutex);
}
开发者ID:gregoryfenton,项目名称:other-life,代码行数:39,代码来源:update.c
注:本文中的safe_snprintf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论