From eebd87c2b696151d4e194a7cbeaf2e06d4e0106f Mon Sep 17 00:00:00 2001 From: Paul Tucker Date: Thu, 23 Mar 2000 00:45:51 +0000 Subject: [PATCH] Updated to cap requested type to be within allowable range --- harbour/ChangeLog | 9 +++ harbour/doc/en/diskspac.txt | 129 +++------------------------------- harbour/include/fileio.ch | 6 +- harbour/source/rtl/diskspac.c | 20 +++--- 4 files changed, 33 insertions(+), 131 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 4c939c4864..18b8636935 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,12 @@ +20000322-19:35 EST Paul Tucker + * include/fileio.ch + * source/rtl/dskspac.c + * Changed and reordered HB_DISK_ defines to be in the range 0-3 + * source/rtl/dskspac.c + * cap uiType to HB_DISK_TOTAL for out of range types. + * doc/en/diskspac.txt + * updated + 2000-03-22 17:25 GMT-5 David G. Holm + source/rtl/gtpca/kbdos2.gcc + Added hb_gt_ReadKey() support for os2/gcc platform diff --git a/harbour/doc/en/diskspac.txt b/harbour/doc/en/diskspac.txt index 3be03c112a..baf7f35955 100644 --- a/harbour/doc/en/diskspac.txt +++ b/harbour/doc/en/diskspac.txt @@ -26,12 +26,12 @@ * The number of the drive you are requesting info on where 1 = A, * 2 = B, etc. For 0 or no parameter, DiskSpace will operate on the current * drive. The default is 0 - * The type of space being requested. The default is HB_FS_AVAIL. + * The type of space being requested. The default is HB_DISK_AVAIL. * $RETURNS$ * The number of bytes on the requested disk that match the * requested type. * $DESCRIPTION$ - * By default, this function will return the number of bytes of amount of + * By default, this function will return the number of bytes of * free space on the current drive that is available to the user * requesting the information. * @@ -44,11 +44,12 @@ * will be equal to that returned for HB_FS_FREE. * HB_FS_FREE The actual amount of free diskspace on the drive. * HB_FS_USED The number of bytes in use on the disk. - * HB_FS_TOTAL The total size of the disk. + * HB_FS_TOTAL The total amount of space allocated for the user if + * disk quotas are in effect, otherwise, the actual size + * of the drive. * - * If information is requested on a removeable disk that is not available, - * the O/S may request that a disk be inserted in the drive, otherwise the - * return value will be 0. + * If information is requested on a disk that is not available, a runtime + * error 2018 will be raised. * $EXAMPLES$ * ? "You can use : " +Str( DiskSpace() ) + " bytes " +; * "Out of a total of " + Str( DiskSpace(0,HB_FS_TOTAL) ) @@ -56,120 +57,10 @@ * R * $COMPLIANCE$ * CA-Clipper will return an integer value which limits it's usefulness to - * drives less than 2 gigabytes. The Harbour version returns a floating - * point value with 0 decimals if the disk is > 2 gigabytes. + * drives less than 2 gigabytes. The Harbour version will return a + * floating point value with 0 decimals if the disk is > 2 gigabytes. * is a Harbour extension. * $SEEALSO$ - * DISKFREE(),DISKUSED(),DISKFULL(),tests\tstdspac.prg + * tests\tstdspac.prg * $END$ */ - -/* $DOC$ - * $FUNCNAME$ - * DISKFREE() - * $CATEGORY$ - * Low level disk information - * $ONELINER$ - * Get the amount of space on a disk - * $SYNTAX$ - * DISKFREE( [] ) --> nDiskbytes - * $ARGUMENTS$ - * The number of the drive you are requesting info on where 1 = A, - * 2 = B, etc. For 0 or no parameter, DiskFree will operate on the current - * drive. The default is 0 - * $RETURNS$ - * The number of bytes of space available on the requested - * disk - * $DESCRIPTION$ - * This function will return the number of bytes of free space on the - * current, or requested drive. - * - * Using DiskFree(0) is the same as calling DiskSpace(0,HB_FS_FREE) - * - * If information is requested on a removeable disk that is not available, - * the O/S may request that a disk be inserted in the drive, otherwise the - * return value will be 0 - * $EXAMPLES$ - * ? "There is : " +Str( DiskFree() ) + " bytes " +; - * "Out of a total of " + Str( DiskSpace(0,HB_FS_TOTAL) ) - * $STATUS$ - * R - * $COMPLIANCE$ - * - unknown - - * $SEEALSO$ - * DISKSPACE(),DISKUSED(),DISKFULL(),tests\tstdspac.prg - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * DISKUSED() - * $CATEGORY$ - * Low level disk information - * $ONELINER$ - * Get the amount of space in use on a disk - * $SYNTAX$ - * DISKUSED( [] ) --> nDiskbytes - * $ARGUMENTS$ - * The number of the drive you are requesting info on where 1 = A, - * 2 = B, etc. For 0 or no parameter, DiskUsed will operate on the current - * drive. The default is 0 - * $RETURNS$ - * The number of bytes in use on the requested disk - * $DESCRIPTION$ - * This function will return the number of bytes in use on the - * current, or requested drive. - * - * Using DiskUsed(0) is the same as calling DiskSpace(0,HB_FS_USED) - * - * If information is requested on a removeable disk that is not available, - * the O/S may request that a disk be inserted in the drive, otherwise the - * return value will be 0 - * $EXAMPLES$ - * ? "There is : " +Str( DiskUsed() ) + " bytes " +; - * "Out of a total of " + Str( DiskSpace(0,HB_FS_USED) ) - * $STATUS$ - * R - * $COMPLIANCE$ - * - unknown - - * $SEEALSO$ - * DISKSPACE(),DISKFREE(),DISKFULL(),tests\tstdspac.prg - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * DISKFULL() - * $CATEGORY$ - * Low level disk information - * $ONELINER$ - * Get the total amount of space on a disk - * $SYNTAX$ - * DISKFULL( [] ) --> nDiskbytes - * $ARGUMENTS$ - * The number of the drive you are requesting info on where 1 = A, - * 2 = B, etc. For 0 or no parameter, DiskUsed will operate on the current - * drive. The default is 0 - * $RETURNS$ - * The total number of bytes on the requested disk - * $DESCRIPTION$ - * This function will return the number of bytes on the - * current, or requested drive. - * - * Using DiskFull(0) is the same as calling DiskSpace(0,HB_FS_TOTAL) - * - * If information is requested on a removeable disk that is not available, - * the O/S may request that a disk be inserted in the drive, otherwise the - * return value will be 0 - * $EXAMPLES$ - * ? "There is : " +Str( DiskUsed() ) + " bytes " +; - * "Out of a total of " + Str( DiskFull() ) - * $STATUS$ - * R - * $COMPLIANCE$ - * - unknown - - * $SEEALSO$ - * DISKSPACE(),DISKFREE(),DISKUSED(),tests\tstdspac.prg - * $END$ - */ - diff --git a/harbour/include/fileio.ch b/harbour/include/fileio.ch index 813ed6d2b8..e3b66df6e1 100644 --- a/harbour/include/fileio.ch +++ b/harbour/include/fileio.ch @@ -86,10 +86,10 @@ #define F_ERROR ( -1 ) /* Unspecified error */ /* DISKSPACE() types */ +#define HB_DISK_AVAIL 0 #define HB_DISK_FREE 1 -#define HB_DISK_AVAIL 2 -#define HB_DISK_TOTAL 4 -#define HB_DISK_USED 8 +#define HB_DISK_USED 2 +#define HB_DISK_TOTAL 3 #endif /* _FILEIO_CH */ diff --git a/harbour/source/rtl/diskspac.c b/harbour/source/rtl/diskspac.c index ebc59a383c..0491987f17 100644 --- a/harbour/source/rtl/diskspac.c +++ b/harbour/source/rtl/diskspac.c @@ -67,6 +67,8 @@ HB_FUNC( DISKSPACE ) USHORT uiType = ISNUM( 2 ) ? hb_parni( 2 ) : HB_DISK_AVAIL; double dSpace = 0.0; + uiType = min( uiType, HB_DISK_TOTAL ); + #if defined(HB_OS_DOS) || defined(__WATCOMC__) struct diskfree_t disk; @@ -84,15 +86,15 @@ HB_FUNC( DISKSPACE ) { switch( uiType ) { - case HB_DISK_FREE: case HB_DISK_AVAIL: + case HB_DISK_FREE: dSpace = ( double ) disk.avail_clusters * ( double ) disk.sectors_per_cluster * ( double ) disk.bytes_per_sector; break; - case HB_DISK_TOTAL: case HB_DISK_USED: + case HB_DISK_TOTAL: dSpace = ( double ) disk.total_clusters * ( double ) disk.sectors_per_cluster * ( double ) disk.bytes_per_sector ); @@ -153,16 +155,16 @@ HB_FUNC( DISKSPACE ) { switch( uiType ) { - case HB_DISK_FREE: - memcpy( &i64RetVal, &i64FreeBytes, sizeof( ULARGE_INTEGER ) ); - break; - case HB_DISK_AVAIL: memcpy( &i64RetVal, &i64FreeBytesToCaller, sizeof( ULARGE_INTEGER ) ); break; - case HB_DISK_TOTAL: + case HB_DISK_FREE: + memcpy( &i64RetVal, &i64FreeBytes, sizeof( ULARGE_INTEGER ) ); + break; + case HB_DISK_USED: + case HB_DISK_TOTAL: memcpy( &i64RetVal, &i64TotalBytes, sizeof( ULARGE_INTEGER ) ); } @@ -220,15 +222,15 @@ HB_FUNC( DISKSPACE ) { switch( uiType ) { - case HB_DISK_FREE: case HB_DISK_AVAIL: + case HB_DISK_FREE: dSpace = ( double ) dwNumberOfFreeClusters * ( double ) dwSectorsPerCluster * ( double ) dwBytesPerSector; break; - case HB_DISK_TOTAL: case HB_DISK_USED: + case HB_DISK_TOTAL: dSpace = ( double ) dwTotalNumberOfClusters * ( double ) dwSectorsPerCluster * ( double ) dwBytesPerSector;