]> git.armaanb.net Git - stagit.git/commitdiff
Fix cp function location
authorArmaan Bhojwani <me@armaanb.net>
Tue, 6 Apr 2021 22:37:27 +0000 (18:37 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Tue, 6 Apr 2021 22:37:27 +0000 (18:37 -0400)
Makefile
src/cp.c [new file with mode: 0644]
src/cp.h
src/stagit.c

index 1277cb7f795914d7c8cb1e3d9ea6fd0427758cf5..0681a85682a4f6c306bb6a8199748561bd1991b9 100644 (file)
--- 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 (file)
index 0000000..92daf2f
--- /dev/null
+++ 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;
+}
index 876b21eda23cc47bd0d02305376fb5781d0e0398..8404fa7da1621d91da168d6626dd3a7cc09c2fbb 100644 (file)
--- 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[]);
index eef927ea8ded24b6dc5ca59fb3fa181adb4b66f4..124366811647e1aa0d9aa549f7985e44dabb841a 100644 (file)
@@ -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)
 {