/*
 * edlib v1.1 Copyright 1989 Edwin Hoogerbeets
 * This code is freely redistributable as long as no charge other than
 * reasonable copying fees are levied for it.
 */
#include "edlib.h"
#include <libraries/dos.h>
#include <exec/memory.h>
#include <errno.h>

#define FIBSIZE sizeof(struct FileInfoBlock)

extern struct FileInfoBlock *AllocMem();
extern struct FileLock      *Lock();

int filetype(path)
char *path;
{
  register struct FileInfoBlock *fib;
  register struct FileLock *lock;
  register int result;


  if ( !(fib = AllocMem(FIBSIZE,MEMF_CLEAR)) ) {
    errno = ENOMEM;
    return(-1);
  }

  if ( !(lock = Lock(path,ACCESS_READ)) ) {
    errno = EACCES;
    return(-1);
  }

  Examine(lock,fib);

  result = ( fib->fib_DirEntryType > 0 ) ? TYPE_DIR : TYPE_FILE;

  UnLock(lock);
  FreeMem(fib,FIBSIZE);

  return(result);
}



