diff --git a/src/sbbs3/sexyz.c b/src/sbbs3/sexyz.c index 900b4d72e764028d491e1ffde1154e30d580ab9f..3b98b5cd2c091bdf4fe80cf2f1f422ede0c2a9f3 100644 --- a/src/sbbs3/sexyz.c +++ b/src/sbbs3/sexyz.c @@ -1260,7 +1260,7 @@ static int receive_files(char** fname_list, int fnames) block_num=1; xmodem_put_nak(&xm, block_num); while(is_connected(NULL)) { - fileoff_t pos=ftell(fp); + off_t pos=ftello(fp); if(max_file_size!=0 && pos>=max_file_size) { lprintf(LOG_WARNING,"Specified maximum file size (%"PRIu64" bytes) reached at offset %"PRIu64 ,max_file_size, pos); @@ -1307,7 +1307,7 @@ static int receive_files(char** fname_list, int fnames) wr=(uint)file_bytes_left; if(fwrite(block,1,wr,fp)!=wr) { lprintf(LOG_ERR,"ERROR %d writing %u bytes at file offset %"PRIu64 - ,errno, wr, (uint64_t)ftell(fp)); + ,errno, wr, (uint64_t)ftello(fp)); xmodem_cancel(&xm); return(1); } diff --git a/src/sbbs3/xmodem.c b/src/sbbs3/xmodem.c index d922e1bbdcb5fb452cf47b95561ebca141a13e21..6cce894dc6879965ca53e7e60809ab89a275e370 100644 --- a/src/sbbs3/xmodem.c +++ b/src/sbbs3/xmodem.c @@ -549,7 +549,7 @@ BOOL xmodem_send_file(xmodem_t* xm, const char* fname, FILE* fp, time_t* start, xm->errors=0; while(sent_bytes < st.st_size && xm->errors<=xm->max_errors && !is_cancelled(xm) && is_connected(xm)) { - fseek(fp,(fileoff_t)sent_bytes,SEEK_SET); + fseeko(fp,(off_t)sent_bytes,SEEK_SET); memset(block,CPMEOF,xm->block_size); if(!sent_header) { if(xm->block_size>XMODEM_MIN_BLOCK_SIZE) { @@ -564,17 +564,17 @@ BOOL xmodem_send_file(xmodem_t* xm, const char* fname, FILE* fp, time_t* start, if((rd=fread(block,1,xm->block_size,fp))!=xm->block_size && (sent_bytes + rd) != st.st_size) { lprintf(xm,LOG_ERR,"ERROR %d reading %u bytes at file offset %"PRIu64 - ,errno,xm->block_size,(uint64_t)ftell(fp)); + ,errno,xm->block_size,(uint64_t)ftello(fp)); xm->errors++; continue; } if(xm->progress!=NULL) - xm->progress(xm->cbdata,block_num,ftell(fp),st.st_size,startfile); + xm->progress(xm->cbdata,block_num,ftello(fp),st.st_size,startfile); xmodem_put_block(xm, block, xm->block_size, block_num); if(xmodem_get_ack(xm, /* tries: */5,block_num) != ACK) { xm->errors++; lprintf(xm,LOG_WARNING,"Block %u: Error #%d at offset %"PRIu64 - ,block_num, xm->errors,ftell(fp)-xm->block_size); + ,block_num, xm->errors,ftello(fp)-xm->block_size); if(xm->errors==3 && block_num==1 && xm->block_size>XMODEM_MIN_BLOCK_SIZE) { lprintf(xm,LOG_NOTICE,"Block %u: Falling back to 128-byte blocks", block_num); xm->block_size=XMODEM_MIN_BLOCK_SIZE; diff --git a/src/sbbs3/zmodem.c b/src/sbbs3/zmodem.c index a304b882ae44cadc8091ce2a449c7d46acb6e784..8158407990a560ac467ce10f6f7a0ec7530c42e5 100644 --- a/src/sbbs3/zmodem.c +++ b/src/sbbs3/zmodem.c @@ -1481,7 +1481,7 @@ int zmodem_send_from(zmodem_t* zm, FILE* fp, uint64_t pos, uint64_t* sent) if(sent!=NULL) *sent=0; - if(fseek(fp,(fileoff_t)pos,SEEK_SET)!=0) { + if(fseeko(fp,(off_t)pos,SEEK_SET)!=0) { lprintf(zm,LOG_ERR,"ERROR %d seeking to file offset %"PRIu64 ,errno, pos); zmodem_send_pos_header(zm, ZFERR, (uint32_t)pos, /* Hex? */ TRUE); @@ -1503,7 +1503,7 @@ int zmodem_send_from(zmodem_t* zm, FILE* fp, uint64_t pos, uint64_t* sent) n = fread(zm->tx_data_subpacket,sizeof(BYTE),zm->block_size,fp); if(zm->progress!=NULL) - zm->progress(zm->cbdata, ftell(fp)); + zm->progress(zm->cbdata, ftello(fp)); type = ZCRCW; @@ -2115,12 +2115,12 @@ unsigned zmodem_recv_file_data(zmodem_t* zm, FILE* fp, int64_t offset) { int type=0; unsigned errors=0; - fileoff_t pos; + off_t pos; zm->transfer_start_pos=offset; zm->transfer_start_time=time(NULL); - if(fseek(fp,(fileoff_t)offset,SEEK_SET)!=0) { + if(fseeko(fp,(off_t)offset,SEEK_SET)!=0) { lprintf(zm,LOG_ERR,"ERROR %d seeking to file offset %"PRIu64 ,errno, offset); zmodem_send_pos_header(zm, ZFERR, (uint32_t)offset, /* Hex? */ TRUE); @@ -2138,7 +2138,7 @@ unsigned zmodem_recv_file_data(zmodem_t* zm, FILE* fp, int64_t offset) */ while(errors<=zm->max_errors && is_connected(zm) && !is_cancelled(zm)) { - if((pos=ftell(fp)) > zm->current_file_size) + if((pos=ftello(fp)) > zm->current_file_size) zm->current_file_size = pos; if(zm->max_file_size!=0 && pos >= zm->max_file_size) { @@ -2155,10 +2155,10 @@ unsigned zmodem_recv_file_data(zmodem_t* zm, FILE* fp, int64_t offset) if(type == ZEOF || type == ZFIN) break; if(type==ENDOFFRAME) - lprintf(zm,LOG_DEBUG,"Received complete frame at offset: %lu", (ulong)ftell(fp)); + lprintf(zm,LOG_DEBUG,"Received complete frame at offset: %lu", (ulong)ftello(fp)); else { if(type>0 && !zm->local_abort) - lprintf(zm,LOG_ERR,"Received %s at offset: %lu", chr(type), (ulong)ftell(fp)); + lprintf(zm,LOG_ERR,"Received %s at offset: %lu", chr(type), (ulong)ftello(fp)); errors++; } } @@ -2194,7 +2194,7 @@ int zmodem_recv_file_frame(zmodem_t* zm, FILE* fp) If the receiver has not received all the bytes of the file, the receiver ignores the ZEOF because a new ZDATA is coming. */ - if(zm->rxd_header_pos==(uint32_t)ftell(fp)) + if(zm->rxd_header_pos==(uint32_t)ftello(fp)) return type; lprintf(zm,LOG_WARNING,"Ignoring ZEOF as all bytes (%lu) have not been received" ,zm->rxd_header_pos); @@ -2212,9 +2212,9 @@ int zmodem_recv_file_frame(zmodem_t* zm, FILE* fp) lprintf(zm,LOG_WARNING,"Received %s instead of ZDATA frame", frame_desc(type)); } - if(zm->rxd_header_pos!=(uint32_t)ftell(fp)) { + if(zm->rxd_header_pos!=(uint32_t)ftello(fp)) { lprintf(zm,LOG_WARNING,"Received wrong ZDATA frame (%lu vs %lu)" - ,zm->rxd_header_pos, (ulong)ftell(fp)); + ,zm->rxd_header_pos, (ulong)ftello(fp)); return FALSE; } @@ -2226,8 +2226,8 @@ int zmodem_recv_file_frame(zmodem_t* zm, FILE* fp) if (type == ENDOFFRAME || type == FRAMEOK) { if(fwrite(zm->rx_data_subpacket,1,n,fp)!=n) { lprintf(zm,LOG_ERR,"ERROR %d writing %u bytes at file offset %"PRIu64 - ,errno, n,(uint64_t)ftell(fp)); - zmodem_send_pos_header(zm, ZFERR, (uint32_t)ftell(fp), /* Hex? */ TRUE); + ,errno, n,(uint64_t)ftello(fp)); + zmodem_send_pos_header(zm, ZFERR, (uint32_t)ftello(fp), /* Hex? */ TRUE); return FALSE; } } @@ -2236,7 +2236,7 @@ int zmodem_recv_file_frame(zmodem_t* zm, FILE* fp) zm->block_size = n; if(zm->progress!=NULL) - zm->progress(zm->cbdata, ftell(fp)); + zm->progress(zm->cbdata, ftello(fp)); if(is_cancelled(zm)) return(ZCAN); diff --git a/src/syncterm/term.c b/src/syncterm/term.c index 5ef359e76e9d55f6ce602eef81259072e79378f5..f0d180a76d70db3d2fe9761399dfeff8beaf8792 100644 --- a/src/syncterm/term.c +++ b/src/syncterm/term.c @@ -1683,7 +1683,7 @@ void xmodem_download(struct bbslist *bbs, long mode, char *path) if(i!=NOT_YMODEM) xmodem_put_nak(&xm, block_num); while(is_connected(NULL)) { - xmodem_progress(&xm,block_num,ftell(fp),file_bytes,startfile); + xmodem_progress(&xm,block_num,ftello(fp),file_bytes,startfile); if(xm.is_cancelled(&xm)) { lprintf(LOG_WARNING,"Cancelled locally"); xmodem_cancel(&xm); @@ -1732,8 +1732,8 @@ void xmodem_download(struct bbslist *bbs, long mode, char *path) if(wr>(uint)file_bytes_left) wr=(uint)file_bytes_left; if(fwrite(block,1,wr,fp)!=wr) { - lprintf(LOG_ERR,"Error writing %u bytes to file at offset %lu" - ,wr,(ulong)ftell(fp)); + lprintf(LOG_ERR,"Error writing %u bytes to file at offset %"PRId64 + ,wr,(int64_t)ftello(fp)); xmodem_cancel(&xm); goto end; } diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c index c15c970c31b88132cc42dfc73c6599f8a8970bd3..6ccc896424b4436fec24642d4f6a2024774841ae 100644 --- a/src/xpdev/dirwrap.c +++ b/src/xpdev/dirwrap.c @@ -84,7 +84,6 @@ #include "genwrap.h" /* strupr/strlwr */ #include "dirwrap.h" /* DLLCALL */ -#include "filewrap.h" /* LARGE_FILE_SUPPORT */ /****************************************************************************/ /* Return the filename portion of a full pathname */ @@ -391,7 +390,7 @@ int DLLCALL setfdate(const char* filename, time_t t) /* Returns the length of the file in 'filename' */ /* or -1 if the file doesn't exist */ /****************************************************************************/ -filelen_t DLLCALL flength(const char *filename) +off_t DLLCALL flength(const char *filename) { #if defined(__BORLANDC__) && !defined(__unix__) /* stat() doesn't work right */ diff --git a/src/xpdev/dirwrap.h b/src/xpdev/dirwrap.h index 5dae2dde1da40d84a657d52d3cd3a1f56e6ffa56..0af68d91c05af8df264874e61fd0e416387359dc 100644 --- a/src/xpdev/dirwrap.h +++ b/src/xpdev/dirwrap.h @@ -218,7 +218,7 @@ extern "C" { /* General file system wrappers for all platforms and compilers */ DLLEXPORT BOOL DLLCALL fexist(const char *filespec); DLLEXPORT BOOL DLLCALL fexistcase(char *filespec); /* fixes upr/lwr case fname */ -DLLEXPORT filelen_t DLLCALL flength(const char *filename); +DLLEXPORT off_t DLLCALL flength(const char *filename); DLLEXPORT time_t DLLCALL fdate(const char *filename); DLLEXPORT int DLLCALL setfdate(const char* filename, time_t t); DLLEXPORT BOOL DLLCALL isdir(const char *filename); diff --git a/src/xpdev/filewrap.c b/src/xpdev/filewrap.c index 08d4d120eb5e4e4ce67969a8e5e60a7aded0420d..e0e95d457d98d8a2b853a6594f830cb30444c5bd 100644 --- a/src/xpdev/filewrap.c +++ b/src/xpdev/filewrap.c @@ -74,7 +74,7 @@ time_t DLLCALL filetime(int fd) /* Returns the length of the file in 'fd' */ /* or -1 if file doesn't exist. */ /****************************************************************************/ -filelen_t DLLCALL filelength(int fd) +off_t DLLCALL filelength(int fd) { struct stat st; @@ -85,7 +85,7 @@ filelen_t DLLCALL filelength(int fd) } /* Sets a lock on a portion of a file */ -int DLLCALL lock(int fd, fileoff_t pos, filelen_t len) +int DLLCALL lock(int fd, off_t pos, off_t len) { #if defined(F_SANERDLCKNO) || !defined(BSD) struct flock alock; @@ -119,7 +119,7 @@ int DLLCALL lock(int fd, fileoff_t pos, filelen_t len) } /* Removes a lock from a file record */ -int DLLCALL unlock(int fd, fileoff_t pos, filelen_t len) +int DLLCALL unlock(int fd, off_t pos, off_t len) { #if defined(F_SANEUNLCK) || !defined(BSD) @@ -247,10 +247,10 @@ int DLLCALL sopen(const char *fn, int sh_access, int share, ...) #define LK_UNLCK LK_UNLOCK #endif -int DLLCALL lock(int file, fileoff_t offset, filelen_t size) +int DLLCALL lock(int file, off_t offset, off_t size) { int i; - fileoff_t pos; + off_t pos; pos=tell(file); if(offset!=pos) @@ -261,10 +261,10 @@ int DLLCALL lock(int file, fileoff_t offset, filelen_t size) return(i); } -int DLLCALL unlock(int file, fileoff_t offset, filelen_t size) +int DLLCALL unlock(int file, off_t offset, off_t size) { int i; - fileoff_t pos; + off_t pos; pos=tell(file); if(offset!=pos) diff --git a/src/xpdev/filewrap.h b/src/xpdev/filewrap.h index 982736e246e2b74c04cb95978b306a646acb84a2..f64dd89a55d67598c855134faaa5bbc0e44cdbef 100644 --- a/src/xpdev/filewrap.h +++ b/src/xpdev/filewrap.h @@ -74,14 +74,17 @@ #define SH_COMPAT 0 #endif - #if defined(XPDEV_LARGE_FILE_SUPPORT) + #if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS==64) #define lseek _lseeki64 #define tell _telli64 #define filelength _filelengthi64 #define stat _stati64 #define fstat _fstati64 - #define fseek _fseeki64 - #define ftell _ftelli64 + #define fseeko _fseeki64 + #define ftello _ftelli64 + #else + #define fseeko fseek + #define ftello ftell #endif #elif defined(__unix__) @@ -159,24 +162,22 @@ extern "C" { #endif #if !defined(__BORLANDC__) && !defined(__WATCOMC__) - DLLEXPORT int DLLCALL lock(int fd, fileoff_t pos, filelen_t len); - DLLEXPORT int DLLCALL unlock(int fd, fileoff_t pos, filelen_t len); + DLLEXPORT int DLLCALL lock(int fd, off_t pos, off_t len); + DLLEXPORT int DLLCALL unlock(int fd, off_t pos, off_t len); #endif #if !defined(__BORLANDC__) && defined(__unix__) DLLEXPORT int DLLCALL sopen(const char* fn, int sh_access, int share, ...); - DLLEXPORT filelen_t DLLCALL filelength(int fd); + DLLEXPORT off_t DLLCALL filelength(int fd); #endif #if defined(__unix__) DLLEXPORT FILE * DLLCALL _fsopen(char *pszFilename, char *pszMode, int shmode); #endif -#if defined(_WIN32) && defined(XPDEV_LARGE_FILE_SUPPORT) -#if _MSC_VER < 1300 - DLLEXPORT int DLLCALL _fseeki64(FILE*, fileoff_t, int origin); - DLLEXPORT fileoff_t DLLCALL _ftelli64(FILE*); -#endif +#if _MSC_VER < 1300 /* missing prototypes */ + DLLEXPORT int DLLCALL _fseeki64(FILE*, int64_t, int origin); + DLLEXPORT int64_t DLLCALL _ftelli64(FILE*); #endif DLLEXPORT time_t DLLCALL filetime(int fd); diff --git a/src/xpdev/gen_defs.h b/src/xpdev/gen_defs.h index b408bcd94b745cee466de9c162ac5e9d4a47f4ec..9b49fffa1d0f8c6872526af564cd823fd2f479ec 100644 --- a/src/xpdev/gen_defs.h +++ b/src/xpdev/gen_defs.h @@ -174,10 +174,8 @@ typedef unsigned long long int uint64_t; /* Legacy 32-bit time_t */ typedef int32_t time32_t; -#if defined(XPDEV_LARGE_FILE_SUPPORT) -typedef int64_t fileoff_t, filelen_t; -#else -typedef long fileoff_t, filelen_t; +#if defined(_WIN32) && defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS==64) +#define off_t int64_t #endif /* Windows Types */ diff --git a/src/xpdev/sockwrap.c b/src/xpdev/sockwrap.c index 03aee13b00f53e8464d53eff87ddb74bf8b5cb4e..6197e7744044ed04902201d224843c38fcec1442 100644 --- a/src/xpdev/sockwrap.c +++ b/src/xpdev/sockwrap.c @@ -164,10 +164,10 @@ socket_option_t* getSocketOptionList(void) return(socket_options); } -int sendfilesocket(int sock, int file, fileoff_t *offset, filelen_t count) +int sendfilesocket(int sock, int file, off_t *offset, off_t count) { char buf[1024*16]; - filelen_t len; + off_t len; int rd; int wr=0; int total=0; @@ -226,7 +226,7 @@ int sendfilesocket(int sock, int file, fileoff_t *offset, filelen_t count) return(total); } -int recvfilesocket(int sock, int file, fileoff_t *offset, filelen_t count) +int recvfilesocket(int sock, int file, off_t *offset, off_t count) { /* Writes a file from a socket - * diff --git a/src/xpdev/sockwrap.h b/src/xpdev/sockwrap.h index 6e56392a07ae8be0b9c8c8bd04b32fe0e2486cea..08ac020e9dd5f09b79f3a8b1a5a55f3596654603 100644 --- a/src/xpdev/sockwrap.h +++ b/src/xpdev/sockwrap.h @@ -39,7 +39,6 @@ #define _SOCKWRAP_H #include "gen_defs.h" /* BOOL */ -#include "filewrap.h" /* fileoff_t, filelen_t */ /***************/ /* OS-specific */ @@ -173,8 +172,8 @@ socket_option_t* getSocketOptionList(void); int getSocketOptionByName(const char* name, int* level); -int sendfilesocket(int sock, int file, fileoff_t* offset, filelen_t count); -int recvfilesocket(int sock, int file, fileoff_t* offset, filelen_t count); +int sendfilesocket(int sock, int file, off_t* offset, off_t count); +int recvfilesocket(int sock, int file, off_t* offset, off_t count); BOOL socket_check(SOCKET sock, BOOL* rd_p, BOOL* wr_p, DWORD timeout); int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen ,uint retries, uint wait_secs, const char* prot