00001
00002
00003
00004
00005
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
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
00028
00029
00030
00031
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 }