From c5366a33da1202d0814bfc0c1d7123b33e4a0303 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 6 Jul 2015 02:04:28 +0200 Subject: [PATCH] fsendfile(): Break ABI by switching src and dst to match rest of API. Signed-off-by: Joachim Nilsson --- README.md | 17 +++++++++++++++++ fsendfile.c | 6 +++--- lite.h | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b2e87aa..bed2322 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,11 @@ Generic Functions names: files and directories that must be freed after use. See the unit test at the bottom for an example. +- `fcopyfile(src, dst)` + + Like `copyfile()` but uses already open `FILE *` pointers. Copies + from current file positions to current file positions until EOF. + - `fexist(file)` Check for the existance of a file, returns True(1) or False(0). @@ -75,6 +80,18 @@ Generic Functions Returns the `mode_t` bits of a file or directory. +- `fsendfile(src, dst, len)` + + Copy data between file streams, very similar to `fcopyfile()`, but + `dst` is allowed to be `NULL` to be able to read and discard `len` + bytes from `src`. + +- `movefile(src, dst)` + + Like `copyfile()`, but renames `src` to `dst`, or recreates symlink + with the `dst` name. On successful operation the source is removed + and the function returns POSIX OK (0). + - `rsync(src, dst, delete, *filter())` Very simple `rsync()` to copy files files and directories diff --git a/fsendfile.c b/fsendfile.c index 7deb892..80bdf8f 100644 --- a/fsendfile.c +++ b/fsendfile.c @@ -28,8 +28,8 @@ /** * fsendfile - copy data between file streams - * @dst: Destination stream * @src: Source stream + * @dst: Destination stream * @len: Number of bytes to copy * * @dst may be %NULL, in which case @len bytes are read and discarded @@ -41,7 +41,7 @@ * The number of bytes copied. If an error is detected -1 is returned * and @errno will be set accordingly. */ -size_t fsendfile(FILE *dst, FILE *src, size_t len) +size_t fsendfile(FILE *src, FILE *dst, size_t len) { char *buf; size_t blk = BUFSIZ, num = 0, tot = 0; @@ -94,7 +94,7 @@ int main(void) src = fopen(files[i], "r"); dst = fopen(files[i + 1], "w"); fprintf(stderr, "fsendfile(%s, %s, 512)\t", files[i], files[i + 1]); - if (-1 == fsendfile(dst, src, 512)) + if (-1 == fsendfile(src, dst, 512)) perror("Failed"); if (!access(files[i + 1], F_OK)) diff --git a/lite.h b/lite.h index fbcc281..dc648ab 100644 --- a/lite.h +++ b/lite.h @@ -43,7 +43,7 @@ FILE *tempfile (void); ssize_t copyfile (char *src, char *dst, int len, int sym); int movefile (char *src, char *dst); int fcopyfile (FILE *src, FILE *dst); -size_t fsendfile (FILE *out, FILE *in, size_t sz); +size_t fsendfile (FILE *src, FILE *dst, size_t len); int dir (const char *dir, const char *type, int (*filter) (const char *file), char ***list, int strip); int rsync (char *src, char *dst, int delete, int (*filter) (const char *file));