From: Armaan Bhojwani Date: Tue, 6 Apr 2021 22:37:27 +0000 (-0400) Subject: Fix cp function location X-Git-Url: https://git.armaanb.net/?p=stagit.git;a=commitdiff_plain;h=bc8b31877878996129dd78b6b2ae9c2f5d2d1486 Fix cp function location --- diff --git a/Makefile b/Makefile index 1277cb7..0681a85 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,8 @@ SRC = \ COMPATSRC = \ src/reallocarray.c\ src/strlcat.c\ - src/strlcpy.c + src/strlcpy.c\ + src/cp.c BIN = \ stagit\ stagit-index @@ -49,7 +50,8 @@ HDR = src/compat.h COMPATOBJ = \ src/reallocarray.o\ src/strlcat.o\ - src/strlcpy.o + src/strlcpy.o\ + src/cp.o OBJ = ${SRC:.c=.o} ${COMPATOBJ} diff --git a/src/cp.c b/src/cp.c new file mode 100644 index 0000000..92daf2f --- /dev/null +++ b/src/cp.c @@ -0,0 +1,25 @@ +#include +#include + +int +cp(const char fileSource[], const char fileDestination[]) +{ + int c; + FILE *stream_R, *stream_W; + + stream_R = fopen(fileSource, "r"); + if (stream_R == NULL) + return -1; + stream_W = fopen(fileDestination, "w"); //create and write to file + if (stream_W == NULL) + { + fclose(stream_R); + return -2; + } + while ((c = fgetc(stream_R)) != EOF) + fputc(c, stream_W); + fclose(stream_R); + fclose(stream_W); + + return 0; +} diff --git a/src/cp.h b/src/cp.h index 876b21e..8404fa7 100644 --- a/src/cp.h +++ b/src/cp.h @@ -1 +1 @@ -int cp(const char fileSource[], const char fileDestination[]); +extern int cp(const char fileSource[], const char fileDestination[]); diff --git a/src/stagit.c b/src/stagit.c index eef927e..1243668 100644 --- a/src/stagit.c +++ b/src/stagit.c @@ -19,8 +19,8 @@ #include #endif -#include "cp.h" #include "compat.h" +#include "cp.h" struct deltainfo { git_patch *patch; @@ -78,29 +78,6 @@ static char lastoidstr[GIT_OID_HEXSZ + 2]; /* id + newline + NUL byte */ static FILE *rcachefp, *wcachefp; static const char *cachefile; -int -cp(const char fileSource[], const char fileDestination[]) -{ - int c; - FILE *stream_R, *stream_W; - - stream_R = fopen(fileSource, "r"); - if (stream_R == NULL) - return -1; - stream_W = fopen(fileDestination, "w"); //create and write to file - if (stream_W == NULL) - { - fclose(stream_R); - return -2; - } - while ((c = fgetc(stream_R)) != EOF) - fputc(c, stream_W); - fclose(stream_R); - fclose(stream_W); - - return 0; -} - void joinpath(char *buf, size_t bufsiz, const char *path, const char *path2) {