File: BlockIO.C

package info (click to toggle)
librcsb-core-wrapper 1.005-13
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,576 kB
  • sloc: xml: 122,915; cpp: 25,250; ansic: 3,736; makefile: 1,033; sh: 772; lex: 294; yacc: 235; perl: 213; python: 121; csh: 30
file content (66 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//$$FILE$$
//$$VERSION$$
//$$DATE$$
//$$LICENSE$$


/*
 ** Class for blockwise IO operations
 */

#ifdef VLAD_DECIDE
#include <strings.h>
#endif

#include <string.h>
#include <unistd.h>
#include <fcntl.h>

#include <string>

#include "rcsb_types.h"
#include "Exceptions.h"
#include "GenString.h"
#include "BlockIO.h"

using std::string;

BlockIO::BlockIO()
{
    memset(_buffer, 0, BLKSIZE);
}

BlockIO::~BlockIO()
{

}

unsigned int BlockIO::ReadBlock(const int fd, const UInt32 blockNum)
{
    if (lseek(fd, BLKSIZE * blockNum, SEEK_SET) == -1)
    {
        throw FileException(string("Could not seek in the file with fd: ") + \
          String::IntToString(fd), "BlockIO::ReadBlock");
    }

    // VLAD - CHECK FOR -1 AND THROW EXCEPTION
    return read(fd, _buffer, BLKSIZE);
}

unsigned int BlockIO::WriteBlock(const int fd, const UInt32 blockNum)
{
    if (lseek(fd, blockNum * BLKSIZE, SEEK_SET) == -1)
    {
        throw FileException(string("Could not seek in the file with fd: ") + \
          String::IntToString(fd), "BlockIO::WriteBlock");
    }

    // VLAD - CHECK FOR -1 AND THROW EXCEPTION
    return write(fd, _buffer, BLKSIZE);
}

void BlockIO::AssociateBuffer(char** newBuffer)
{
    *newBuffer = (char*)_buffer;
}