Last active
April 30, 2021 22:54
-
-
Save alsamitech/1a9bda214d7dfe5d7147d64dbc8b4662 to your computer and use it in GitHub Desktop.
Requires <unistd.h>, <fcntl.h>. It is recommended that you contain the result as an arr_t or use a wrapper for that.
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
| char* unix_read_file(char* filenm, long unsigned int* len){ | |
| int fd=open(filenm, O_RDONLY); | |
| char* buf=0x0; | |
| if(fd>0){ | |
| struct stat stats; | |
| fstat(fd, &stats); | |
| buf=malloc(stats.st_size+1); | |
| if(buf){ | |
| read(fd, buf, stats.st_size); | |
| buf[stats.st_size]=0x0; | |
| } | |
| close(fd); | |
| } | |
| return buf; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment