- /*
 - * winsetfilesize1.c - Win32 set file size
 - *
 - * Written by Roland Mainz <roland.mainz@nrubsig.org>
 - */
 - #define UNICODE 1
 - #define _UNICODE 1
 - #include <windows.h>
 - #include <stdlib.h>
 - #include <stdbool.h>
 - #include <stdio.h>
 - int main(int ac, char *av[]) {
 - HANDLE hFile = CreateFileA("myfile.txt", GENERIC_WRITE, 0, NULL,
 - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 - if (hFile == INVALID_HANDLE_VALUE) {
 - // Error handling
 - return 1;
 - }
 - LARGE_INTEGER newEndOfFile = { .QuadPart = 1234567890 };
 - if (true) {
 - FILE_END_OF_FILE_INFO endOfFile;
 - endOfFile.EndOfFile = newEndOfFile;
 - if (!SetFileInformationByHandle(hFile, FileEndOfFileInfo,
 - &endOfFile, sizeof(endOfFile))) {
 - (void)CloseHandle(hFile);
 - return 1;
 - }
 - }
 - newEndOfFile.QuadPart = 72448;
 - if (true) {
 - FILE_ALLOCATION_INFO endOfFile;
 - endOfFile.AllocationSize = newEndOfFile;
 - if (!SetFileInformationByHandle(hFile, FileAllocationInfo,
 - &endOfFile, sizeof(endOfFile))) {
 - (void)CloseHandle(hFile);
 - return 1;
 - }
 - }
 - // Close the file handle
 - (void)CloseHandle(hFile);
 - return 0;
 - }
 
winsetfilesize1.c - Win32 set file size
Posted by Anonymous on Wed 15th May 2024 23:45
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
 nrubsig.kpaste.net RSS