home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / fgetpos.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  57 lines

  1. /***
  2. *fgetpos.c - Contains the fgetpos runtime
  3. *
  4. *       Copyright (c) 1987-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Get file position (in an internal format).
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <stdio.h>
  13. #include <internal.h>
  14.  
  15. /***
  16. *int fgetpos(stream,pos) - Get file position (internal format)
  17. *
  18. *Purpose:
  19. *       Fgetpos gets the current file position for the file identified by
  20. *       [stream].  The file position is returned in the object pointed to
  21. *       by [pos] and is in internal format; that is, the user is not supposed
  22. *       to interpret the value but simply use it in the fsetpos call.  Our
  23. *       implementation simply uses fseek/ftell.
  24. *
  25. *Entry:
  26. *       FILE *stream = pointer to a file stream value
  27. *       fpos_t *pos = pointer to a file position value
  28. *
  29. *Exit:
  30. *       Successful fgetpos call returns 0.
  31. *       Unsuccessful fgetpos call returns non-zero (!0) value and sets
  32. *       ERRNO (this is done by ftell and passed back by fgetpos).
  33. *
  34. *Exceptions:
  35. *       None.
  36. *
  37. *******************************************************************************/
  38.  
  39. int __cdecl fgetpos (
  40.         FILE *stream,
  41.         fpos_t *pos
  42.         )
  43. {
  44. #ifdef _MAC
  45.         int posl = ftell(stream);
  46.  
  47.         *pos = (fpos_t) posl;
  48.  
  49.         if ( posl != -1L )
  50. #else  /* _MAC */
  51.         if ( (*pos = _ftelli64(stream)) != -1i64 )
  52. #endif  /* _MAC */
  53.                 return(0);
  54.         else
  55.                 return(-1);
  56. }
  57.