Created
September 2, 2022 01:22
-
-
Save worthless443/642331ef12e1906ae879f08c62fe5c3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
#include<sys/mman.h> | |
#include<string.h> | |
#include<assert.h> | |
#define GLOBAL_FILE 0x4000000 | |
void start_file(const char *fname) { | |
void *fp = mmap((void*)GLOBAL_FILE, sizeof(FILE), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE,0,0); | |
FILE *f = fopen(fname, "w"); | |
assert(*(int*)fp!=-1); | |
memcpy(fp, f, sizeof(FILE)); | |
} | |
void write_file(const char *what) { | |
FILE *f = (FILE*)(void*)GLOBAL_FILE; | |
fwrite(what,1,strlen(what),f); | |
} | |
int main() { | |
start_file("file.txt"); | |
write_file("content"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment