/*******************************************
 *   Copyright (C) 2008 by Mauro Rodrigues *
 *******************************************/
#include "mytime.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <sys/time.h>
//---------------------
// Determinação da hora
//---------------------
int gethour(char hour[])
{
	struct timeval tv;
	time_t curtime;

	gettimeofday(&tv, NULL);
	curtime=tv.tv_sec;

	strftime(hour, 10, "%T", localtime(&curtime));

	return EXIT_SUCCESS;
}

//---------------------
// Determinação da data
//---------------------
int getdate(char buffer[])
{
	struct timeval tv;
	time_t curtime;

	gettimeofday(&tv, NULL); 
	curtime=tv.tv_sec;

	strftime(buffer,30,"%d-%m-%Y_%T",localtime(&curtime));

	return EXIT_SUCCESS;
}

//----------------------------------------
// Determinação do tempo em microssegundos
//----------------------------------------
int getsec(unsigned long &sec, unsigned long &usec)
{
	struct timeval tv;
	gettimeofday(&tv, NULL); 
	sec=tv.tv_sec;
	usec=tv.tv_usec;

	return EXIT_SUCCESS;
}

//---------------------------
// Marca temporal no ficheiro
//---------------------------
void tmstamp(FILE *f, char c)
{
	unsigned long sec, usec;

	getsec(sec, usec);
	fprintf(f, "%lu%06lu%c", sec, usec, c);
}
