void ls_switch_file( ChannelLog *cl ) { static char tmbuf[MAXPATH]; static char newfname[MAXPATH]; static char oldfname[MAXPATH]; int res; /* no need to switch, its not opened */ if( cl->logfile == NULL ) return; ls_close_log( cl ); /* check if the target directory exists */ if( os_create_dir( LogServ.savedir ) != NS_SUCCESS ) { return; } os_strftime( tmbuf, MAXPATH, "%d%m%Y%H%M%S", os_localtime( &me.now ) ); ircsnprintf( newfname, MAXPATH, "%s/%s-%s.log", LogServ.savedir, cl->filename, tmbuf ); ircsnprintf( oldfname, MAXPATH, "%s/%s.log", LogServ.logdir, cl->filename ); res = os_rename( oldfname, newfname ); if( res != 0 ) { nlog( LOG_CRITICAL, "Couldn't rename file %s: %s", oldfname, os_strerror() ); return; } nlog( LOG_NORMAL, "Switched Logfile for %s from %s to %s", cl->channame, oldfname, newfname ); }
void xchat_startlog( ChannelLog *chandata, const CmdParams *cmdparams ) { static char startlog[BUFSIZE]; static char tmbuf[TIMEBUFSIZE]; os_strftime( tmbuf, TIMEBUFSIZE, "%a %b %d %H:%M:%S %Y", os_localtime( &me.now ) ); ircsnprintf( startlog, BUFSIZE, XSTARTLOG, tmbuf ); os_fprintf( chandata->logfile, "%s", startlog ); }
static void reset_time(struct udevice *dev) { struct sandbox_i2c_rtc_plat_data *plat = dev_get_platdata(dev); struct rtc_time now; os_localtime(&now); plat->base_time = rtc_mktime(&now); plat->offset = 0; plat->use_system_time = true; }
static int sandbox_i2c_rtc_get(struct udevice *dev, struct rtc_time *time) { struct sandbox_i2c_rtc_plat_data *plat = dev_get_platdata(dev); struct rtc_time tm_now; long now; if (plat->use_system_time) { os_localtime(&tm_now); now = rtc_mktime(&tm_now); } else { now = plat->base_time; } return rtc_to_tm(now + plat->offset, time); }
static int sandbox_i2c_rtc_set(struct udevice *dev, const struct rtc_time *time) { struct sandbox_i2c_rtc_plat_data *plat = dev_get_platdata(dev); struct rtc_time tm_now; long now; if (plat->use_system_time) { os_localtime(&tm_now); now = rtc_mktime(&tm_now); } else { now = plat->base_time; } plat->offset = rtc_mktime(time) - now; return 0; }
/* * Log a string with a given length */ void vm_log(VMG_ const char *str, size_t len) { /* open the system log file */ osfildef *fp = osfoprwt(G_syslogfile, OSFTTEXT); if (fp != 0) { /* wrap it in a data source */ CVmFileSource ds(fp); /* get a printable timestamp */ os_time_t timer = os_time(0); struct tm *tblk = os_localtime(&timer); char *tmsg = asctime(tblk); /* remove the trailing '\n' from the asctime message */ size_t tmsgl = strlen(tmsg); if (tmsgl > 0 && tmsg[tmsgl-1] == '\n') tmsg[--tmsgl] = '\0'; /* build the full message: [<timestamp>] <message> <newline> */ char *msg = t3sprintf_alloc("[%s] %.*s\n", tmsg, (int)len, str); size_t msglen = strlen(msg); /* seek to the end of the file */ ds.seek(0, OSFSK_END); /* if we can convert to a local character set, do so */ if (G_cmap_to_log != 0) { /* write the message in the local character set */ G_cmap_to_file->write_file(&ds, msg, msglen); } else { /* write the message with no character set conversion */ (void)osfwb(fp, (unsigned char*)msg, msglen); } /* done with the formatted text string */ t3free(msg); } }
char *TadsServerManager::gen_rand_id(void *obj) { /* set up a hashing buffer */ sha256_ctx s; sha256_begin(&s); /* add the current date/time to the hash */ os_time_t timer = os_time(0); struct tm *tblock = os_localtime(&timer); sha256_hash((unsigned char *)tblock, sizeof(*tblock), &s); /* add the system timer to the hash */ long systime = os_get_sys_clock_ms(); sha256_hash((unsigned char *)&systime, sizeof(systime), &s); /* add the object address to the hash */ sha256_hash((unsigned char *)obj, sizeof(obj), &s); /* add the current stack location to the hash */ sha256_hash((unsigned char *)&obj, sizeof(void *), &s); /* add some random bytes from the operating system */ unsigned char rbuf[128]; os_gen_rand_bytes(rbuf, sizeof(rbuf)); sha256_hash(rbuf, sizeof(rbuf), &s); /* compute the hash */ unsigned char hval[32]; sha256_end(hval, &s); /* convert it to hex, but just keep the low nybbles, for 32 digits */ char *ret = lib_alloc_str(32); int i; for (i = 0 ; i < 32 ; ++i) ret[i] = nybble2hex(hval[i]); /* null-terminate the string */ ret[i] = '\0'; /* return the allocated string */ return ret; }
static char *xchat_time( void ) { os_strftime( timebuf, TIMEBUFSIZE, XCHATTIME, os_localtime( &me.now ) ); return timebuf; }