2001-12-06 13:10:51 +01:00
|
|
|
/* Copyright (C) 2000 MySQL AB
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
2000-07-31 21:29:14 +02:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2001-12-06 13:10:51 +01:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
#include "mysys_priv.h"
|
|
|
|
|
2006-10-31 09:26:16 +01:00
|
|
|
/*
|
|
|
|
Seek to a position in a file.
|
|
|
|
|
|
|
|
ARGUMENTS
|
|
|
|
File fd The file descriptor
|
|
|
|
my_off_t pos The expected position (absolute or relative)
|
|
|
|
int whence A direction parameter and one of
|
|
|
|
{SEEK_SET, SEEK_CUR, SEEK_END}
|
2007-05-16 20:42:32 +02:00
|
|
|
myf MyFlags MY_THREADSAFE must be set in case my_seek may be mixed
|
|
|
|
with my_pread/my_pwrite calls and fd is shared among
|
|
|
|
threads.
|
2006-10-31 09:26:16 +01:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
The my_seek function is a wrapper around the system call lseek and
|
|
|
|
repositions the offset of the file descriptor fd to the argument
|
|
|
|
offset according to the directive whence as follows:
|
|
|
|
SEEK_SET The offset is set to offset bytes.
|
|
|
|
SEEK_CUR The offset is set to its current location plus offset bytes
|
|
|
|
SEEK_END The offset is set to the size of the file plus offset bytes
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
my_off_t newpos The new position in the file.
|
|
|
|
MY_FILEPOS_ERROR An error was encountered while performing
|
|
|
|
the seek. my_errno is set to indicate the
|
|
|
|
actual error.
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2001-11-22 12:15:17 +01:00
|
|
|
my_off_t my_seek(File fd, my_off_t pos, int whence,
|
|
|
|
myf MyFlags __attribute__((unused)))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2009-09-11 22:26:35 +02:00
|
|
|
os_off_t newpos= -1;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("my_seek");
|
2009-09-11 22:26:35 +02:00
|
|
|
DBUG_PRINT("my",("fd: %d Pos: %llu Whence: %d MyFlags: %d",
|
|
|
|
fd, (ulonglong) pos, whence, MyFlags));
|
2003-05-13 17:58:26 +02:00
|
|
|
DBUG_ASSERT(pos != MY_FILEPOS_ERROR); /* safety check */
|
|
|
|
|
2006-10-09 21:13:37 +02:00
|
|
|
/*
|
|
|
|
Make sure we are using a valid file descriptor!
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(fd != -1);
|
2009-09-11 22:26:35 +02:00
|
|
|
#if defined (_WIN32)
|
|
|
|
newpos= my_win_lseek(fd, pos, whence);
|
|
|
|
#else
|
|
|
|
newpos= lseek(fd, pos, whence);
|
2007-05-16 20:42:32 +02:00
|
|
|
#endif
|
2000-07-31 21:29:14 +02:00
|
|
|
if (newpos == (os_off_t) -1)
|
|
|
|
{
|
2009-09-11 22:26:35 +02:00
|
|
|
my_errno= errno;
|
|
|
|
DBUG_PRINT("error",("lseek: %llu errno: %d", (ulonglong) newpos,errno));
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(MY_FILEPOS_ERROR);
|
|
|
|
}
|
2001-11-29 20:46:51 +01:00
|
|
|
if ((my_off_t) newpos != pos)
|
2001-11-28 01:55:52 +01:00
|
|
|
{
|
2009-09-11 22:26:35 +02:00
|
|
|
DBUG_PRINT("exit",("pos: %llu", (ulonglong) newpos));
|
2001-11-28 01:55:52 +01:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN((my_off_t) newpos);
|
|
|
|
} /* my_seek */
|
|
|
|
|
|
|
|
|
|
|
|
/* Tell current position of file */
|
|
|
|
/* ARGSUSED */
|
|
|
|
|
2001-11-22 12:15:17 +01:00
|
|
|
my_off_t my_tell(File fd, myf MyFlags __attribute__((unused)))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
os_off_t pos;
|
|
|
|
DBUG_ENTER("my_tell");
|
2009-09-11 22:26:35 +02:00
|
|
|
DBUG_PRINT("my",("fd: %d MyFlags: %d",fd, MyFlags));
|
2007-06-05 00:16:02 +02:00
|
|
|
DBUG_ASSERT(fd >= 0);
|
2009-09-11 22:26:35 +02:00
|
|
|
#if defined (HAVE_TELL) && !defined (_WIN32)
|
|
|
|
pos= tell(fd);
|
2000-07-31 21:29:14 +02:00
|
|
|
#else
|
2009-09-11 22:26:35 +02:00
|
|
|
pos= my_seek(fd, 0L, MY_SEEK_CUR,0);
|
2000-07-31 21:29:14 +02:00
|
|
|
#endif
|
|
|
|
if (pos == (os_off_t) -1)
|
2009-09-11 22:26:35 +02:00
|
|
|
my_errno= errno;
|
|
|
|
DBUG_PRINT("exit",("pos: %llu", (ulonglong) pos));
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN((my_off_t) pos);
|
|
|
|
} /* my_tell */
|