/*-- Rev Header - do NOT edit!
 *
 *  Filename : getfilesize2.cc
 *  Purpose  : Gibt Länge eines Files(BPTR) zurück, oder -1
 *
 *  Program  : -
 *  Author   : Gerhard Müller
 *  Copyright: (c) by Gerhard Müller
 *  Creation : Tue Sep  7 17:39:24 1993
 *
 *  compile  :
 *
 *  Compile version  : 0.1
 *  Ext. Version     : 0.1
 *
 *  REVISION HISTORY
 *
 *  Date                     Comment
 *  ------------------------ -------------------------------------------------
 *  Fri Sep 17 00:48:35 1993 Works
 *
 *-- REV_END --
 */

	/*
	 * C-Includes, C-Definitionen
	 *
	 */

#define class _class
#define template _template

extern "C" {
#include <exec/types.h>
#include <exec/execbase.h>
#include <exec/memory.h>
#include <clib/alib_protos.h>
#include <clib/alib_stdio_protos.h>
#include <inline/stubs.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#ifdef __OPTIMIZE__
#include <inline/exec.h>
#include <inline/dos.h>
#else
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#endif
}

#undef template
#undef class

	/* GetFileSize(BPTR fh):
	 *
	 *	Simple routine to return the size of a file in
	 *	bytes.
	 */

LONG GetFileSize(BPTR FileHandle)
{
	BPTR FileLock;
	long len=-1;

	if(FileLock=DupLockFromFH(FileHandle))
	{
		/* get FIB */
		struct FileInfoBlock *FileInfo;

		if(FileInfo=(struct FileInfoBlock *)AllocDosObject(DOS_FIB,0))
		{
			/* Examine the file... */

			if(Examine(FileLock,FileInfo))
			{
				len=FileInfo -> fib_Size;
			}

			FreeDosObject(DOS_FIB,FileInfo);
		}
		UnLock(FileLock);
	}

	return len;
}

