Thread: [Libsysio-commit] HEAD: libsysio/src lseek.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2003-10-29 00:10:48
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1:/tmp/cvs-serv12663/src Modified Files: lseek.c Log Message: Add prototype for lseek and fix bug in _sysio_lseek (from Wally Wang) that makes the temporary offset a _SYSIO_OFF_T instead of off_t. Index: lseek.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/lseek.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -w -b -B -p -r1.8 -r1.9 --- lseek.c 10 Oct 2003 18:50:31 -0000 1.8 +++ lseek.c 29 Oct 2003 00:10:42 -0000 1.9 @@ -58,7 +58,7 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset { int err; struct file *fil; - off_t off = 0; + _SYSIO_OFF_T off = 0; struct intnl_stat stbuf; err = 0; |
From: Lee W. <lw...@us...> - 2004-03-18 14:43:56
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13944 Modified Files: lseek.c Log Message: Lseek backwards was broken -- from Ruth Klundt and the Sandia CTH team. Fixed now. Index: lseek.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/lseek.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -w -b -B -p -r1.13 -r1.14 --- lseek.c 14 Feb 2004 19:42:59 -0000 1.13 +++ lseek.c 18 Mar 2004 14:34:18 -0000 1.14 @@ -91,8 +91,8 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset return -EINVAL; } pos = off + offset; - if ((offset < 0 && -offset > off) || - (off && offset && pos <= off)) + if ((offset < 0 && -offset >= off) || + (offset > 0 && pos <= off)) return -EINVAL; #ifdef O_LARGEFILE if (pos >= ((fil->f_flags & O_LARGEFILE) ? _SYSIO_OFF_T_MAX : LONG_MAX)) |
From: Ruth K. <rk...@us...> - 2004-04-27 22:40:32
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26597 Modified Files: lseek.c Log Message: fix swapped value in lseek return Index: lseek.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/lseek.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -w -b -B -p -r1.16 -r1.17 --- lseek.c 27 Apr 2004 22:10:55 -0000 1.16 +++ lseek.c 27 Apr 2004 22:40:20 -0000 1.17 @@ -107,10 +107,9 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset #endif pos = (fil->f_ino->i_ops.inop_pos)(fil->f_ino, pos); if (pos < 0) - return pos; + SYSIO_INTERFACE_RETURN(pos, pos); fil->f_pos = pos; - - SYSIO_INTERFACE_RETURN(pos, -1); + SYSIO_INTERFACE_RETURN(pos, 0); } #if _LARGEFILE64_SOURCE |
From: Lee W. <lw...@us...> - 2004-06-04 14:13:37
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20569/src Modified Files: lseek.c Log Message: From Eric Mei; lseek(fd, -64K, SEEK_END) fails if file size is 64K. Fixed a fence-post calculation in the offset check in _sysio_lseek. Index: lseek.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/lseek.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -w -b -B -p -r1.19 -r1.20 --- lseek.c 30 Apr 2004 19:24:46 -0000 1.19 +++ lseek.c 4 Jun 2004 14:13:27 -0000 1.20 @@ -94,7 +94,7 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset return -EINVAL; } pos = off + offset; - if ((offset < 0 && -offset >= off) || (offset > 0 && pos <= off)) + if ((offset < 0 && -offset > off) || (offset > 0 && pos <= off)) SYSIO_INTERFACE_RETURN((off_t )-1, -EINVAL); #ifdef O_LARGEFILE |
From: Lee W. <lw...@us...> - 2004-06-24 12:32:58
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4076 Modified Files: lseek.c Log Message: From Kevin Pedretti; Legacy return. Uses the interface-return macro now. Index: lseek.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/lseek.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -w -b -B -p -r1.20 -r1.21 --- lseek.c 4 Jun 2004 14:13:27 -0000 1.20 +++ lseek.c 24 Jun 2004 12:32:50 -0000 1.21 @@ -91,7 +91,7 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset off = stbuf.st_size; break; default: - return -EINVAL; + SYSIO_INTERFACE_RETURN((off_t )-1, -EINVAL); } pos = off + offset; if ((offset < 0 && -offset > off) || (offset > 0 && pos <= off)) |
From: Lee W. <lw...@us...> - 2004-08-09 15:30:28
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20858 Modified Files: lseek.c Log Message: Cray SPR_729670: lseek is not checking whence arg. Returns errno 1 instead of errno 22. _sysio_lseek is an internal function but was crafted as an external. It returned API compliant return and set errno accordingly. All callers, though, expected errno or return value. Fixed. Index: lseek.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/lseek.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -w -b -B -p -r1.23 -r1.24 --- lseek.c 27 Jul 2004 15:00:48 -0000 1.23 +++ lseek.c 9 Aug 2004 15:30:06 -0000 1.24 @@ -60,9 +60,7 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset struct file *fil; _SYSIO_OFF_T off, pos; struct intnl_stat stbuf; - SYSIO_INTERFACE_DISPLAY_BLOCK; - SYSIO_INTERFACE_ENTER; fil = _sysio_fd_find(fd); if (!fil) return -EBADF; @@ -85,42 +83,58 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset fil->f_ino, &stbuf); if (err) - SYSIO_INTERFACE_RETURN((off_t )-1, (int )err); + return err; } off = stbuf.st_size; break; default: - SYSIO_INTERFACE_RETURN((off_t )-1, -EINVAL); + return -EINVAL; } pos = off + offset; if ((offset < 0 && -offset > off) || (offset > 0 && pos <= off)) - SYSIO_INTERFACE_RETURN((off_t )-1, -EINVAL); + return -EINVAL; #ifdef O_LARGEFILE if (pos >= ((fil->f_flags & O_LARGEFILE) ? _SYSIO_OFF_T_MAX : LONG_MAX)) - SYSIO_INTERFACE_RETURN((off_t )-1, -EOVERFLOW); + return -EOVERFLOW; #else if (pos >= _SYSIO_OFF_T_MAX) - SYSIO_INTERFACE_RETURN((off_t )-1, -EOVERFLOW); + return -EOVERFLOW; #endif pos = (fil->f_ino->i_ops.inop_pos)(fil->f_ino, pos); if (pos < 0) - SYSIO_INTERFACE_RETURN((off_t )-1, (int )pos); + return pos; fil->f_pos = pos; - SYSIO_INTERFACE_RETURN((off_t )pos, 0); + return pos; } #if _LARGEFILE64_SOURCE #undef lseek64 -sysio_sym_weak_alias(_sysio_lseek, SYSIO_INTERFACE_NAME(lseek64)) + +extern off64_t +SYSIO_INTERFACE_NAME(lseek64)(int fd, off64_t offset, int whence) +{ + _SYSIO_OFF_T off; + off_t rtn; + SYSIO_INTERFACE_DISPLAY_BLOCK; + + SYSIO_INTERFACE_ENTER; + off = _sysio_lseek(fd, offset, whence); + if (off < 0) + SYSIO_INTERFACE_RETURN((off_t )-1, (int )off); + rtn = (off64_t )off; + assert(rtn == off); + SYSIO_INTERFACE_RETURN(rtn, 0); +} #ifdef __GLIBC__ #undef __lseek64 -sysio_sym_weak_alias(_sysio_lseek, PREPEND(__, SYSIO_INTERFACE_NAME(lseek64))) +sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(lseek64), + PREPEND(__, SYSIO_INTERFACE_NAME(lseek64))) #endif #ifdef REDSTORM #undef __libc_lseek64 -sysio_sym_weak_alias(_sysio_lseek, +sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(lseek64), PREPEND(__, SYSIO_INTERFACE_NAME(libc_lseek64))) #endif #endif |
From: Lee W. <lw...@us...> - 2005-08-02 21:57:24
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv468/src Modified Files: lseek.c Log Message: Changes to support better detection of overflow in 32/64 mixed compiles. Index: lseek.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/lseek.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -w -b -B -p -r1.25 -r1.26 --- lseek.c 14 Oct 2004 14:59:29 -0000 1.25 +++ lseek.c 2 Aug 2005 21:57:09 -0000 1.26 @@ -46,6 +46,7 @@ #include <assert.h> #include <sys/types.h> #include <sys/stat.h> +#include <fcntl.h> #include <sys/queue.h> #include "sysio.h" @@ -54,17 +55,31 @@ #include "sysio-symbols.h" +/* + * Test whether large file support on this file. + */ +#ifdef O_LARGEFILE +#define _SEEK_MAX_TEST(fil) \ + ((fil)->f_flags & O_LARGEFILE) +#else +#define _SEEK_MAX_TEST(fil) \ + (1) +#endif +/* + * Return max seek value for this file. + */ +#define _SEEK_MAX(fil) \ + (_SEEK_MAX_TEST(fil) ? _SYSIO_OFF_T_MAX : LONG_MAX) + static _SYSIO_OFF_T -_sysio_lseek(int fd, _SYSIO_OFF_T offset, int whence) +_sysio_lseek(struct file *fil, + _SYSIO_OFF_T offset, + int whence, + _SYSIO_OFF_T max) { - struct file *fil; _SYSIO_OFF_T off, pos; struct intnl_stat stbuf; - fil = _sysio_fd_find(fd); - if (!fil) - return -EBADF; - off = -1; switch (whence) { @@ -99,14 +114,8 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset pos = off + offset; if ((offset < 0 && -offset > off) || (offset > 0 && pos <= off)) return -EINVAL; - -#ifdef O_LARGEFILE - if (pos >= ((fil->f_flags & O_LARGEFILE) ? _SYSIO_OFF_T_MAX : LONG_MAX)) - return -EOVERFLOW; -#else - if (pos >= _SYSIO_OFF_T_MAX) + if (pos >= max) return -EOVERFLOW; -#endif pos = (fil->f_ino->i_ops.inop_pos)(fil->f_ino, pos); if (pos < 0) return pos; @@ -120,17 +129,18 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset extern off64_t SYSIO_INTERFACE_NAME(lseek64)(int fd, off64_t offset, int whence) { - _SYSIO_OFF_T off; - off_t rtn; + struct file *fil; + off64_t off; SYSIO_INTERFACE_DISPLAY_BLOCK; SYSIO_INTERFACE_ENTER; - off = _sysio_lseek(fd, offset, whence); - if (off < 0) - SYSIO_INTERFACE_RETURN((off_t )-1, (int )off); - rtn = (off64_t )off; - assert(rtn == off); - SYSIO_INTERFACE_RETURN(rtn, 0); + fil = _sysio_fd_find(fd); + if (!fil) + SYSIO_INTERFACE_RETURN((off64_t )-1, -EBADF); + off = _sysio_lseek(fil, offset, whence, _SEEK_MAX(fil)); + SYSIO_INTERFACE_RETURN(off < 0 ? (off64_t )-1 : off, + off < 0 ? (int )off : 0); + } #ifdef __GLIBC__ #undef __lseek64 @@ -149,12 +159,16 @@ sysio_sym_weak_alias(SYSIO_INTERFACE_NAM extern off_t SYSIO_INTERFACE_NAME(lseek)(int fd, off_t offset, int whence) { + struct file *fil; _SYSIO_OFF_T off; off_t rtn; SYSIO_INTERFACE_DISPLAY_BLOCK; SYSIO_INTERFACE_ENTER; - off = _sysio_lseek(fd, offset, whence); + fil = _sysio_fd_find(fd); + if (!fil) + SYSIO_INTERFACE_RETURN((off_t )-1, -EBADF); + off = _sysio_lseek(fil, offset, whence, LONG_MAX); if (off < 0) SYSIO_INTERFACE_RETURN((off_t )-1, (int )off); rtn = (off_t )off; @@ -177,6 +191,7 @@ SYSIO_INTERFACE_NAME(llseek)(unsigned in loff_t *result __IS_UNUSED, unsigned int whence __IS_UNUSED) { + struct file *fil; loff_t off; SYSIO_INTERFACE_DISPLAY_BLOCK; @@ -184,6 +199,9 @@ SYSIO_INTERFACE_NAME(llseek)(unsigned in * This is just plain goofy. */ SYSIO_INTERFACE_ENTER; + fil = _sysio_fd_find(fd); + if (!fil) + SYSIO_INTERFACE_RETURN(-1, -EBADF); #if !_LARGEFILE64_SOURCE if (offset_high) { /* @@ -197,7 +215,7 @@ SYSIO_INTERFACE_NAME(llseek)(unsigned in off <<= 32; off |= offset_low; #endif - off = _sysio_lseek(fd, off, whence); + off = _sysio_lseek(fil, off, whence, _SEEK_MAX(fil)); if (off < 0) SYSIO_INTERFACE_RETURN((off_t )-1, (int )off); *result = off; |