From 0f623548115340cf5f2d39abf9098bf27b822b68 Mon Sep 17 00:00:00 2001 From: Daniel Brahneborg Date: Fri, 8 Mar 2002 19:42:40 +0000 Subject: Added copyFromPsion() that takes a 'to' argument that is a file descriptor, to be able to use mkstemp(). --- lib/rfsv.h | 5 +++++ lib/rfsv16.cc | 27 +++++++++++++++++++++++++++ lib/rfsv16.h | 1 + lib/rfsv32.cc | 24 ++++++++++++++++++++++++ lib/rfsv32.h | 1 + 5 files changed, 58 insertions(+) diff --git a/lib/rfsv.h b/lib/rfsv.h index 58c82cb..2a445ef 100644 --- a/lib/rfsv.h +++ b/lib/rfsv.h @@ -412,6 +412,11 @@ public: */ virtual Enum copyFromPsion(const char *from, const char *to, void *, cpCallback_t func) = 0; + /** + * Copies a file from the Psion to the local machine. + */ + virtual Enum copyFromPsion(const char *from, int fd, cpCallback_t cb) = 0; + /** * Copies a file from local machine to the Psion. * diff --git a/lib/rfsv16.cc b/lib/rfsv16.cc index 15bb0aa..e920698 100644 --- a/lib/rfsv16.cc +++ b/lib/rfsv16.cc @@ -640,6 +640,33 @@ copyFromPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) return res; } +Enum rfsv16:: +copyFromPsion(const char *from, int fd, void *ptr, cpCallback_t cb) +{ + Enum res; + u_int32_t handle; + u_int32_t len; + u_int32_t total = 0; + + if ((res = fopen(P_FSHARE | P_FSTREAM, from, handle)) != E_PSI_GEN_NONE) + return res; + do { + unsigned char buf[RFSV_SENDLEN]; + if ((res = fread(handle, buf, sizeof(buf), len)) == E_PSI_GEN_NONE) { + if (len > 0) + write(fd, buf, len); + total += len; + if (cb && !cb(ptr, total)) + res = E_PSI_FILE_CANCEL; + } + } while (len > 0 && (res == E_PSI_GEN_NONE)); + + fclose(handle); + if (res == E_PSI_FILE_EOF) + res = E_PSI_GEN_NONE; + return res; +} + Enum rfsv16:: copyToPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) { diff --git a/lib/rfsv16.h b/lib/rfsv16.h index fa32e5e..dad9650 100644 --- a/lib/rfsv16.h +++ b/lib/rfsv16.h @@ -60,6 +60,7 @@ public: Enum fread(const u_int32_t, unsigned char * const, const u_int32_t, u_int32_t &); Enum fwrite(const u_int32_t, const unsigned char * const, const u_int32_t, u_int32_t &); Enum copyFromPsion(const char * const, const char * const, void *, cpCallback_t); + Enum copyFromPsion(const char *from, int fd, void *ptr, cpCallback_t cb); Enum copyToPsion(const char * const, const char * const, void *, cpCallback_t); Enum copyOnPsion(const char *, const char *, void *, cpCallback_t); Enum fsetsize(const u_int32_t, const u_int32_t); diff --git a/lib/rfsv32.cc b/lib/rfsv32.cc index 739844e..da9c6e0 100644 --- a/lib/rfsv32.cc +++ b/lib/rfsv32.cc @@ -506,6 +506,30 @@ copyFromPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) return res; } +Enum rfsv32:: +copyFromPsion(const char *from, int fd, cpCallback_t cb) +{ + Enum res; + u_int32_t handle; + u_int32_t len; + u_int32_t total = 0; + + if ((res = fopen(EPOC_OMODE_SHARE_READERS | EPOC_OMODE_BINARY, from, handle)) != E_PSI_GEN_NONE) + return res; + unsigned char *buff = new unsigned char[RFSV_SENDLEN]; + do { + if ((res = fread(handle, buff, RFSV_SENDLEN, len)) == E_PSI_GEN_NONE) { + write(fd, buff, len); + total += len; + if (cb && !cb(NULL, total)) + res = E_PSI_FILE_CANCEL; + } + } while ((len > 0) && (res == E_PSI_GEN_NONE)); + delete [] buff; + fclose(handle); + return res; +} + Enum rfsv32:: copyToPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) { diff --git a/lib/rfsv32.h b/lib/rfsv32.h index 0680354..2adf4d8 100644 --- a/lib/rfsv32.h +++ b/lib/rfsv32.h @@ -48,6 +48,7 @@ public: Enum dir(const char * const, PlpDir &); Enum dircount(const char * const, u_int32_t &); Enum copyFromPsion(const char * const, const char * const, void *, cpCallback_t); + Enum copyFromPsion(const char *from, int fd, cpCallback_t cb); Enum copyToPsion(const char * const, const char * const, void *, cpCallback_t); Enum copyOnPsion(const char * const, const char * const, void *, cpCallback_t); Enum mkdir(const char * const); -- cgit v1.2.3