Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

os_seek.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: os_seek.c,v 12.2 2005/08/10 15:47:27 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 
00015 #include <stdlib.h>
00016 #include <string.h>
00017 #endif
00018 
00019 #include "db_int.h"
00020 
00021 /*
00022  * __os_seek --
00023  *      Seek to a page/byte offset in the file.
00024  *
00025  * PUBLIC: int __os_seek __P((DB_ENV *,
00026  * PUBLIC:      DB_FH *, u_int32_t, db_pgno_t, u_int32_t, int, DB_OS_SEEK));
00027  */
00028 int
00029 __os_seek(dbenv, fhp, pgsize, pageno, relative, isrewind, db_whence)
00030         DB_ENV *dbenv;
00031         DB_FH *fhp;
00032         u_int32_t pgsize;
00033         db_pgno_t pageno;
00034         u_int32_t relative;
00035         int isrewind;
00036         DB_OS_SEEK db_whence;
00037 {
00038         off_t offset;
00039         int ret, whence;
00040 
00041         /* Check for illegal usage. */
00042         DB_ASSERT(F_ISSET(fhp, DB_FH_OPENED) && fhp->fd != -1);
00043 
00044         switch (db_whence) {
00045         case DB_OS_SEEK_CUR:
00046                 whence = SEEK_CUR;
00047                 break;
00048         case DB_OS_SEEK_END:
00049                 whence = SEEK_END;
00050                 break;
00051         case DB_OS_SEEK_SET:
00052                 whence = SEEK_SET;
00053                 break;
00054         default:
00055                 return (EINVAL);
00056         }
00057 
00058         offset = (off_t)pgsize * pageno + relative;
00059         if (isrewind)
00060                 offset = -offset;
00061 
00062         if (DB_GLOBAL(j_seek) != NULL)
00063                 ret = DB_GLOBAL(j_seek)(fhp->fd, offset, whence);
00064         else
00065                 RETRY_CHK((lseek(fhp->fd, offset, whence) == -1 ? 1 : 0), ret);
00066 
00067         if (ret == 0) {
00068                 fhp->pgsize = pgsize;
00069                 fhp->pgno = pageno;
00070                 fhp->offset = relative;
00071         } else
00072                 __db_err(dbenv, "seek: %lu %d %d: %s",
00073                     (u_long)pgsize * pageno + relative,
00074                     isrewind, db_whence, strerror(ret));
00075 
00076         return (ret);
00077 }

Generated on Sun Dec 25 12:14:42 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2