~ubuntu-branches/ubuntu/karmic/psicode/karmic

« back to all changes in this revision

Viewing changes to src/lib/libpsio/close.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
/*! \defgroup PSIO libpsio: The PSI I/O Library */
 
2
 
 
3
/*!
 
4
 ** \file
 
5
 ** \ingroup PSIO
 
6
 */
 
7
 
 
8
#include <unistd.h>
 
9
#include <cstring>
 
10
#include <cstdlib>
 
11
#include <libpsio/psio.h>
 
12
#include <libpsio/psio.hpp>
 
13
 
 
14
using namespace psi;
 
15
 
 
16
void PSIO::close(unsigned int unit, int keep) {
 
17
  unsigned int i;
 
18
  psio_ud *this_unit;
 
19
  psio_tocentry *this_entry, *next_entry;
 
20
  
 
21
  this_unit = &(psio_unit[unit]);
 
22
  
 
23
  /* First check to see if this unit is already closed */
 
24
  if (this_unit->vol[0].stream == -1)
 
25
    psio_error(unit, PSIO_ERROR_RECLOSE);
 
26
  
 
27
  /* Dump the current TOC back out to disk */
 
28
  tocwrite(unit);
 
29
  
 
30
  /* Free the TOC */
 
31
  this_entry = this_unit->toc;
 
32
  for (i=0; i < this_unit->toclen; i++) {
 
33
    next_entry = this_entry->next;
 
34
    free(this_entry);
 
35
    this_entry = next_entry;
 
36
  }
 
37
  
 
38
  /* Close each volume (remove if necessary) and free the path */
 
39
  for (i=0; i < this_unit->numvols; i++) {
 
40
    
 
41
    if (::close(this_unit->vol[i].stream) == -1)
 
42
    psio_error(unit,PSIO_ERROR_CLOSE);
 
43
 
 
44
    /* Delete the file completely if requested */
 
45
    if(!keep) unlink(this_unit->vol[i].path);
 
46
 
 
47
    free(this_unit->vol[i].path);
 
48
    this_unit->vol[i].path = NULL;
 
49
    this_unit->vol[i].stream = -1;
 
50
  }
 
51
 
 
52
  /* Reset the global page stats to zero */
 
53
  this_unit->numvols = 0;
 
54
  this_unit->toclen = 0;
 
55
}
 
56
 
 
57
extern "C" {
 
58
  int psio_close(unsigned int unit, int keep) {
 
59
    _default_psio_lib_->close(unit, keep);
 
60
    return 0;
 
61
  }
 
62
}
 
63