~ubuntu-branches/ubuntu/vivid/psicode/vivid

« back to all changes in this revision

Viewing changes to src/lib/libpsio/volseek.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2009-02-23 00:12:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090223001202-rutldoy3dimfpesc
Tags: 3.4.0-1
* New upstream release.

[ Michael Banck ]
* debian/patches/01_DESTDIR.dpatch: Refreshed.
* debian/patches/02_FHS.dpatch: Removed, applied upstream.
* debian/patches/03_debian_docdir: Likewise.
* debian/patches/04_man.dpatch: Likewise.
* debian/patches/06_466828_fix_gcc_43_ftbfs.dpatch: Likewise.
* debian/patches/07_464867_move_executables: Fixed and refreshed.
* debian/patches/00list: Adjusted.
* debian/control: Improved description.
* debian/patches-held: Removed.
* debian/rules (install/psi3): Do not ship the ruby bindings for now.

[ Daniel Leidert ]
* debian/rules: Fix txtdir via DEB_MAKE_INSTALL_TARGET.
* debian/patches/01_DESTDIR.dpatch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
 \file
 
3
 \ingroup PSIO
 
4
 */
 
5
 
 
6
#include <unistd.h>
 
7
#include <libpsio/psio.h>
 
8
 
 
9
/* This is strictly used to avoid overflow errors on lseek() calls */
 
10
#define PSIO_BIGNUM 10000
 
11
 
 
12
extern "C" {
 
13
  /*!
 
14
   ** PSIO_VOLSEEK()
 
15
   **
 
16
   ** \ingroup PSIO
 
17
   */
 
18
  int psio_volseek(psio_vol *vol, ULI page, ULI offset, ULI numvols) {
 
19
    int stream, errcod;
 
20
    ULI bignum, total_offset;
 
21
    
 
22
    bignum = PSIO_BIGNUM*numvols;
 
23
    
 
24
    stream = vol->stream;
 
25
    
 
26
    /* Set file pointer to beginning of file */
 
27
    errcod = lseek(stream, (ULI) 0, SEEK_SET);
 
28
    if (errcod == -1)
 
29
      return (errcod);
 
30
    
 
31
    /* lseek() through large chunks of the file to avoid offset overflows */
 
32
    for (; page > bignum; page -= bignum) {
 
33
      total_offset = PSIO_BIGNUM * PSIO_PAGELEN;
 
34
      errcod = lseek(stream, total_offset, SEEK_CUR);
 
35
      if (errcod == -1)
 
36
        return (errcod);
 
37
    }
 
38
    
 
39
    /* Now compute the final offset including the page-relative term */
 
40
    total_offset = (ULI) page/numvols; /* This should truncate */
 
41
    total_offset *= PSIO_PAGELEN;
 
42
    total_offset += offset; /* Add the page-relative term */
 
43
    errcod = lseek(stream, total_offset, SEEK_CUR);
 
44
    if (errcod == -1)
 
45
      return (errcod);
 
46
    
 
47
    return (0);
 
48
  }
 
49
}