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

  1. /*-- Rev Header - do NOT edit!
  2.  *
  3.  *  Filename : getfilesize1.cc
  4.  *  Purpose  : Gibt Länge eines Files(Filename) 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:47:50 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(STRPTR Name):
  55.      *
  56.      *    Simple routine to return the size of a file in
  57.      *    bytes.
  58.      */
  59.  
  60. LONG
  61. GetFileSize(STRPTR Name)
  62. {
  63.     struct FileInfoBlock    *FileInfo;
  64.     LONG             FileSize = -1;
  65.  
  66.     if(FileInfo = (struct FileInfoBlock *)AllocDosObject(DOS_FIB,TAG_DONE))
  67.     {
  68.         BPTR FileLock;
  69.  
  70.         if(FileLock = Lock(Name,ACCESS_READ))
  71.         {
  72.             if(Examine(FileLock,FileInfo))
  73.             {
  74.                 if(FileInfo -> fib_DirEntryType < 0)
  75.                     FileSize = FileInfo -> fib_Size;
  76.             }
  77.  
  78.             UnLock(FileLock);
  79.         }
  80.  
  81.         FreeDosObject(DOS_FIB,FileInfo);
  82.     }
  83.  
  84.     return(FileSize);
  85. }
  86.