#include <string.h>
#include <exec/types.h>
#include <exec/execbase.h>
#include <proto/dos.h>

#include "users.h"
#include "misc.h"

extern struct ExecBase *SysBase;
#define UID_PEEKER		0xf000
#define CUID	  ((struct Process *)(SysBase->ThisTask))->pr_Pad

int search_userdata(char *file,struct User *usr,int startpos,char *loginname)
{	LONG handle,read;
	int i=0;
	UWORD uid=CUID;

	CUID=UID_SYSTEM;
	lowercase(loginname,loginname);
	if(handle=Open(file,MODE_OLDFILE))
	{	Seek(handle,startpos*sizeof(struct User),OFFSET_BEGINNING);
		do
		{	read=Read(handle,usr,sizeof(struct User));
			i++;
		}	while(strcmp(usr->Loginname,loginname) && read);
		Close(handle);
		CUID=uid;
		if(read)
			return i-1;
	}
	CUID=uid;
	return -1;			/* passwd-file not found */
}
