Remove unneeded function
This commit is contained in:
		| @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) { | ||||
| 	} | ||||
| 	// Read file | ||||
| 	char *path = argv[1]; | ||||
| 	char *png_buffer = load_file(get_fd(path)); | ||||
| 	char *png_buffer = load_file(path); | ||||
| 	if (!is_png(png_buffer)) { | ||||
| 		printf("It's not a PNG file\n"); | ||||
| 		exit(EXIT_FAILURE); | ||||
|   | ||||
| @@ -35,31 +35,17 @@ | ||||
| #include <stdbool.h> | ||||
| #include "png.h" | ||||
|  | ||||
| int get_fd(char *path) { | ||||
| FILE *get_file(char *path) { | ||||
| 	FILE *fp = fopen(path, "rb"); | ||||
| 	if (fp == NULL) { | ||||
| 		perror("fopen"); | ||||
| 		exit(EXIT_FAILURE); | ||||
| 	} | ||||
| 	int fd = fileno(fp); | ||||
| 	if (fd == -1) { | ||||
| 		perror("fileno"); | ||||
| 		exit(EXIT_FAILURE); | ||||
| 	} | ||||
| 	return fd; | ||||
| } | ||||
|  | ||||
| FILE *get_fp(int fd) { | ||||
| 	FILE *fp = fdopen(fd, "rb"); | ||||
| 	if (fp == NULL) { | ||||
| 		perror("fdopen"); | ||||
| 		exit(EXIT_FAILURE); | ||||
| 	} | ||||
| 	return fp; | ||||
| } | ||||
|  | ||||
| char *load_file(int fd) { | ||||
| 	FILE *fp = get_fp(fd); | ||||
| char *load_file(char *path) { | ||||
| 	FILE *fp = get_file(path); | ||||
| 	fseek(fp, 0, SEEK_END); | ||||
| 	long size = ftell(fp); | ||||
| 	rewind(fp); | ||||
|   | ||||
| @@ -47,14 +47,11 @@ typedef struct png_chunk { | ||||
| 	uint32_t crc; | ||||
| } png_chunk; | ||||
|  | ||||
| // Get file descriptor from path | ||||
| // Get FILE from path | ||||
| int get_fd(char *path); | ||||
|  | ||||
| // Get FILE* from file descriptor | ||||
| FILE *get_fp(int fd); | ||||
|  | ||||
| // Store file in heap memory | ||||
| char *load_file(int fd); | ||||
| char *load_file(char *path); | ||||
|  | ||||
| // Check if file is a PNG | ||||
| int is_png(char *buffer); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user