diff options
author | Simo Sorce <idra@samba.org> | 2002-08-27 09:07:08 +0000 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2002-08-27 09:07:08 +0000 |
commit | b275547c9ecc13bede5bd21a392fa1d695a3926d (patch) | |
tree | 661d7407a9dff72621982de882ea74c5d1642b9a /source/lib/xfile.c | |
parent | 4e142ba3749d2eb45687425ff87c153fb6147056 (diff) | |
download | samba-b275547c9ecc13bede5bd21a392fa1d695a3926d.tar.gz samba-b275547c9ecc13bede5bd21a392fa1d695a3926d.tar.xz samba-b275547c9ecc13bede5bd21a392fa1d695a3926d.zip |
add a trivial seeking function to xfile (tseek) that does not do SEEK_CUR
and add commands reget and reput to smbclient that continues a transfer that has been onterrupted.
thanks to josef Zlomek that did the original patch.
Diffstat (limited to 'source/lib/xfile.c')
-rw-r--r-- | source/lib/xfile.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/lib/xfile.c b/source/lib/xfile.c index b5710f3a39e..7621712e9ad 100644 --- a/source/lib/xfile.c +++ b/source/lib/xfile.c @@ -43,6 +43,7 @@ XFILE *x_stderr = &_x_stderr; #define X_FLAG_EOF 1 #define X_FLAG_ERROR 2 +#define X_FLAG_EINVAL 3 /* simulate setvbuf() */ int x_setvbuf(XFILE *f, char *buf, int mode, size_t size) @@ -341,3 +342,36 @@ char *x_fgets(char *s, int size, XFILE *stream) *s = 0; return s0; } + +/* trivial seek, works only for SEEK_SET and SEEK_END if SEEK_CUR is + * set then an error is returned */ +off_t x_tseek(XFILE *f, off_t offset, int whence) +{ + if (f->flags & X_FLAG_ERROR) + return -1; + + /* only SEEK_SET and SEEK_END are supported */ + /* SEEK_CUR needs internal offset counter */ + if (whence != SEEK_SET && whence != SEEK_END) { + f->flags |= X_FLAG_EINVAL; + errno = EINVAL; + return -1; + } + + /* empty the buffer */ + switch (f->open_flags & O_ACCMODE) { + case O_RDONLY: + f->bufused = 0; + break; + case O_WRONLY: + if (x_fflush(f) != 0) + return -1; + break; + default: + errno = EINVAL; + return -1; + } + + f->flags &= ~X_FLAG_EOF; + return (off_t)sys_lseek(f->fd, offset, whence); +} |