diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-09-15 17:00:55 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-09-15 17:00:55 +0800 |
commit | 53923bff58000761fcfa19c346727fb9eb877047 (patch) | |
tree | bbf758258d48059688b74719ab7569bba6519816 /mbbsd/kaede.c | |
parent | 74f24ed0c4f5309d4ff0fb896a168a11c3a6094e (diff) | |
download | pttbbs-53923bff58000761fcfa19c346727fb9eb877047.tar pttbbs-53923bff58000761fcfa19c346727fb9eb877047.tar.gz pttbbs-53923bff58000761fcfa19c346727fb9eb877047.tar.bz2 pttbbs-53923bff58000761fcfa19c346727fb9eb877047.tar.lz pttbbs-53923bff58000761fcfa19c346727fb9eb877047.tar.xz pttbbs-53923bff58000761fcfa19c346727fb9eb877047.tar.zst pttbbs-53923bff58000761fcfa19c346727fb9eb877047.zip |
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
Diffstat (limited to 'mbbsd/kaede.c')
-rw-r--r-- | mbbsd/kaede.c | 52 |
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) { |