From 53923bff58000761fcfa19c346727fb9eb877047 Mon Sep 17 00:00:00 2001 From: piaip Date: Thu, 15 Sep 2005 09:00:55 +0000 Subject: real main text editing. recommendation/comments are not modifiable now. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3172 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/kaede.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'mbbsd/kaede.c') 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) { -- cgit v1.2.3