os_seek.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997, 1998, 1999, 2000
00005  *      Sleepycat Software.  All rights reserved.
00006  */
00007 
00008 #include "config.h"
00009 
00010 #ifndef lint
00011 static const char revid[] = "$Id: os__seek_8c-source.html,v 1.1 2008/06/08 10:21:30 sebdiaz Exp $";
00012 #endif /* not lint */
00013 
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016 
00017 #include <errno.h>
00018 #include <stdlib.h>
00019 #include <string.h>
00020 #include <unistd.h>
00021 #endif
00022 
00023 #include "db_int.h"
00024 #include "os_jump.h"
00025 
00026 /*
00027  * CDB___os_seek --
00028  *      Seek to a page/byte offset in the file.
00029  *
00030  * PUBLIC: int CDB___os_seek __P((DB_ENV *,
00031  * PUBLIC:      DB_FH *, size_t, db_pgno_t, u_int32_t, int, DB_OS_SEEK));
00032  */
00033 int
00034 CDB___os_seek(dbenv, fhp, pgsize, pageno, relative, isrewind, db_whence)
00035         DB_ENV *dbenv;
00036         DB_FH *fhp;
00037         size_t pgsize;
00038         db_pgno_t pageno;
00039         u_int32_t relative;
00040         int isrewind;
00041         DB_OS_SEEK db_whence;
00042 {
00043         off_t offset;
00044         int ret, whence;
00045 
00046         switch (db_whence) {
00047         case DB_OS_SEEK_CUR:
00048                 whence = SEEK_CUR;
00049                 break;
00050         case DB_OS_SEEK_END:
00051                 whence = SEEK_END;
00052                 break;
00053         case DB_OS_SEEK_SET:
00054                 whence = SEEK_SET;
00055                 break;
00056         default:
00057                 return (EINVAL);
00058         }
00059 
00060         if (CDB___db_jump.j_seek != NULL)
00061                 ret = CDB___db_jump.j_seek(fhp->fd,
00062                     pgsize, pageno, relative, isrewind, whence);
00063         else {
00064                 offset = (off_t)pgsize * pageno + relative;
00065                 if (isrewind)
00066                         offset = -offset;
00067                 ret =
00068                     lseek(fhp->fd, offset, whence) == -1 ? CDB___os_get_errno() : 0;
00069         }
00070 
00071         if (ret != 0)
00072                 CDB___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 Jun 8 10:56:38 2008 for GNUmifluz by  doxygen 1.5.5