#include    <rpc/rpc.h>
#include    <sys/dir.h>
#include    "rls.h"

extern int      errno;
extern char     *malloc();
extern char     *strdup();

rls_res *rls_1(nametype *dirname)
{
namelist    nl;
namelist    *nlp;
static rls_res  res;     /* must be static! */
static DIR      *dirp=NULL;
struct direct   *d;

    if(dirp){
        xdr_free(xdr_rls_res,&res);
    }
    dirp=opendir(*dirname);
    if(dirp==NULL){
        res.errno=errno;
        return(&res);
    }
    nlp=(&res.rls_res_u.list);
    while(d=readdir(dirp)){
        nl=(*nlp)=(namenode *)malloc(sizeof(namenode));
        nl->name=strdup(d->d_name);
        nlp=(&nl->pNext);
    }
    (*nlp)=NULL;
    res.errno=0;
    closedir(dirp);
    return(&res);
}
