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

« back to all changes in this revision

Viewing changes to src/lib/libpsio/toclen.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2008-06-07 16:49:57 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080607164957-8pifvb133yjlkagn
Tags: 3.3.0-3
* debian/rules (DEB_MAKE_CHECK_TARGET): Do not abort test suite on
  failures.
* debian/rules (DEB_CONFIGURE_EXTRA_FLAGS): Set ${bindir} to /usr/lib/psi.
* debian/rules (install/psi3): Move psi3 file to /usr/bin.
* debian/patches/07_464867_move_executables.dpatch: New patch, add
  /usr/lib/psi to the $PATH, so that the moved executables are found.
  (closes: #464867)
* debian/patches/00list: Adjusted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
   \ingroup (PSIO)
4
4
*/
5
5
 
 
6
#include <stdio.h>
 
7
#include <unistd.h>
 
8
#include <stdlib.h>
6
9
#include "psio.h"
 
10
#include <psifiles.h>
7
11
 
8
12
/*!
9
 
** PSIO_TOCLEN(): Compute the length of the TOC for a given unit.
 
13
** PSIO_TOCLEN(): Compute the length of the TOC for a given unit using the in-core TOC list.
10
14
**
11
15
** \ingroup (PSIO)
12
16
*/
19
23
  this_entry = psio_unit[unit].toc;
20
24
 
21
25
  while(this_entry != NULL) {
22
 
      ++toclen;
23
 
      this_entry = this_entry->next;
24
 
    }
25
 
 
26
 
  return(toclen);
 
26
    ++toclen;
 
27
    this_entry = this_entry->next;
 
28
  }
 
29
 
 
30
  return(toclen);
 
31
}
 
32
 
 
33
/*!
 
34
** PSIO_RD_TOCLEN(): Read the length of the TOC for a given unit directly from the file.
 
35
**
 
36
** \param unit = PSI unit number from which to read the toclen.
 
37
**
 
38
** NB: Note that we do not exit if the read request of the toclen from
 
39
** the file fails. This is because the request may be to an new file
 
40
** for which the toclen has not yet been written.  (We allow the user
 
41
** to open files with status PSIO_OPEN_OLD even if they don't exist,
 
42
** because sometimes you can't know this in advance.)
 
43
**
 
44
** \ingroup (PSIO)
 
45
*/
 
46
ULI psio_rd_toclen(unsigned int unit)
 
47
{
 
48
  int errcod, stream;
 
49
  psio_ud *this_unit;
 
50
  ULI toclen;
 
51
 
 
52
  this_unit = &(psio_unit[unit]);
 
53
 
 
54
  /* Seek vol[0] to its beginning */
 
55
  stream = this_unit->vol[0].stream;
 
56
  errcod = lseek(stream, 0L, SEEK_SET);
 
57
  if(errcod == -1) psio_error(unit,PSIO_ERROR_LSEEK);
 
58
 
 
59
  /* Read the value */
 
60
  errcod = read(stream, (char *) &toclen, sizeof(ULI));
 
61
  if(errcod != sizeof(ULI)) return(0); /* assume that all is well (see comments above) */
 
62
 
 
63
  return(toclen);
 
64
}
 
65
 
 
66
/*!
 
67
** PSIO_WT_TOCLEN(): Write the length of the TOC for a given unit directly to the file.
 
68
**
 
69
** \param unit = PSI unit number to which to write the toclen.
 
70
**
 
71
** \ingroup (PSIO)
 
72
*/
 
73
void psio_wt_toclen(unsigned int unit, ULI toclen)
 
74
{
 
75
  int errcod, stream;
 
76
  psio_ud *this_unit;
 
77
 
 
78
  this_unit = &(psio_unit[unit]);
 
79
 
 
80
  /* Seek vol[0] to its beginning */
 
81
  stream = this_unit->vol[0].stream;
 
82
  errcod = lseek(stream, 0L, SEEK_SET);
 
83
  if(errcod == -1) {
 
84
    fprintf(stderr, "Error in PSIO_WT_TOCLEN()!\n");
 
85
    exit(PSI_RETURN_FAILURE);
 
86
  }
 
87
 
 
88
  /* Write the value */
 
89
  errcod = write(stream, (char *) &toclen, sizeof(ULI));
 
90
  if(errcod != sizeof(ULI)) {
 
91
    fprintf(stderr, "PSIO_ERROR: Failed to write toclen to unit %d.\n", unit);
 
92
    psio_error(unit,PSIO_ERROR_WRITE);
 
93
  }
27
94
}