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

  1. /***
  2. *drivfree.c - Get the size of a disk
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       This file has _getdiskfree()
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <direct.h>
  13. #include <oscalls.h>
  14.  
  15. /***
  16. *int _getdiskfree(drivenum, diskfree)  - get size of a specified disk
  17. *
  18. *Purpose:
  19. *       Gets the size of the current or specified disk drive
  20. *
  21. *Entry:
  22. *       int drivenum - 0 for current drive, or drive 1-26
  23. *
  24. *Exit:
  25. *       returns 0 if succeeds
  26. *       returns system error code on error.
  27. *
  28. *Exceptions:
  29. *
  30. *******************************************************************************/
  31.  
  32. #ifndef _WIN32
  33. #error ERROR - ONLY WIN32 TARGET SUPPORTED!
  34. #endif  /* _WIN32 */
  35.  
  36. unsigned __cdecl _getdiskfree (
  37.         unsigned uDrive,
  38.         struct _diskfree_t * pdf
  39.         )
  40. {
  41.         char   Root[4];
  42.         char * pRoot;
  43.  
  44.         if ( uDrive == 0 ) {
  45.             pRoot = NULL;
  46.         }
  47.         else if ( uDrive > 26 ) {
  48.             return ( ERROR_INVALID_PARAMETER );
  49.         }
  50.         else {
  51.             pRoot = &Root[0];
  52.             Root[0] = (char)uDrive + (char)('A' - 1);
  53.             Root[1] = ':';
  54.             Root[2] = '\\';
  55.             Root[3] = '\0';
  56.         }
  57.  
  58.  
  59.         if ( !GetDiskFreeSpace( pRoot,
  60.                                 (LPDWORD)&(pdf->sectors_per_cluster),
  61.                                 (LPDWORD)&(pdf->bytes_per_sector),
  62.                                 (LPDWORD)&(pdf->avail_clusters),
  63.                                 (LPDWORD)&(pdf->total_clusters)) )
  64.         {
  65.             return ( (unsigned)GetLastError() );
  66.         }
  67.         return ( 0 );
  68. }
  69.