--- sbbs/src/xpdev/filewrap.c 2018/04/24 16:41:24 1.1.1.1 +++ sbbs/src/xpdev/filewrap.c 2018/04/24 16:45:39 1.1.1.2 @@ -2,13 +2,13 @@ /* File-related system-call wrappers */ -/* $Id: filewrap.c,v 1.1.1.1 2018/04/24 16:41:24 root Exp $ */ +/* $Id: filewrap.c,v 1.1.1.2 2018/04/24 16:45:39 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2004 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 * @@ -56,6 +56,7 @@ /****************************************************************************/ /* Returns the modification time of the file in 'fd' */ +/* or -1 if file doesn't exist. */ /****************************************************************************/ time_t DLLCALL filetime(int fd) { @@ -71,8 +72,9 @@ 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) +off_t DLLCALL filelength(int fd) { struct stat st; @@ -83,7 +85,7 @@ long DLLCALL filelength(int fd) } /* Sets a lock on a portion of a file */ -int DLLCALL lock(int fd, long pos, long len) +int DLLCALL lock(int fd, off_t pos, off_t len) { #if defined(F_SANERDLCKNO) || !defined(BSD) struct flock alock; @@ -92,7 +94,7 @@ int DLLCALL lock(int fd, long pos, long int flags; if((flags=fcntl(fd,F_GETFL))==-1) return -1; - if(flags==O_RDONLY) + if((flags & (O_RDONLY|O_RDWR|O_WRONLY))==O_RDONLY) alock.l_type = F_RDLCK; /* set read lock to prevent writes */ else alock.l_type = F_WRLCK; /* set write lock to prevent all access */ @@ -117,7 +119,7 @@ int DLLCALL lock(int fd, long pos, long } /* Removes a lock from a file record */ -int DLLCALL unlock(int fd, long pos, long len) +int DLLCALL unlock(int fd, off_t pos, off_t len) { #if defined(F_SANEUNLCK) || !defined(BSD) @@ -245,29 +247,29 @@ int DLLCALL sopen(const char *fn, int sh #define LK_UNLCK LK_UNLOCK #endif -int DLLCALL lock(int file, long offset, long size) +int DLLCALL lock(int file, off_t offset, off_t size) { int i; - long pos; + off_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, off_t offset, off_t size) { int i; - long pos; + off_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); @@ -306,7 +308,7 @@ FILE *_fsopen(char *pszFilename, char *p } switch(Mode) { case 1: - Mode=O_RDONLY; + Mode =O_RDONLY; break; case 2: Mode=O_WRONLY|O_CREAT|O_TRUNC;