summaryrefslogtreecommitdiffstats
path: root/mbbsd/kaede.c
diff options
context:
space:
mode:
Diffstat (limited to 'mbbsd/kaede.c')
-rw-r--r--mbbsd/kaede.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/mbbsd/kaede.c b/mbbsd/kaede.c
index eef5bb03..150d13f3 100644
--- a/mbbsd/kaede.c
+++ b/mbbsd/kaede.c
@@ -104,12 +104,62 @@ Copy(const char *src, const char *dst)
if(fi<0) return -1;
fo=open(dst, O_WRONLY | O_TRUNC | O_CREAT, 0600);
if(fo<0) {close(fi); return -1;}
- while((bytes=read(fi, buf, 8192))>0)
+ while((bytes=read(fi, buf, sizeof(buf)))>0)
write(fo, buf, bytes);
close(fo);
close(fi);
return 0;
}
+
+int
+CopyN(const char *src, const char *dst, int n)
+{
+ int fi, fo, bytes;
+ char buf[8192];
+
+ fi=open(src, O_RDONLY);
+ if(fi<0) return -1;
+
+ fo=open(dst, O_WRONLY | O_TRUNC | O_CREAT, 0600);
+ if(fo<0) {close(fi); return -1;}
+
+ while(n > 0 && (bytes=read(fi, buf, sizeof(buf)))>0)
+ {
+ n -= bytes;
+ if (n < 0)
+ bytes += n;
+ write(fo, buf, bytes);
+ }
+ close(fo);
+ close(fi);
+ return 0;
+}
+
+/* append data from tail of src (starting point=off) to dst */
+int
+AppendTail(const char *src, const char *dst, int off)
+{
+ int fi, fo, bytes;
+ char buf[8192];
+
+ fi=open(src, O_RDONLY);
+ if(fi<0) return -1;
+
+ fo=open(dst, O_WRONLY | O_APPEND | O_CREAT, 0600);
+ if(fo<0) {close(fi); return -1;}
+
+ if(off > 0)
+ lseek(fi, (off_t)off, SEEK_SET);
+
+ while((bytes=read(fi, buf, sizeof(buf)))>0)
+ {
+ write(fo, buf, bytes);
+ }
+ close(fo);
+ close(fi);
+ return 0;
+}
+
int
Link(const char *src, const char *dst)
{