Implement file opening

This commit is contained in:
Shav Kinderlehrer 2023-04-10 00:58:48 -04:00
parent 97a99175f4
commit e2ed5aca4d
5 changed files with 33 additions and 3 deletions

View File

@ -9,10 +9,10 @@ CC=cc
CFLAGS=-I$(IDIR) -Wall -Wextra -pedantic CFLAGS=-I$(IDIR) -Wall -Wextra -pedantic
LIB= LIB=
_DEPS= _DEPS=lib.h
DEPS=$(patsubst %,$(IDIR)/%,$(_DEPS)) DEPS=$(patsubst %,$(IDIR)/%,$(_DEPS))
_OBJ=$(NAME).o _OBJ=$(NAME).o lib.o
OBJ=$(patsubst %,$(ODIR)/%,$(_OBJ)) OBJ=$(patsubst %,$(ODIR)/%,$(_OBJ))

1
compile_flags.txt Normal file
View File

@ -0,0 +1 @@
-Iinclude

4
include/lib.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef LIB_H
#define LIB_H
void die(const char *message);
#endif

7
src/lib.c Normal file
View File

@ -0,0 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
void die(const char *message) {
perror(message);
exit(1);
}

View File

@ -1,3 +1,21 @@
int main(void) { #include <stdio.h>
#include <stdlib.h>
#include "lib.h"
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("usage: catclone <FILE>\n");
die("args");
}
FILE *fp = fopen(argv[1], "r");
if (fp == NULL) {
die("fopen");
}
fclose(fp);
return 0; return 0;
} }