Remove unneeded function

This commit is contained in:
Isaac Shoebottom 2023-12-05 12:57:16 -04:00
parent 530ab9a135
commit 93635bc1d6
3 changed files with 6 additions and 23 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);