#include "utmpx-wrapper.h"

static int ut_fd = -1;
static STRUCT_UTMPX cur;

void setutent_wrapper(void){
	ut_fd = open(_PATH_UTMP, O_RDONLY);
	if(ut_fd < 0) bail("shit man, no utmp record?", 1);
}

STRUCT_UTMPX *getutent_wrapper(void){
	int amt_read = read(ut_fd, &cur, sizeof(STRUCT_UTMPX));
	if(amt_read < 0) bail("error reading utmp record", 1);
	else if(amt_read == 0) return NULL;
	else return &cur;
}

void endutent_wrapper(void){
	if(close(ut_fd)<0) bail("error closing utmpx file!", 1);
}
