Example #1
0
char* asctime_r(const tm* tm, char* buf) {
  char tmpBuf[64];
  if (asctime_s(tmpBuf, tm)) {
    return nullptr;
  }
  // Nothing we can do if the buff is to small :(
  return strcpy(buf, tmpBuf);
}
Example #2
0
static char *web_server_asctime_r(const struct tm *tm, char *buf)
{
	if (tm == NULL || buf == NULL)
		return NULL;

	asctime_s(buf, ASCTIME_R_BUFFER_SIZE, tm);
	return buf;
}
Example #3
0
int main(void)
{
    struct tm ptm;
    time_t t = time(NULL);
    ptm = *gmtime(&t);
    printf("UTC:   %s", asctime(&ptm));
    ptm = *localtime(&t);
    printf("local: %s", asctime(&ptm));

#ifdef __STDC_LIB_EXT1__
    struct tm buf;
    char str[26];
    asctime_s(str, sizeof str, gmtime_s(&t, &buf));
    printf("UTC:   %s", str);
    asctime_s(str, sizeof str, localtime_s(&t, &buf));
    printf("local: %s", str);
#endif
}
Example #4
0
	std::string TimeString::GetTimeString()
	{
		auto t = std::time(nullptr);
		char buffer[1024];
		struct tm newtime;
		localtime_s(&newtime, &t);
		asctime_s(buffer, &newtime);
		return std::string(buffer);
	}
Example #5
0
	void EventLogger::add(const char* lpStrDesc, EVENTTYPE t, 
		const char* lpStrSource, int value)
	{
		if(lpStrDesc == NULL)
			return;

		DAnsiStr strEvent;			
		//Write Event Type
		if(m_bWriteEventTypes)
		{
			if(t == etInfo)
				strEvent += printToAStr("INFO: ");
			else if(t == etWarning)
				strEvent += printToAStr("WARNING: ");
			else if(t == etError)
				strEvent += printToAStr("ERROR: ");
		}

		//Write Event Time
		if(m_bWriteTimeStamps)
		{
			time_t rawtime;
			time (&rawtime);
#ifdef PS_SECURE_API
			char buffer[64];
			struct tm timeinfo;
			localtime_s(&timeinfo, &rawtime);
			asctime_s(timeinfo, buffer, 64)
				strEvent += printToAStr("TIME: [%s], ", buffer);
#else
			struct tm * timeinfo = localtime ( &rawtime );
			DAnsiStr strTime = DAnsiStr(asctime(timeinfo));
			strTime.trim();
			strEvent += printToAStr("TIME: [%s], ", strTime.cptr());
#endif
		}

		//Write Source + Value
		if(m_bWriteSourceInfo && lpStrSource)
		{
			strEvent += printToAStr("SOURCE: [%s, LINE:%d], ", lpStrSource, value);
		}

		//Write Event itself
		strEvent += DAnsiStr(lpStrDesc);			
		m_lstLog.push_back(strEvent);

		//Write Message to screen
		if(m_bWriteToScreen)
			display(strEvent.cptr());

		//Update Buffer size and Flush if ready
		m_szBufferSize += strEvent.length();
		if(m_szBufferSize > PS_LOG_BUFFER_SIZE)
			flush();
	}
Example #6
0
void __cdecl sdlogtime() {
	char timebuf[26];
    time_t ltime;
    struct tm gmt;
	time(&ltime);
    _gmtime64_s(&gmt, &ltime);
    asctime_s(timebuf, 26, &gmt);
	timebuf[24] = '\0'; // remove newline
	SDLOG(0, "===== %s =====\n", timebuf);
}
Example #7
0
string getTimeString() {
	char timebuf[26];
    time_t ltime;
    struct tm gmt;
	time(&ltime);
    _localtime64_s(&gmt, &ltime);
    asctime_s(timebuf, 26, &gmt);
	timebuf[24] = '\0'; // remove newline
	return string(timebuf);
}
Example #8
0
/*------------------------------------------------------------------------
 * ascdate  -  convert internal date/time to ascii
 * including hours:mins:secs.
 * buf is a pointer to a caller's array of at least 26 octets
 *------------------------------------------------------------------------
 */
char *ascdate(char *buf, size_t bufSize) {
	char *p_buf;
	struct tm *newtime;
	time_t ltime;
	_time64(&ltime);
	newtime = _localtime64(&ltime);
	asctime_s(buf, bufSize, newtime);
	p_buf = strchr(buf, '\n');
	*p_buf = 0;
	return buf;
}
void PrintTime()
{
	time_t rawtime;
	struct tm timeinfo;
	char str[26];
	time(&rawtime);
	localtime_s(&timeinfo, &rawtime);
	asctime_s(str, sizeof str, &timeinfo);
	str[24] = '\0';
	printf("%s ", str);
}
Example #10
0
void main()
{
    time_t time_of_day;
    auto char buf[26];
    auto struct tm tmbuf;

    time_of_day = time( NULL );
    localtime_s( &time_of_day, &tmbuf );
    asctime_s( buf, sizeof( buf ), &tmbuf );
    printf( "It is now: %s", buf );
}
Example #11
0
 std::string get_asctime()
 {
     tm t;
     get_local_tm(&t);
 #if (__STDC_WANT_LIB_EXT1__ || __STDC_WANT_SECURE_LIB__)
     char buf[50];
     asctime_s(buf, 50, &t);
     return buf;
 #else
     return asctime(&t);
 #endif
 }
Example #12
0
//------------------------------------------------------------------
//
//	EndLog(..)
//
//	Writes foot entry
//
//------------------------------------------------------------------
void CDebugLog::EndLog()
{
	if (m_bInit) {
		time_t rawTime;
		struct tm timeinfo;
		char buffer[32];

		time(&rawTime);
		localtime_s(&timeinfo, &rawTime);
		asctime_s(buffer, &timeinfo);
		m_fileStream << "\nDebug Log Ended: " << buffer;
	}
}
Example #13
0
char_t *websCalcNonce(webs_t wp)
{
	char_t		*nonce, *prenonce;
	time_t		longTime;
#if defined(WIN32)
	char_t		buf[26];
	errno_t	error;
	struct tm	newtime;
#else
	struct tm	*newtime;
#endif

	a_assert(wp);
/*
 *	Get time as long integer.
 */
	time(&longTime);
/*
 *	Convert to local time.
 */
#if !defined(WIN32)
	newtime = localtime(&longTime);
#else
	
	error = localtime_s(&newtime, &longTime);
#endif
/*
 *	Create prenonce string.
 */
#if !defined(WIN32)
	prenonce = NULL;
	fmtAlloc(&prenonce, 256, T("%s:%s:%s"), RANDOMKEY, gasctime(newtime),
		wp->realm); 
#else
	asctime_s(buf, elementsof(buf), &newtime);
	fmtAlloc(&prenonce, 256, T("%s:%s:%s"), RANDOMKEY, buf, 
		RANDOMKEY); 
#endif

	a_assert(prenonce);
/*
 *	Create the nonce
 */
    nonce = websMD5(prenonce);
/*
 *	Cleanup
 */
	bfreeSafe(B_L, prenonce);

	return nonce;
}
Example #14
0
std::string MATLABPLOTTER::createFilename()
{
	// creates a date & time stamped data file
	std::string filename;

	struct tm newtime;
	__int64 local_time;
	char time_buf[26];
	errno_t err;

	_time64( &local_time );

	// Obtain coordinated universal time: 
	err = _localtime64_s( &newtime, &local_time );
	if (err)
	{
		printf("Invalid Argument to _gmtime64_s.");
	}
   
	// Convert to an ASCII representation 
	err = asctime_s(time_buf, 26, &newtime);
	if (err)
	{
		printf("Invalid Argument to asctime_s.");
	}

	std::string date_string = time_buf;

	size_t found;

	found=date_string.find_first_of(":");
	
	while (found!=std::string::npos)
		{
		date_string[found]='_';
		found=date_string.find_first_of(":",found+1);
		}

	found=date_string.find_first_of("\n");
		
	while (found!=std::string::npos)
	{
		date_string.erase(found, 1);
		found=date_string.find_first_of("\n",found+1);
	}

	filename = "thermocouple data on " + date_string + ".csv"; 

	return filename;

}
Example #15
0
// Print the project name and a time and date stamp to the top of a file 
void PrintFileHeader(FILE *File)
{
	char *TimeBuffer;
	struct tm Time;
	time_t PrintTime;
	TimeBuffer = (char*)malloc(100*sizeof(char));

	time(&PrintTime);
	gmtime_s(&Time, &PrintTime);
	asctime_s(TimeBuffer, 100, &Time);

	fprintf(File,"Event based TLM\nProject: %s\n%s\n\n", ProjectName, TimeBuffer);

	free(TimeBuffer);
}
Example #16
0
string getTimeString(bool forDisplay) {
	char timebuf[64];
    time_t ltime;
    struct tm gmt;
	time(&ltime);
    _localtime64_s(&gmt, &ltime);
	if(!forDisplay) {
		asctime_s(timebuf, 64, &gmt);
		timebuf[24] = '\0'; // remove newline
	}
	else {
		strftime(timebuf, 64, "%Y-%d-%m %H:%M:%S", &gmt);
	}
	return string(timebuf);
}
Example #17
0
String TimeStampString()
{
 	struct tm timeinfo;
	time_t rawtime;

	time(&rawtime);
	localtime_s(&timeinfo, &rawtime);

	char time_str[256];
	asctime_s(time_str, sizeof(time_str), &timeinfo);

	// chop of \n
	size_t len = strlen(time_str);
	time_str[len-1] = 0;

	return time_str;
}
Example #18
0
std::string MATLABPLOTTER::generateDate()
{
	//this generates the date string for the file name
	struct tm newtime;
	__int64 local_time;
	char time_buf[26];
	errno_t err;

	_time64( &local_time );

	// Obtain coordinated universal time: 
	err = _localtime64_s( &newtime, &local_time );
	if (err)
	{
		printf("Invalid Argument to _gmtime64_s.");
	}
   
	// Convert to an ASCII representation 
	err = asctime_s(time_buf, 26, &newtime);
	if (err)
	{
		printf("Invalid Argument to asctime_s.");
	}

	std::string date_string = time_buf;

	size_t found;

	found=date_string.find_first_of(":");
		
	while (found!=std::string::npos)
	{
		date_string[found]='_';
		found=date_string.find_first_of(":",found+1);
	}

	found=date_string.find_first_of("\n");
		
	while (found!=std::string::npos)
	{
		date_string.erase(found, 1);
		found=date_string.find_first_of("\n",found+1);
	}
	return date_string;
}
void RaceStandingsPlugin::Log(const char *msg)
{
  FILE *fo;
  time_t curtime;
  struct tm localtime;
  char timestamp[26];

  fo = fopen( RACE_STANDINGS_LOG_FILENAME, "a" );
  if( fo != NULL )
  {
	curtime = time(NULL);
	localtime_s(&localtime, &curtime);
	asctime_s(timestamp, 26, &localtime);
	timestamp[24] = 0;
    fprintf( fo, "[%s] %s\n", timestamp, msg );
    fclose( fo );
  }
}
Example #20
0
	virtual void GetHistoryForParticipant_CB(GetHistoryForParticipant_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
	{
		if (wasCancelled)
			printf("GetHistoryForParticipant call cancelled:\n");
		else if (callResult->dbQuerySuccess==false)
		{
			printf("GetHistoryForParticipant call DB failure:\n");
			printf("%s", callResult->rankingServer->GetLastError());
		}
		else
		{
			printf("GetHistoryForParticipant result:\n");
			printf("[in] participantDbId.primaryKey=%i\n", callResult->participantDbId.primaryKey);
			printf("[in] participantDbId.secondaryKey=%i\n", callResult->participantDbId.secondaryKey);
			printf("[in] gameDbId.primaryKey=%i\n", callResult->gameDbId.primaryKey);
			printf("[in] gameDbId.secondaryKey=%i\n", callResult->gameDbId.secondaryKey);
			printf("[out] %i matches found for this participant.\n", callResult->matchHistoryList.Size());
			unsigned i;
			for (i=0; i < callResult->matchHistoryList.Size(); i++)
			{
				printf("[out] %i. participantBDbId.primaryKey (opponent) =%i\n", i+1, callResult->matchHistoryList[i]->participantBDbId.primaryKey);
				printf("[out] %i. participantBDbId.secondaryKey (opponent) =%i\n", i+1, callResult->matchHistoryList[i]->participantBDbId.secondaryKey);
				printf("[out] %i. participantAScore (us) =%f\n", i+1, callResult->matchHistoryList[i]->participantAScore);
				printf("[out] %i. participantBScore (opponent) =%f\n", i+1, callResult->matchHistoryList[i]->participantBScore);
				printf("[out] %i. participantAOldRating (us) =%f\n", i+1, callResult->matchHistoryList[i]->participantAOldRating);
				printf("[out] %i. participantANewRating (us) =%f\n", i+1, callResult->matchHistoryList[i]->participantANewRating);
				printf("[out] %i. participantBOldRating (opponent) =%f\n", i+1, callResult->matchHistoryList[i]->participantBOldRating);
				printf("[out] %i. participantBNewRating (opponent) =%f\n", i+1, callResult->matchHistoryList[i]->participantBNewRating);
				printf("[out] %i. Match Notes=%s\n", i+1, callResult->matchHistoryList[i]->matchNotes.C_String());
				printf("[out] %i. matchBinaryDataLength=%i\n", i+1, callResult->matchHistoryList[i]->matchBinaryDataLength);

				// Copied from the docs
				struct tm *newtime;
				newtime = _localtime64(& callResult->matchHistoryList[i]->matchTime);
				char buff[30];
				asctime_s( buff, sizeof(buff), newtime );
				printf("[out] %i. matchTime (converted) =\n%s\n", i+1, buff );
			}
		}

		printf("\n");
	}
Logger& Logger::operator<<(const std::string& message)
{
	time_t sec = time(NULL);
	tm timeInfo;
	std::string date, temp;
	errno_t err = localtime_s(&timeInfo, &sec);
	char buf[26];
	if (err || asctime_s(buf, 26, &timeInfo))
		date = "00\XXX\0000 00:00:00";
	else
	{
		temp = std::string(buf);
		date = temp.substr(8, 2) + "\\" + temp.substr(4, 3) + "\\" + temp.substr(20, 4) + " " + temp.substr(11, 8) + " : ";
	}
	out.open(filename, std::ios::out | std::ios::app);
	out << date << message << std::endl;
	out.close();

	return *this;
}
Example #22
0
	void WriteCurrentTimestampToBuffer(char buffer[32])
	{
		# ifdef YUNI_OS_MSVC
		__time64_t rawtime = ::_time64(nullptr);
		# else
		time_t rawtime = ::time(nullptr);
		# endif

		struct tm timeinfo;

		# if defined(YUNI_OS_MSVC)
		// Microsoft Visual Studio
		_localtime64_s(&timeinfo, &rawtime);
		// MSDN specifies that the buffer length value must be >= 26 for validity.
		asctime_s(buffer, 32, &timeinfo);
		# else
		// Unixes
		::localtime_r(&rawtime, &timeinfo);
		::asctime_r(&timeinfo, buffer);
		# endif
	}
Example #23
0
std::string Logger::TimeStamp() {
    time_t rawtime;
    struct tm timeinfo;

    time(&rawtime);
#ifdef _WIN32
	localtime_s(&timeinfo, &rawtime);
	char timebuf[26];
	#else
    timeinfo = *localtime(&rawtime);
    char* timebuf;
#endif
#ifdef _WIN32
	asctime_s(timebuf, 26, &timeinfo);
	#else
    timebuf = asctime(&timeinfo);
#endif
    std::string output = std::string(timebuf);
    Utils::RemoveEndline(output);
    return output;
}
Example #24
0
errno_t	ctime_s(char *s, rsize_t maxsize, const time_t *timer)
{
	if(s == NULL || timer == NULL)
	{
		ERR()
		VIOLATION("s or time is NULL")
	}
	if(maxsize < 26)
	{
		ERR()
		VIOLATION("maxsize is less than 26")
	}
	if(maxsize > RSIZE_MAX)
	{
		ERR()
		VIOLATION("maxsize is greater than RSIZE_MAX")
	}
	struct tm date;
	localtime_r(timer, &date);
	return (asctime_s(s, maxsize, &date));
}
Example #25
0
// displays the date associated with the supplied parameter
string CTimeSupport::ConvertTimeToString(const uint64_t& currentTime) {

	string ret;

#ifdef WIN32

	FILETIME ft;
	SYSTEMTIME st;
	ULARGE_INTEGER ul;

	ul.QuadPart       = currentTime;
	ft.dwHighDateTime = ul.HighPart;
	ft.dwLowDateTime  = ul.LowPart;

	FileTimeToSystemTime(&ft, &st);

	ostringstream sb;

	// "Fri Feb 9 12:15:48 2007"
	sb << setfill('0') << WEEKDAYS[st.wDayOfWeek] << " " << MONTHS[st.wMonth - 1]
	<< " " << st.wDay << " " << st.wHour << ":" << setw(2) << st.wMinute 
		<< ":" << setw(2) << st.wSecond << " " << st.wYear;

	ret = sb.str();

#else

	struct tm localTime;
	char timebuf[26];

	time_t currentTimeT = (time_t)((currentTime - 116444736000000000) / 10000000.0);
	localtime_s(&localTime, &currentTimeT);
	asctime_s(timebuf, 26, &localTime);

	ret = timebuf;

#endif

	return ret;
}
Example #26
0
/**
 * This operator outputs a CST object to the screen
 **/
ostream& operator <<(	ostream& cout, 
						const CST& a)
{
	if (&a)
	{
		char* tmptm = new char[100];
		asctime_s(tmptm, 100, &a.SellTime);

		cout << "############################################################" << endl
			 << "Ticket Info" << endl
			 << "------------------------------------------------------------" << endl
			 << "Paydesk ID: ";

		cout.fill('0');
		cout.width(8);

		cout << a.PaydeskID << endl
			 << "Ticket ID: ";

		cout.fill('0');
		cout.width(8);

		cout << a.TicketID << endl
			 << "SellTime: " 
			 << tmptm << endl
		     << a.Rt
		     << "Passenger: " 
			 << a.Passenger << endl
			 << "############################################################" << endl;
		return cout;
	}
	else
	{
		cout << "############################################################" << endl
			 << "There is no such a ticket" << endl
			 << "############################################################" << endl;
		return cout;
	}
}
Example #27
0
static errno_t __cdecl
_int_ctime32_s (char *d, size_t dn, const __time32_t *pt)
{
  struct tm ltm;
  errno_t e;

  if (!d || !dn)
     {
        errno = EINVAL;
	return EINVAL;
     }
  d[0] = 0;
  if (!pt)
     {
	errno = EINVAL;
	return EINVAL;
     }

  if ((e = _localtime32_s (&ltm, pt)) != 0)
    return e;  
  return asctime_s (d, dn, &ltm);
}
void Logger::openService(size_t logNum, std::string& fName)
{
	time_t sec = time(NULL);
	tm timeInfo;
	std::string date, temp;
	if (localtime_s(&timeInfo, &sec))
	{
		std::cout << "Can't open file" << std::endl;
		throw LocalTimeError("Error getting local time.");
	}
	char buf1[26];
	if (asctime_s(buf1, 26, &timeInfo))
	{
		std::cout << "Can't open file" << std::endl;
		throw AscTimeError("Error getting time string.");
	}

	char buf2[10];
	_ltoa_s(logNum, buf2, 10, 10);

	fName = ("log_" + std::string(buf1).substr(0, 3) + "_" + std::string(buf1).substr(11, 2) + "_" +
		std::string(buf1).substr(14, 2) + "_" + std::string(buf1).substr(17, 2) + "_" + std::string(buf2) + ".txt");
}
Example #29
0
bool UploadDump(const char* file, const char* user, int build, int branch, DelegateI<Prog_s>* progress)
{
	Logger log;
	log.write("---------------------------------------\r\n");

	time_t ltime; /* calendar time */
	ltime=time(NULL); /* get current cal time */

	
#ifdef WIN32
	char buff[255] = {0};

	struct tm t;
	localtime_s(&t, &ltime);
	asctime_s(buff, 255, &t);
#else
	struct tm *t = localtime(&ltime);
	char* buff = asctime(t);
#endif

	log.write("%s\r\n", buff);
	log.write("---------------------------------------\r\n");

	log.write("Uploaded crash dump: [%s]\r\n", file);


	gcString dump(file);

	if (PrepDumpForUpload(dump) == false)
	{
		log.write("Failed to prepare crash dump.\r\n");
		return false;
	}
	else
	{
		log.write("Prepared crash dump to: [%s]\r\n", dump.c_str());
	}

	std::string os = UTIL::OS::getOSString();

	HttpHandle hh(DUMP_UPLOAD_URL);

	if (progress)
		hh->getProgressEvent() += progress;

	hh->setUserAgent(DUMP_UPLOAD_AGENT);

	hh->cleanUp();
	hh->addPostText("os", os.c_str());
	hh->addPostText("build", build);
	hh->addPostText("appid", branch);

	if (user)
		hh->addPostText("user", user);

	hh->addPostFile("crashfile", dump.c_str());

	try
	{
		hh->postWeb();
	}
	catch (gcException &except)
	{
		log.write("Failed to upload crash: %s [%d.%d].\r\n", except.getErrMsg(), except.getErrId(), except.getSecErrId());
		return false;
	}

	TiXmlDocument doc;
	doc.LoadBuffer(const_cast<char*>(hh->getData()), hh->getDataSize());
	
	try
	{
		XML::processStatus(doc, "crashupload");
		log.write("Uploaded dump\r\n");
		UTIL::FS::delFile(UTIL::FS::Path(dump, "", true));		
	}
	catch (gcException &)
	{
		log.write("Bad status returned from upload crash dump.\r\n");

		gcString res;
		res.assign(hh->getData(), hh->getDataSize());

		log.write("Result: \r\n\r\n%s\r\n\r\n", res.c_str());
		
		return false;	
	}

	return true;
}
Example #30
0
	bool IO::update(sf::RenderWindow *w)
	{
		for (unsigned int i = 0; i < IO::m_buttons.size(); i++)
		{
			if (IO::m_buttons[i]->update(w))
			{
				if (IO::save)
				{
					// Creating the time stamp node.
					std::time_t currentTime = std::time_t();
					std::tm convertedTime = tm();
					char buffer[256];

					std::time(&currentTime);

					localtime_s(&convertedTime, &currentTime);
					asctime_s(buffer, &convertedTime);

					for (unsigned int j = 0; j < 256; j++)
					{
						if (buffer[j] == '\n')
						{
							buffer[j] = '\0';
							break;
						}
					}

					jsoncons::json log;
					log["date_time"] = std::string(buffer);
					log["scene_name"] = yingge::session->sceneName;

					jsoncons::json bools;
					for (auto b : yingge::session->booleans)
						bools[b.first.c_str()] = b.second;

					jsoncons::json numbers;
					for (auto n : yingge::session->numbers)
						numbers[n.first.c_str()] = n.second;

					jsoncons::json strings;
					for (auto s : yingge::session->strings)
						strings[s.first.c_str()] = s.second.c_str();

					log["booleans"] = bools;
					log["numbers"] = numbers;
					log["strings"] = strings;

					std::ofstream str;

					str.open("logs/" + std::to_string(i) + ".json", std::ios::trunc);
					str << log.to_string();
					str.close();

					jsoncons::json man = jsoncons::json::parse_file("logs/manifest.json");
					std::vector<std::string> vecMan = man["logs"].as<std::vector<std::string>>();
					vecMan[i] = std::string(buffer);
					man["logs"] = vecMan;

					str.open("logs/manifest.json", std::ios::trunc);
					str << man.to_string();
					str.close();

					IO::createButtons(IO::save);
				}
				else
				{
					jsoncons::json log = jsoncons::json::parse_file("logs/" + std::to_string(i) + ".json");

					delete yingge::session;
					yingge::session = new yingge::Session();

					jsoncons::json bools = log["booleans"];
					for (auto b = bools.begin_members(); b != bools.end_members(); ++b)
					{
						yingge::session->booleans.insert(std::pair<std::string, bool>(b->name(), b->value().as<bool>()));
					}

					jsoncons::json numbers = log["numbers"];
					for (auto n = numbers.begin_members(); n != numbers.end_members(); ++n)
					{
						yingge::session->numbers.insert(std::pair<std::string, double>(n->name(), n->value().as<double>()));
					}

					jsoncons::json strings = log["strings"];
					for (auto s = numbers.begin_members(); s != numbers.end_members(); ++s)
					{
						yingge::session->strings.insert(std::pair<std::string, std::string>(s->name(), s->value().as<std::string>()));
					}

					yingge::sceneManager->replaceScenes(getScene(log["scene_name"].as<std::string>()));
					return true;
				}
			}
		}

		return IO::m_cancelButton.update(w);
	}