Commit c4bc6778 authored by rswindell's avatar rswindell
Browse files

Enable 64-bit file length support automatically when XPDEV_LARGE_FILE_SUPPORT

is defined (for MSVC only, currently).
parent c317d9ce
......@@ -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. */
/****************************************************************************/
long DLLCALL filelength(int fd)
filelen_t DLLCALL filelength(int fd)
{
struct stat st;
......@@ -84,23 +84,8 @@ long DLLCALL filelength(int fd)
return(st.st_size);
}
/****************************************************************************/
/* Returns the length (63-bits) of the file in 'fd' */
/* or -1 if file doesn't exist. */
/* Microsoftism */
/****************************************************************************/
int64_t DLLCALL _filelengthi64(int fd)
{
struct stat st;
if(fstat(fd, &st)!=0)
return(-1);
return(st.st_size);
}
/* Sets a lock on a portion of a file */
int DLLCALL lock(int fd, long pos, long len)
int DLLCALL lock(int fd, fileoff_t pos, filelen_t len)
{
#if defined(F_SANERDLCKNO) || !defined(BSD)
struct flock alock;
......@@ -134,7 +119,7 @@ int DLLCALL lock(int fd, long pos, long len)
}
/* Removes a lock from a file record */
int DLLCALL unlock(int fd, long pos, long len)
int DLLCALL unlock(int fd, fileoff_t pos, filelen_t len)
{
#if defined(F_SANEUNLCK) || !defined(BSD)
......@@ -262,29 +247,29 @@ int DLLCALL sopen(const char *fn, int sh_access, int share, ...)
#define LK_UNLCK LK_UNLOCK
#endif
int DLLCALL lock(int file, long offset, long size)
int DLLCALL lock(int file, fileoff_t offset, filelen_t size)
{
int i;
long pos;
fileoff_t pos;
pos=tell(file);
if(offset!=pos)
lseek(file, offset, SEEK_SET);
i=_locking(file,LK_NBLCK,size);
i=_locking(file,LK_NBLCK,(long)size);
if(offset!=pos)
lseek(file, pos, SEEK_SET);
return(i);
}
int DLLCALL unlock(int file, long offset, long size)
int DLLCALL unlock(int file, fileoff_t offset, filelen_t size)
{
int i;
long pos;
fileoff_t pos;
pos=tell(file);
if(offset!=pos)
lseek(file, offset, SEEK_SET);
i=_locking(file,LK_UNLCK,size);
i=_locking(file,LK_UNLCK,(long)size);
if(offset!=pos)
lseek(file, pos, SEEK_SET);
return(i);
......
......@@ -39,6 +39,7 @@
#define _FILEWRAP_H
#include "wrapdll.h" /* DLLEXPORT and DLLCALL */
#include "gen_defs.h" /* int32_t, int64_t */
#include <sys/stat.h> /* S_IREAD and S_IWRITE (for use with sopen) */
#include <stdio.h>
......@@ -53,6 +54,16 @@
#include <fcntl.h> /* O_RDONLY, O_CREAT, etc. */
/************/
/* Typedefs */
/************/
#if defined(XPDEV_LARGE_FILE_SUPPORT)
typedef int64_t fileoff_t, filelen_t;
#else
typedef int32_t fileoff_t, filelen_t;
#endif
/**********/
/* Macros */
/**********/
......@@ -73,6 +84,16 @@
#define SH_COMPAT 0
#endif
#if defined(XPDEV_LARGE_FILE_SUPPORT)
#define lseek _lseeki64
#define tell _telli64
#define filelength _filelengthi64
#define stat _stati64
#define fstat _fstati64
#define fseek _fseeki64
#define ftell _ftelli64
#endif
#elif defined(__unix__)
#ifdef __solaris__
......@@ -115,7 +136,6 @@
#endif
#define chsize(fd,size) ftruncate(fd,size)
#define _chsize_s(fd,size) ftruncate(fd,size) /* supports 64-bit size */
#define tell(fd) lseek(fd,0,SEEK_CUR)
#define eof(fd) (tell(fd)==filelength(fd))
......@@ -149,20 +169,26 @@ extern "C" {
#endif
#if !defined(__BORLANDC__) && !defined(__WATCOMC__)
DLLEXPORT int DLLCALL lock(int fd, long pos, long len);
DLLEXPORT int DLLCALL unlock(int fd, long pos, long len);
DLLEXPORT int DLLCALL lock(int fd, fileoff_t pos, filelen_t len);
DLLEXPORT int DLLCALL unlock(int fd, fileoff_t pos, filelen_t len);
#endif
#if !defined(__BORLANDC__) && defined(__unix__)
DLLEXPORT int DLLCALL sopen(const char* fn, int sh_access, int share, ...);
DLLEXPORT long DLLCALL filelength(int fd);
DLLEXPORT int64_t DLLCALL _filelengthi64(int fd);
DLLEXPORT filelen_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
#endif
DLLEXPORT time_t DLLCALL filetime(int fd);
#if defined(__cplusplus)
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -164,14 +164,14 @@ socket_option_t* getSocketOptionList(void)
return(socket_options);
}
int sendfilesocket(int sock, int file, long *offset, long count)
int sendfilesocket(int sock, int file, fileoff_t *offset, filelen_t count)
{
char buf[1024*16];
long len;
int rd;
int wr=0;
int total=0;
int i;
char buf[1024*16];
filelen_t len;
int rd;
int wr=0;
int total=0;
int i;
/* sendfile() on Linux may or may not work with non-blocking sockets ToDo */
len=filelength(file);
......@@ -226,7 +226,7 @@ int sendfilesocket(int sock, int file, long *offset, long count)
return(total);
}
int recvfilesocket(int sock, int file, long *offset, long count)
int recvfilesocket(int sock, int file, fileoff_t *offset, filelen_t count)
{
/* Writes a file from a socket -
*
......@@ -252,7 +252,7 @@ int recvfilesocket(int sock, int file, long *offset, long count)
return(-1);
}
if((buf=(char*)alloca(count))==NULL) {
if((buf=(char*)alloca((size_t)count))==NULL) {
errno=ENOMEM;
return(-1);
}
......@@ -261,7 +261,7 @@ int recvfilesocket(int sock, int file, long *offset, long count)
if(lseek(file,*offset,SEEK_SET)<0)
return(-1);
rd=read(sock,buf,count);
rd=read(sock,buf,(size_t)count);
if(rd!=count)
return(-1);
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -39,6 +39,7 @@
#define _SOCKWRAP_H
#include "gen_defs.h" /* BOOL */
#include "filewrap.h" /* fileoff_t, filelen_t */
/***************/
/* OS-specific */
......@@ -172,8 +173,8 @@ socket_option_t*
getSocketOptionList(void);
int getSocketOptionByName(const char* name, int* level);
int sendfilesocket(int sock, int file, long *offset, long count);
int recvfilesocket(int sock, int file, long *offset, long count);
int sendfilesocket(int sock, int file, fileoff_t* offset, filelen_t count);
int recvfilesocket(int sock, int file, fileoff_t* offset, filelen_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