00001
00002
00003
00004
00005
00006
00007
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
00023
00024
00025
00026
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
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 }