Skip to content

Commit 0b31421

Browse files
committed
winapi: Run clang format
1 parent 736d943 commit 0b31421

36 files changed

+2462
-2454
lines changed

lib/winapi/badptr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BOOL IsBadWritePtr (LPVOID lp, UINT_PTR ucb)
1010
// The Microsoft implementation then probes each page.
1111
// For Xbox, this is not suitable because `lp` potentially points at MMIO.
1212

13-
//FIXME: Walk allocations in region with NtQueryVirtualMemory and check write permission?
13+
// FIXME: Walk allocations in region with NtQueryVirtualMemory and check write permission?
1414

1515
// We disallow all access for now, because memory is potentially unsafe
1616
return TRUE;

lib/winapi/debug.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ void WINAPI OutputDebugStringA (LPCTSTR lpOutputString)
2424

2525
__asm__ __volatile__("mov $1, %%eax\n" // $1 = BREAKPOINT_PRINT
2626
"int $0x2D\n"
27-
"int $3\n": :"c" (&s));
27+
"int $3\n" : : "c"(&s));
2828
}

lib/winapi/debugapi.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#include <windef.h>
99

1010
#ifdef __cplusplus
11-
extern "C"
12-
{
11+
extern "C" {
1312
#endif
1413

1514
BOOL IsDebuggerPresent (VOID);

lib/winapi/errhandlingapi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
// SPDX-FileCopyrightText: 2019 Stefan Schmidt
44

5-
#include <windows.h>
65
#include <string.h>
6+
#include <windows.h>
77
#include <xboxkrnl/xboxkrnl.h>
88

99
VOID RaiseException (DWORD dwExceptionCode, DWORD dwExceptionFlags, DWORD nNumberOfArguments, const ULONG_PTR *lpArguments)

lib/winapi/errhandlingapi.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#include <winbase.h>
99

1010
#ifdef __cplusplus
11-
extern "C"
12-
{
11+
extern "C" {
1312
#endif
1413

1514
VOID RaiseException (DWORD dwExceptionCode, DWORD dwExceptionFlags, DWORD nNumberOfArguments, const ULONG_PTR *lpArguments);

lib/winapi/error.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
// SPDX-FileCopyrightText: 2019 Stefan Schmidt
44

5-
#include <winbase.h>
65
#include <threads.h>
6+
#include <winbase.h>
77

88
static thread_local DWORD lastError = 0;
99

lib/winapi/fiber.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
// SPDX-FileCopyrightText: 2019-2022 Stefan Schmidt
44

5-
#include <windows.h>
65
#include <assert.h>
76
#include <stdint.h>
87
#include <threads.h>
8+
#include <windows.h>
99

1010
// Each thread gets a node to keep track of its FLS data.
1111
// Threads must register themselves, so their FLS nodes can be put into a list
@@ -29,7 +29,7 @@ static __cdecl VOID fls_init (VOID)
2929
InitializeListHead(&fls_nodes_list);
3030
}
3131
#pragma comment(linker, "/include:___fls_init_p")
32-
__attribute__((section(".CRT$XXT"))) void (__cdecl *const __fls_init_p)(void) = fls_init;
32+
__attribute__((section(".CRT$XXT"))) void(__cdecl *const __fls_init_p)(void) = fls_init;
3333

3434
VOID fls_register_thread (VOID)
3535
{
@@ -70,11 +70,13 @@ DWORD FlsAlloc (PFLS_CALLBACK_FUNCTION lpCallback)
7070
EnterCriticalSection(&fls_lock);
7171

7272
for (size_t i = 0; i < (FLS_MAXIMUM_AVAILABLE / 32); i++) {
73-
if (fls_bitmap[i] == 0xFFFFFFFF) continue;
73+
if (fls_bitmap[i] == 0xFFFFFFFF) {
74+
continue;
75+
}
7476

7577
unsigned int index = __builtin_ctz(~fls_bitmap[i]);
7678
fls_bitmap[i] |= (1 << index);
77-
retval = i*32 + index;
79+
retval = i * 32 + index;
7880
fls_dtors[retval] = lpCallback;
7981
break;
8082
}

lib/winapi/fibersapi.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#include <winbase.h>
99

1010
#ifdef __cplusplus
11-
extern "C"
12-
{
11+
extern "C" {
1312
#endif
1413

1514
DWORD FlsAlloc (PFLS_CALLBACK_FUNCTION lpCallback);

lib/winapi/fileapi.h

+19-20
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
#ifndef __FILEAPI_H__
77
#define __FILEAPI_H__
88

9-
#include <windef.h>
109
#include <winbase.h>
10+
#include <windef.h>
1111
#include <winnt.h>
1212

1313
#ifdef __cplusplus
14-
extern "C"
15-
{
14+
extern "C" {
1615
#endif
1716

1817
DWORD GetFileAttributesA (LPCSTR lpFileName);
@@ -22,10 +21,10 @@ BOOL SetFileAttributesA (LPCSTR lpFileName, DWORD dwFileAttributes);
2221
BOOL GetFileTime (HANDLE hFile, LPFILETIME lpCreationTime, LPFILETIME lpLastAccessTime, LPFILETIME lpLastWriteTime);
2322
BOOL SetFileTime (HANDLE hFile, const FILETIME *lpCreationTime, const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime);
2423

25-
#define CREATE_NEW 1
26-
#define CREATE_ALWAYS 2
27-
#define OPEN_EXISTING 3
28-
#define OPEN_ALWAYS 4
24+
#define CREATE_NEW 1
25+
#define CREATE_ALWAYS 2
26+
#define OPEN_EXISTING 3
27+
#define OPEN_ALWAYS 4
2928
#define TRUNCATE_EXISTING 5
3029

3130
HANDLE CreateFileA (LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
@@ -54,19 +53,19 @@ DWORD GetLogicalDrives (VOID);
5453
DWORD GetLogicalDriveStringsA (DWORD nBufferLength, LPSTR lpBuffer);
5554

5655
#ifndef UNICODE
57-
#define GetFileAttributes GetFileAttributesA
58-
#define GetFileAttributesEx GetFileAttributesExA
59-
#define SetFileAttributes SetFileAttributesA
60-
#define CreateFile CreateFileA
61-
#define FindFirstFile FindFirstFileA
62-
#define FindNextFile FindNextFileA
63-
#define DeleteFile(...) DeleteFileA(__VA_ARGS__)
64-
#define RemoveDirectory(...) RemoveDirectoryA(__VA_ARGS__)
65-
#define CreateDirectory(...) CreateDirectoryA(__VA_ARGS__)
66-
#define MoveFile(...) MoveFileA(__VA_ARGS__)
67-
#define CopyFile(...) CopyFileA(__VA_ARGS__)
68-
#define GetDiskFreeSpaceEx GetDiskFreeSpaceExA
69-
#define GetDiskFreeSpace GetDiskFreeSpaceA
56+
#define GetFileAttributes GetFileAttributesA
57+
#define GetFileAttributesEx GetFileAttributesExA
58+
#define SetFileAttributes SetFileAttributesA
59+
#define CreateFile CreateFileA
60+
#define FindFirstFile FindFirstFileA
61+
#define FindNextFile FindNextFileA
62+
#define DeleteFile(...) DeleteFileA(__VA_ARGS__)
63+
#define RemoveDirectory(...) RemoveDirectoryA(__VA_ARGS__)
64+
#define CreateDirectory(...) CreateDirectoryA(__VA_ARGS__)
65+
#define MoveFile(...) MoveFileA(__VA_ARGS__)
66+
#define CopyFile(...) CopyFileA(__VA_ARGS__)
67+
#define GetDiskFreeSpaceEx GetDiskFreeSpaceExA
68+
#define GetDiskFreeSpace GetDiskFreeSpaceA
7069
#define GetLogicalDriveStrings GetLogicalDriveStringsA
7170
#else
7271
#error nxdk does not support the Unicode API

lib/winapi/fileio.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
// SPDX-FileCopyrightText: 2019-2021 Stefan Schmidt
44

5-
#include <fileapi.h>
6-
#include <winerror.h>
75
#include <assert.h>
6+
#include <fileapi.h>
87
#include <stdbool.h>
98
#include <string.h>
9+
#include <winerror.h>
1010
#include <xboxkrnl/xboxkrnl.h>
1111

1212
HANDLE CreateFileA (LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
@@ -77,7 +77,7 @@ HANDLE CreateFileA (LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
7777
if (status == STATUS_OBJECT_NAME_COLLISION) {
7878
SetLastError(ERROR_FILE_EXISTS);
7979
} else if (status == STATUS_FILE_IS_A_DIRECTORY) {
80-
if (lpFileName[path.Length-1] == '\\') {
80+
if (lpFileName[path.Length - 1] == '\\') {
8181
SetLastError(ERROR_PATH_NOT_FOUND);
8282
} else {
8383
SetLastError(ERROR_ACCESS_DENIED);
@@ -190,7 +190,7 @@ BOOL WriteFile (HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPD
190190
lpOverlapped->InternalHigh = 0;
191191

192192
status = NtWriteFile(hFile, lpOverlapped->hEvent, NULL, NULL, (PIO_STATUS_BLOCK)&lpOverlapped->Internal,
193-
(PVOID)lpBuffer, nNumberOfBytesToWrite, &overlappedOffset);
193+
(PVOID)lpBuffer, nNumberOfBytesToWrite, &overlappedOffset);
194194

195195
// The write can finish immediately. Handle this case
196196
if (NT_SUCCESS(status) && status != STATUS_PENDING) {
@@ -341,7 +341,7 @@ BOOL SetFilePointerEx (HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTE
341341
case FILE_CURRENT:
342342
status = NtQueryInformationFile(hFile, &ioStatusBlock, &positionInfo, sizeof(positionInfo), FilePositionInformation);
343343

344-
if(!NT_SUCCESS(status)) {
344+
if (!NT_SUCCESS(status)) {
345345
SetLastError(RtlNtStatusToDosError(status));
346346
return FALSE;
347347
}

lib/winapi/filemanip.c

+27-26
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
// SPDX-FileCopyrightText: 2019-2022 Stefan Schmidt
44
// SPDX-FileCopyrightText: 2021 Erik Abair
55

6-
#include <fileapi.h>
7-
#include <handleapi.h>
8-
#include <winbase.h>
9-
#include <winerror.h>
106
#include <assert.h>
117
#include <ctype.h>
8+
#include <fileapi.h>
9+
#include <handleapi.h>
1210
#include <stdbool.h>
1311
#include <string.h>
12+
#include <winbase.h>
13+
#include <winerror.h>
1414
#include <xboxkrnl/xboxkrnl.h>
1515

1616
DWORD GetFileAttributesA (LPCSTR lpFileName)
@@ -356,26 +356,26 @@ BOOL CopyFileA (LPCSTR lpExistingFileName, LPCSTR lpNewFileName, BOOL bFailIfExi
356356
InitializeObjectAttributes(&objectAttributes, &targetPath, OBJ_CASE_INSENSITIVE, ObDosDevicesDirectory(), NULL);
357357

358358
status = NtCreateFile(
359-
&targetHandle,
360-
FILE_GENERIC_WRITE,
361-
&objectAttributes,
362-
&ioStatusBlock,
363-
&networkOpenInformation.AllocationSize,
364-
networkOpenInformation.FileAttributes,
365-
0,
366-
bFailIfExists ? FILE_CREATE : FILE_SUPERSEDE,
367-
FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE | FILE_SEQUENTIAL_ONLY);
359+
&targetHandle,
360+
FILE_GENERIC_WRITE,
361+
&objectAttributes,
362+
&ioStatusBlock,
363+
&networkOpenInformation.AllocationSize,
364+
networkOpenInformation.FileAttributes,
365+
0,
366+
bFailIfExists ? FILE_CREATE : FILE_SUPERSEDE,
367+
FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE | FILE_SEQUENTIAL_ONLY);
368368
if (!NT_SUCCESS(status)) {
369369
NtClose(sourceHandle);
370370
SetLastError(RtlNtStatusToDosError(status));
371371
return FALSE;
372372
}
373373

374374
status = NtAllocateVirtualMemory(&readBuffer,
375-
0,
376-
&readBufferRegionSize,
377-
MEM_RESERVE | MEM_COMMIT,
378-
PAGE_READWRITE);
375+
0,
376+
&readBufferRegionSize,
377+
MEM_RESERVE | MEM_COMMIT,
378+
PAGE_READWRITE);
379379
if (!NT_SUCCESS(status)) {
380380
NtClose(sourceHandle);
381381
NtClose(targetHandle);
@@ -418,11 +418,11 @@ BOOL CopyFileA (LPCSTR lpExistingFileName, LPCSTR lpNewFileName, BOOL bFailIfExi
418418
fileBasicInformation.LastWriteTime = networkOpenInformation.LastWriteTime;
419419
fileBasicInformation.FileAttributes = networkOpenInformation.FileAttributes;
420420
status = NtSetInformationFile(
421-
targetHandle,
422-
&ioStatusBlock,
423-
&fileBasicInformation,
424-
sizeof(fileBasicInformation),
425-
FileBasicInformation);
421+
targetHandle,
422+
&ioStatusBlock,
423+
&fileBasicInformation,
424+
sizeof(fileBasicInformation),
425+
FileBasicInformation);
426426
if (!NT_SUCCESS(status)) {
427427
SetLastError(RtlNtStatusToDosError(status));
428428
NtClose(sourceHandle);
@@ -439,8 +439,8 @@ BOOL CopyFileA (LPCSTR lpExistingFileName, LPCSTR lpNewFileName, BOOL bFailIfExi
439439

440440
status = NtClose(targetHandle);
441441
if (!NT_SUCCESS(status)) {
442-
SetLastError(RtlNtStatusToDosError(status));
443-
return FALSE;
442+
SetLastError(RtlNtStatusToDosError(status));
443+
return FALSE;
444444
}
445445
return TRUE;
446446
}
@@ -555,7 +555,8 @@ DWORD GetLogicalDrives (VOID)
555555
ANSI_STRING path;
556556
HANDLE handle;
557557
OBJECT_ATTRIBUTES attributes;
558-
struct {
558+
struct
559+
{
559560
OBJECT_DIRECTORY_INFORMATION objDirInfo;
560561
CHAR filenameBuf[2];
561562
} objDirInfoBuf;
@@ -614,7 +615,7 @@ DWORD GetLogicalDriveStringsA (DWORD nBufferLength, LPSTR lpBuffer)
614615
}
615616

616617
if (nBufferLength == 0 || nBufferLength < requiredBufLength) {
617-
return requiredBufLength+1;
618+
return requiredBufLength + 1;
618619
}
619620

620621
for (int bit = 0; bit < 26; bit++) {

lib/winapi/findfile.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,29 @@
22

33
// SPDX-FileCopyrightText: 2019-2020 Stefan Schmidt
44

5-
#include <string.h>
65
#include <assert.h>
6+
#include <fileapi.h>
77
#include <stdbool.h>
8+
#include <string.h>
89
#include <winbase.h>
9-
#include <xboxkrnl/xboxkrnl.h>
1010
#include <winerror.h>
11-
#include <fileapi.h>
11+
#include <xboxkrnl/xboxkrnl.h>
1212

13-
struct FileInfo {
13+
struct FileInfo
14+
{
1415
FILE_DIRECTORY_INFORMATION dirInfo;
1516
// Reserve path buffer minus the null-terminator and the first byte provided by dirInfo
16-
char filename[MAX_PATH-2];
17+
char filename[MAX_PATH - 2];
1718
};
1819

1920
static void dirtofind (FILE_DIRECTORY_INFORMATION *dirInfo, LPWIN32_FIND_DATAA lpFindFileData)
2021
{
2122
lpFindFileData->dwFileAttributes = dirInfo->FileAttributes;
2223
lpFindFileData->ftCreationTime.dwLowDateTime = dirInfo->CreationTime.LowPart;
2324
lpFindFileData->ftCreationTime.dwHighDateTime = dirInfo->CreationTime.HighPart;
24-
lpFindFileData->ftLastAccessTime.dwLowDateTime = dirInfo->LastAccessTime.LowPart;
25+
lpFindFileData->ftLastAccessTime.dwLowDateTime = dirInfo->LastAccessTime.LowPart;
2526
lpFindFileData->ftLastAccessTime.dwHighDateTime = dirInfo->LastAccessTime.HighPart;
26-
lpFindFileData->ftLastWriteTime.dwLowDateTime = dirInfo->LastWriteTime.LowPart;
27+
lpFindFileData->ftLastWriteTime.dwLowDateTime = dirInfo->LastWriteTime.LowPart;
2728
lpFindFileData->ftLastWriteTime.dwHighDateTime = dirInfo->LastWriteTime.HighPart;
2829
lpFindFileData->nFileSizeHigh = dirInfo->EndOfFile.HighPart;
2930
lpFindFileData->nFileSizeLow = dirInfo->EndOfFile.LowPart;
@@ -48,8 +49,9 @@ HANDLE FindFirstFileA (LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
4849
RtlInitAnsiString(&dirPath, lpFileName);
4950

5051
for (maskOffset = dirPath.Length; maskOffset > 0; maskOffset--) {
51-
if (dirPath.Buffer[maskOffset - 1] == '\\')
52+
if (dirPath.Buffer[maskOffset - 1] == '\\') {
5253
break;
54+
}
5355
}
5456

5557
mask.Buffer = dirPath.Buffer + maskOffset;

lib/winapi/handleapi.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
#include <winbase.h>
77
#include <xboxkrnl/xboxkrnl.h>
88

9-
BOOL CloseHandle (HANDLE hObject)
10-
{
11-
NTSTATUS status = NtClose(hObject);
9+
BOOL CloseHandle (HANDLE hObject)
10+
{
11+
NTSTATUS status = NtClose(hObject);
1212

13-
if (NT_SUCCESS(status)) {
14-
return TRUE;
15-
} else {
16-
SetLastError(RtlNtStatusToDosError(status));
17-
return FALSE;
18-
}
19-
}
13+
if (NT_SUCCESS(status)) {
14+
return TRUE;
15+
} else {
16+
SetLastError(RtlNtStatusToDosError(status));
17+
return FALSE;
18+
}
19+
}

lib/winapi/handleapi.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#include <windef.h>
99

1010
#ifdef __cplusplus
11-
extern "C"
12-
{
11+
extern "C" {
1312
#endif
1413

1514
BOOL CloseHandle (HANDLE hObject);

0 commit comments

Comments
 (0)