stagit

Personal stagit fork
git clone git://git.alexwennerberg.com/stagit
Log | Files | Refs | README | LICENSE

commit bc8b31877878996129dd78b6b2ae9c2f5d2d1486
parent 8b5e07f7ed45ce24d40a961902d70e939d4f6d56
Author: Armaan Bhojwani <me@armaanb.net>
Date:   Tue,  6 Apr 2021 18:37:27 -0400

Fix cp function location

Diffstat:
MMakefile | 6++++--
Asrc/cp.c | 25+++++++++++++++++++++++++
Msrc/cp.h | 2+-
Msrc/stagit.c | 25+------------------------
4 files changed, 31 insertions(+), 27 deletions(-)

diff --git 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 @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <stddef.h> + +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 @@ -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 @@ -19,8 +19,8 @@ #include <cmark-gfm.h> #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) {