/******************************************************************************/
/* THE BEER-WARE LICENSE   (Revision 42):                                     */
/*  As long as you retain this notice you can do whatever you want with this  */
/*   stuff. If we meet some day, and you think this stuff is worth it,        */
/*   you can buy me a beer in return.    --solarx                             */
/******************************************************************************/


#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

int main()
{
	int entropy_avail, entropy_curr;
	char buf[16];
	char *p;
	FILE *fp;

	entropy_avail = entropy_avail = 0;

	while (1) {
		if ((fp =
			 fopen("/proc/sys/kernel/random/entropy_avail", "r")) != NULL) {
			// printf("fpos=%d\n", ftell(fp));
			// rewind(fp);
			fgets(buf, sizeof(buf), fp);
			if ((p = strchr(buf, '\n')) != NULL)
				*p = 0;
			entropy_curr = atoi(buf);
			if (entropy_curr < entropy_avail)
				printf("entropy_avail has gone down [ %8d ] : total [ %8d ]\n",
					   entropy_avail - entropy_curr, entropy_curr);
			if (entropy_curr > entropy_avail)
				printf("entropy_avail has gone up.. [ %8d ] : total [ %8d ]\n",
					   entropy_curr - entropy_avail, entropy_curr);
			entropy_avail = entropy_curr;
			// printf("-fpos=%d\n", ftell(fp));
			sleep(1);
			fclose(fp);

		}
	}
	_exit(1);			/* should never be reached */
}
