Skip to content

Commit 8c8c844

Browse files
Taojunshen3836425+corob-msft@users.noreply.i.8713187.xyzSteve Wishnouskyopbld17pritamso
authored
5/12/2022 AM Publish (#4276)
* Fix issues in valarray content * Acrolinx pass * Update scanf %c to mention field width As part of UCRT refactoring, we introduced an undocumented breaking change that follows the C standard that changed out %c specifier from following the usual rules for field width to using the standardized exception for the %c specifier. We should document it. * Broken link fixed * Broken link fixed * Update dynamicbase.md arm32 and arm64 is not supported for this linker switch as ASLR cannot be disabled for these architectures. * update code examples * offer an alternative project type * fix for github #3859 * acrolinx * Clarify per Russ' comments Also update date and add formatting to current standard. * Work in progress for 17.2 release * Followup cpp-docs 3871 in linker opts * Fix grammar and formatting issues * Update latest-supported-vc-redist.md In the line 35, at the very end removed an extra dot. * Fix alarming bidi description * text tweaks * Address cpp-docs 3857 3865 3877 3882 * simplify code example-related to github #3847 (#4272) * simplify code example-related to github #3847 * right justify output * Update docs/c-runtime-library/reference/getdiskfree.md Co-authored-by: TylerMSFT <[email protected]> Co-authored-by: Shannon Leavitt <[email protected]> * fix for github 3787 * acrolinx pass * more acrolinx Co-authored-by: [email protected] <[email protected]> Co-authored-by: Steve Wishnousky <[email protected]> Co-authored-by: opbld17 <[email protected]> Co-authored-by: Pritam Ovhal <[email protected]> Co-authored-by: Lauren Prinn <[email protected]> Co-authored-by: PRMerger16 <[email protected]> Co-authored-by: TylerMSFT <[email protected]> Co-authored-by: PRMerger4 <[email protected]> Co-authored-by: Tamara K <[email protected]> Co-authored-by: Matin Sasanpour <[email protected]> Co-authored-by: Courtney Wales <[email protected]> Co-authored-by: Dennis Rea <[email protected]> Co-authored-by: Colin Cooper <[email protected]> Co-authored-by: Carolyn McSharry <[email protected]> Co-authored-by: PRMerger12 <[email protected]> Co-authored-by: Tyler Whitney <[email protected]> Co-authored-by: Shannon Leavitt <[email protected]> Co-authored-by: Anna Huff <[email protected]>
1 parent 7dca55c commit 8c8c844

File tree

11 files changed

+804
-855
lines changed

11 files changed

+804
-855
lines changed
Lines changed: 44 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
22
description: "Learn more about: _getdiskfree"
33
title: "_getdiskfree"
4-
ms.date: "4/2/2020"
4+
ms.date: 05/11/2022
55
api_name: ["_getdiskfree", "_o__getdiskfree"]
66
api_location: ["msvcrt.dll", "msvcr80.dll", "msvcr90.dll", "msvcr100.dll", "msvcr100_clr0400.dll", "msvcr110.dll", "msvcr110_clr0400.dll", "msvcr120.dll", "msvcr120_clr0400.dll", "ucrtbase.dll", "api-ms-win-crt-filesystem-l1-1-0.dll", "api-ms-win-crt-private-l1-1-0.dll"]
77
api_type: ["DLLExport"]
88
topic_type: ["apiref"]
99
f1_keywords: ["getdiskfree", "_getdiskfree"]
1010
helpviewer_keywords: ["diskfree_t type", "_getdiskfree function", "_diskfree_t type", "disk size", "getdiskfree function"]
11-
ms.assetid: 47a3f6cf-4816-452a-8f3d-1c3ae02a0f2a
1211
---
1312
# _getdiskfree
1413

15-
Uses information about a disk drive to populate a **_diskfree_t** structure.
14+
Get information about a disk drive such as total clusters, available clusters, sectors per cluster, and bytes per sector.
1615

1716
> [!IMPORTANT]
1817
> This API cannot be used in applications that execute in the Windows Runtime. For more information, see [CRT functions not supported in Universal Windows Platform apps](../../cppcx/crt-functions-not-supported-in-universal-windows-platform-apps.md).
@@ -28,19 +27,19 @@ unsigned _getdiskfree(
2827

2928
### Parameters
3029

31-
*drive*<br/>
30+
*`drive`*\
3231
The disk drive for which you want information.
3332

34-
*driveinfo*<br/>
35-
A **_diskfree_t** structure that will be populated with information about the drive.
33+
*`driveinfo`*\
34+
A **`_diskfree_t`** structure that will be populated with information about the drive.
3635

3736
## Return Value
3837

39-
If the function succeeds, the return value is zero. If the function fails, the return value is the error code. The value **errno** is set for any errors that are returned by the operating system. For more information about error conditions that are indicated by **errno**, see [errno Constants](../../c-runtime-library/errno-constants.md).
38+
If the function succeeds, the return value is zero. If the function fails, the return value is the error code. The value **`errno`** is set for any errors that are returned by the operating system. For more information about error conditions that are indicated by **`errno`**, see [`errno` constants](../../c-runtime-library/errno-constants.md).
4039

4140
## Remarks
4241

43-
The **_diskfree_t** structure is defined in Direct.h.
42+
The **`_diskfree_t`** structure is defined in Direct.h.
4443

4544
```C
4645
struct _diskfree_t {
@@ -51,15 +50,15 @@ struct _diskfree_t {
5150
};
5251
```
5352

54-
This function validates its parameters. If the *driveinfo* pointer is **NULL** or *drive* specifies an invalid drive, this function invokes an invalid parameter handler, as described in [Parameter Validation](../../c-runtime-library/parameter-validation.md). If execution is allowed to continue, the function returns **EINVAL** and sets **errno** to **EINVAL**. Valid drives range from 0 to 26. A *drive* value of 0 specifies the current drive; thereafter, numbers map to letters of the English alphabet such that 1 indicates drive A, 3 indicates drive C, and so on.
53+
This function validates its parameters. If the *`driveinfo`* pointer is **`NULL`** or *`drive`* specifies an invalid drive, this function invokes an invalid parameter handler, as described in [Parameter Validation](../../c-runtime-library/parameter-validation.md). If execution is allowed to continue, the function returns **`EINVAL`** and sets **`errno`** to **`EINVAL`**. Valid drives range from 0 to 26. A *drive* value of 0 specifies the current drive; thereafter, numbers map to letters of the English alphabet such that 1 indicates drive A, 3 indicates drive C, and so on.
5554

5655
By default, this function's global state is scoped to the application. To change this, see [Global state in the CRT](../global-state.md).
5756

5857
## Requirements
5958

6059
|Routine|Required header|
6160
|-------------|---------------------|
62-
|**_getdiskfree**|\<direct.h>|
61+
|**`_getdiskfree`**|`<direct.h>`|
6362

6463
For more compatibility information, see [Compatibility](../../c-runtime-library/compatibility.md).
6564

@@ -71,100 +70,47 @@ For more compatibility information, see [Compatibility](../../c-runtime-library/
7170
#include <windows.h>
7271
#include <direct.h>
7372
#include <stdio.h>
74-
#include <tchar.h>
75-
76-
TCHAR g_szBorder[] = _T("======================================================================\n");
77-
TCHAR g_szTitle1[] = _T("|DRIVE|TOTAL CLUSTERS|AVAIL CLUSTERS|SECTORS / CLUSTER|BYTES / SECTOR|\n");
78-
TCHAR g_szTitle2[] = _T("|=====|==============|==============|=================|==============|\n");
79-
TCHAR g_szLine[] = _T("| A: | | | | |\n");
80-
81-
void utoiRightJustified(TCHAR* szLeft, TCHAR* szRight, unsigned uVal);
82-
83-
int main(int argc, char* argv[]) {
84-
TCHAR szMsg[4200];
85-
struct _diskfree_t df = {0};
86-
ULONG uDriveMask = _getdrives();
87-
unsigned uErr, uLen, uDrive;
88-
89-
printf(g_szBorder);
90-
printf(g_szTitle1);
91-
printf(g_szTitle2);
92-
93-
for (uDrive=1; uDrive<=26; ++uDrive) {
94-
if (uDriveMask & 1) {
95-
uErr = _getdiskfree(uDrive, &df);
96-
memcpy(szMsg, g_szLine, sizeof(g_szLine));
97-
szMsg[3] = uDrive + 'A' - 1;
98-
99-
if (uErr == 0) {
100-
utoiRightJustified(szMsg+8, szMsg+19, df.total_clusters);
101-
utoiRightJustified(szMsg+23, szMsg+34, df.avail_clusters);
102-
utoiRightJustified(szMsg+38, szMsg+52, df.sectors_per_cluster);
103-
utoiRightJustified(szMsg+56, szMsg+67, df.bytes_per_sector);
104-
}
105-
else {
106-
uLen = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL,
107-
uErr, 0, szMsg+8, 4100, NULL);
108-
szMsg[uLen+6] = ' ';
109-
szMsg[uLen+7] = ' ';
110-
szMsg[uLen+8] = ' ';
111-
}
112-
113-
printf(szMsg);
114-
}
115-
116-
uDriveMask >>= 1;
117-
}
118-
119-
printf(g_szBorder);
120-
}
12173

122-
void utoiRightJustified(TCHAR* szLeft, TCHAR* szRight, unsigned uVal) {
123-
TCHAR* szCur = szRight;
124-
int nComma = 0;
125-
126-
if (uVal) {
127-
while (uVal && (szCur >= szLeft)) {
128-
if (nComma == 3) {
129-
*szCur = ',';
130-
nComma = 0;
131-
}
132-
else {
133-
*szCur = (uVal % 10) | 0x30;
134-
uVal /= 10;
135-
++nComma;
136-
}
137-
138-
--szCur;
139-
}
140-
}
141-
else {
142-
*szCur = '0';
143-
--szCur;
144-
}
145-
146-
if (uVal) {
147-
szCur = szLeft;
148-
149-
while (szCur <= szRight) {
150-
*szCur = '*';
151-
++szCur;
152-
}
153-
}
74+
int main(int argc, char* argv[])
75+
{
76+
ULONG uDriveMask = _getdrives();
77+
78+
for (unsigned uDrive = 1; uDrive <= 26; ++uDrive)
79+
{
80+
if (uDriveMask & 1)
81+
{
82+
struct _diskfree_t df = { 0 };
83+
unsigned uErr = _getdiskfree(uDrive, &df);
84+
printf("\nDrive: %c\n", uDrive + 'A' - 1);
85+
86+
if (uErr == 0)
87+
{
88+
printf("\tTotal clusters: %11u\n", df.total_clusters);
89+
printf("\tAvailable clusters: %11u\n", df.avail_clusters);
90+
printf("\tSectors per cluster: %11u\n", df.sectors_per_cluster);
91+
printf("\tBytes per sector: %11u\n", df.bytes_per_sector);
92+
}
93+
else
94+
{
95+
WCHAR errMsg[80];
96+
unsigned uLen = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL,
97+
uErr, 0, errMsg, sizeof(errMsg), NULL);
98+
printf("%S\n", errMsg);
99+
}
100+
}
101+
uDriveMask >>= 1;
102+
}
154103
}
155104
```
156105
157106
```Output
158-
======================================================================
159-
|DRIVE|TOTAL CLUSTERS|AVAIL CLUSTERS|SECTORS / CLUSTER|BYTES / SECTOR|
160-
|=====|==============|==============|=================|==============|
161-
| A: | The device is not ready. | | |
162-
| C: | 4,721,093 | 3,778,303 | 8 | 512 |
163-
| D: | 1,956,097 | 1,800,761 | 8 | 512 |
164-
| E: | The device is not ready. | | |
165-
======================================================================
107+
Drive: C
108+
Total clusters: 249754111
109+
Available clusters: 160184686
110+
Sectors per cluster: 8
111+
Bytes per sector: 512
166112
```
167113

168114
## See also
169115

170-
[Directory Control](../../c-runtime-library/directory-control.md)<br/>
116+
[Directory Control](../../c-runtime-library/directory-control.md)

docs/c-runtime-library/scanf-type-field-characters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ The `type` character is the only required format field; it appears after any opt
1414

1515
|Character|Type of input expected|Type of argument|Size argument in secure version?|
1616
|---------------|----------------------------|----------------------|--------------------------------------|
17-
|`c`|Character. When used with `scanf` functions, specifies single-byte character; when used with `wscanf` functions, specifies wide character. White-space characters that are ordinarily skipped are read when `c` is specified. To read next non-white-space single-byte character, use `%1s`; to read next non-white-space wide character, use `%1ws`.|Pointer to **`char`** when used with `scanf` functions, pointer to **`wchar_t`** when used with `wscanf` functions.|Required. Size does not include space for a null terminator.|
18-
|`C`|Opposite size character. When used with `scanf` functions, specifies wide character; when used with `wscanf` functions, specifies single-byte character. White-space characters that are ordinarily skipped are read when `C` is specified. To read next non-white-space single-byte character, use `%1s`; to read next non-white-space wide character, use `%1ws`.|Pointer to **`wchar_t`** when used with `scanf` functions, pointer to **`char`** when used with `wscanf` functions.|Required. Size argument does not include space for a null terminator.|
17+
|`c`|Character. When used with `scanf` functions, specifies single-byte character; when used with `wscanf` functions, specifies wide character. White-space characters that are ordinarily skipped are read when `c` is specified. Unlike with other type fields, the field width specifier indicates the exact number of characters, not the maximum. To read next non-white-space single-byte character, use `%1s`; to read next non-white-space wide character, use `%1ws`.|Pointer to **`char`** when used with `scanf` functions, pointer to **`wchar_t`** when used with `wscanf` functions.|Required. Size does not include space for a null terminator.|
18+
|`C`|Opposite size character. When used with `scanf` functions, specifies wide character; when used with `wscanf` functions, specifies single-byte character. White-space characters that are ordinarily skipped are read when `C` is specified. Unlike with other type fields, the field width specifier indicates the exact number of characters, not the maximum. To read next non-white-space single-byte character, use `%1s`; to read next non-white-space wide character, use `%1ws`.|Pointer to **`wchar_t`** when used with `scanf` functions, pointer to **`char`** when used with `wscanf` functions.|Required. Size argument does not include space for a null terminator.|
1919
|`d`|Decimal integer.|Pointer to **`int`**.|No.|
2020
|`i`|An integer. Hexadecimal if the input string begins with "0x" or "0X", octal if the string begins with "0", otherwise decimal.|Pointer to **`int`**.|No.|
2121
|`o`|Octal integer.|Pointer to **`int`**.|No.|

0 commit comments

Comments
 (0)