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