Commit 37c78a5a authored by rswindell's avatar rswindell
Browse files

Use the Linux method for enabling 64-bit file size support, by defining

_FILE_OFFSET_BITS=64, and use fseeko() and ftello() for 64-bit offset support
(instead of fseek() and ftell()) - also redefine off_t on Win32 to int64_t and
removed filelen_t and fileoff_t typedefs (use off_t instead).
parent 2a33c56b
......@@ -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);
}
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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 */
......
......@@ -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);
......
......@@ -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)
......
......@@ -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);
......
......@@ -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 */
......
......@@ -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 -
*
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment