/* This software is Copyright 1989, 1990, 1992, 1993 by various individuals. Please see the accompanying file COPYRIGHT for details. */ #include #include #include "db.h" #include "config.h" #include "externs.h" /* remove the first occurence of what in list headed by first */ dbref remove_first(dbref first, dbref what) { dbref prev; /* special case if it's the first one */ if(first == what) return DBFETCH(first)->next; else { /* have to find it */ DOLIST(prev, first) { if(DBFETCH(prev)->next == what) { DBSTORE(prev, next, DBFETCH(what)->next); return first; } } return first; } } int member(dbref thing, dbref list) { DOLIST(list, list) { if(list == thing) return 1; } return 0; } dbref reverse(dbref list) { dbref newlist; dbref rest; newlist = NOTHING; while(list != NOTHING) { rest = DBFETCH(list)->next; PUSH(list, newlist); DBDIRTY(newlist); list = rest; } return newlist; } int Read(int fd, void *buf, int nb) { char *bp; int left; int did; int done; bp = buf; left = nb; done = 0; while (left > 0) { did = read(fd,bp,left); if (did < 0) return(-1); if (did == 0) { errno = 0; return(-1); } bp += did; left -= did; done += did; } return(0); }