#include	<stdio.h>	// printf()
#include	<time.h>		// clock()

#define	CLOCK_CORRECTED
#ifdef	CLOCK_CORRECTED

clock_t	clock(void)
{
	struct	timespec	ts;
	
	clock_gettime(CLOCK_REALTIME, &ts);	
	
	return	ts.tv_sec * 1000000000 + ts.tv_nsec;
}

#undef	CLOCKS_PER_SEC
#define	CLOCKS_PER_SEC	1000000000

#endif

int	main(int argc, char* argv[])
{
	struct	timespec	ts;
	
	ts.tv_sec  = 0;
	ts.tv_nsec = 100000000;											// 0.1 / 10^-9

	clock_t	tic_o, toc_o, tac_o = 0;
	
	printf	("\e[?25l");											// hide cursor

	for	(int l = 0; l < 600; l++)										// 60 / 0.1
	{
		tic_o	 = clock();

		nanosleep(&ts, NULL);

		toc_o	 = clock();	tac_o	+= toc_o - tic_o;
		
		double	t_elap = ((double) tac_o / CLOCKS_PER_SEC);
		
		long int	elap_h	 = (((long int) t_elap / 3600)     );
		long int	elap_m	 = (((long int) t_elap % 3600) / 60);
		long int	elap_s	 = (((long int) t_elap % 3600) % 60);

		printf("\e[001G"); printf("elapsed: %02ld:%02ld:%02ld of %02ld:%02ld:%02ld (%11ld)", elap_h, elap_m, elap_s, 0, 1, 0, tac_o); fflush(stdout);
	}

	printf("\n");
	
	printf	("\e[?25h");											// show cursor
}

