
/* 
 * Getcookie for MiNTlib
 * 
 * jerry g geiger (Ssystem extension Draco)
 
 * returns 0 if Cookie was found, 1 if not
 * returns cookie val in val if found, 0 if not
 */
#include <osbind.h>
#include <mintbind.h>
#include <ssystem.h>
#include <time.h>
 
static long cookie;
static long cookieval;

static long getcookie()
{
	long *cookiep;

	cookiep = *((long **) 0x5a0L);
	if (cookiep) {
		while (*cookiep) {
			if (*cookiep == cookie) {	/*  */
				return cookiep[1];
			}
			cookiep += 2;
		}
	}
	/* else, fall through	*/
	cookie = 0L;
	return(0L);
}

int Getcookie(long which, long *val)
{
	if (Ssystem(-1, NULL, NULL)) {
		cookie = which;
		cookieval = Supexec(getcookie);
	}
	else {
		cookieval = Ssystem(GETCOOKIE, which, NULL);
		if (cookieval = -1)
			cookieval = cookie = 0;
	}
	
	if(val)
		*val = cookieval;
	if(cookie)
		return(0);
	return(1);	
}
