#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "obj.h"

extern char *progname;
extern char *ckfmsg, *magicfile;
extern int debug;
extern FILE *efopen();
extern long obj_type;

int fsmagic(char *fn)
 {
	extern struct stat statbuf;
   char warnbuf[80];

	if (stat(fn, &statbuf) < 0)
		{
			warning("can't stat", "");
			return -1;
		}

	if (statbuf.st_mode == 7794)           /* device or volume name */
	  {
		 obj_type = OBJ_DIRECTORY;
		 return 1;
	  }
   switch (statbuf.st_mode & S_IFMT) 
     {
	    case S_IFDIR:
		    obj_type = OBJ_DIRECTORY;
//		    ckfputs("directory", stdout);
		    return 1;

#ifdef	S_IFLNK
case S_IFLNK:
		ckfputs("symbolic link", stdout);
		return 1;
#endif
	case S_IFREG:
		break;
   
	default:
      sprintf(warnbuf, "invalid st_mode %d in statbuf!", statbuf.st_mode);
      warning(warnbuf, "");
	  } /* end switch */

	/*
	 * regular file, check next possibility
	 */
	if (statbuf.st_size == 0) 
    {
//		ckfputs("empty", stdout);
      obj_type = EMPTY;
		return 1;
	 }
	return 0;
 }
