home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_USR08B.LHA / gerlib / examples / add / baserel / GetFileSize2.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  1.5 KB  |  87 lines

  1. /*-- Rev Header - do NOT edit!
  2.  *
  3.  *  Filename : getfilesize2.cc
  4.  *  Purpose  : Gibt Länge eines Files(BPTR) zurück, oder -1
  5.  *
  6.  *  Program  : -
  7.  *  Author   : Gerhard Müller
  8.  *  Copyright: (c) by Gerhard Müller
  9.  *  Creation : Tue Sep  7 17:39:24 1993
  10.  *
  11.  *  compile  :
  12.  *
  13.  *  Compile version  : 0.1
  14.  *  Ext. Version     : 0.1
  15.  *
  16.  *  REVISION HISTORY
  17.  *
  18.  *  Date                     Comment
  19.  *  ------------------------ -------------------------------------------------
  20.  *  Fri Sep 17 00:48:35 1993 Works
  21.  *
  22.  *-- REV_END --
  23.  */
  24.  
  25.     /*
  26.      * C-Includes, C-Definitionen
  27.      *
  28.      */
  29.  
  30. #define class _class
  31. #define template _template
  32.  
  33. extern "C" {
  34. #include <exec/types.h>
  35. #include <exec/execbase.h>
  36. #include <exec/memory.h>
  37. #include <clib/alib_protos.h>
  38. #include <clib/alib_stdio_protos.h>
  39. #include <inline/stubs.h>
  40. #include <dos/dos.h>
  41. #include <dos/dosextens.h>
  42. #ifdef __OPTIMIZE__
  43. #include <inline/exec.h>
  44. #include <inline/dos.h>
  45. #else
  46. #include <clib/exec_protos.h>
  47. #include <clib/dos_protos.h>
  48. #endif
  49. }
  50.  
  51. #undef template
  52. #undef class
  53.  
  54.     /* GetFileSize(BPTR fh):
  55.      *
  56.      *    Simple routine to return the size of a file in
  57.      *    bytes.
  58.      */
  59.  
  60. LONG GetFileSize(BPTR FileHandle)
  61. {
  62.     BPTR FileLock;
  63.     long len=-1;
  64.  
  65.     if(FileLock=DupLockFromFH(FileHandle))
  66.     {
  67.         /* get FIB */
  68.         struct FileInfoBlock *FileInfo;
  69.  
  70.         if(FileInfo=(struct FileInfoBlock *)AllocDosObject(DOS_FIB,0))
  71.         {
  72.             /* Examine the file... */
  73.  
  74.             if(Examine(FileLock,FileInfo))
  75.             {
  76.                 len=FileInfo -> fib_Size;
  77.             }
  78.  
  79.             FreeDosObject(DOS_FIB,FileInfo);
  80.         }
  81.         UnLock(FileLock);
  82.     }
  83.  
  84.     return len;
  85. }
  86.  
  87.