~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/lib/util/file/fileAccess.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  simple file access interface.
 
3
  Copyright (C) 2001  Martin Vogt
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU Library General Public License as published by
 
7
  the Free Software Foundation.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
 
 
15
#include "fileAccess.h"
 
16
 
 
17
 
 
18
FileAccess::FileAccess() {
 
19
  file=NULL;
 
20
  length=0;
 
21
}
 
22
 
 
23
 
 
24
FileAccess::~FileAccess() {
 
25
  close();
 
26
}
 
27
 
 
28
 
 
29
int FileAccess::open(const char* path) {
 
30
  close();
 
31
  file=fopen(path,"rb");
 
32
  length=calcByteLength();
 
33
  return (file != NULL);
 
34
}
 
35
 
 
36
 
 
37
void FileAccess::close() {
 
38
  if (file != NULL) {
 
39
    fclose(file);
 
40
    file=NULL;
 
41
    length=0;
 
42
  }
 
43
}
 
44
 
 
45
 
 
46
int FileAccess::read(char* dest,int len) {
 
47
  int back=0;
 
48
  if (file != NULL) {
 
49
    back=fread(dest,1,len,file);
 
50
  } else {
 
51
    printf("FileAccess::read not open\n");
 
52
  }
 
53
  return back;
 
54
}
 
55
                                                
 
56
int FileAccess::eof() {
 
57
  int back=true;
 
58
  if (file != NULL) {
 
59
    back=feof(file);
 
60
  }
 
61
  return back;
 
62
}
 
63
 
 
64
 
 
65
int FileAccess::seek(long pos) {
 
66
  if (file == NULL) {
 
67
    return -1;
 
68
  }
 
69
  return fseek(file,pos,SEEK_SET);
 
70
}
 
71
 
 
72
 
 
73
long FileAccess::getBytePosition() {
 
74
  if (file == NULL) {
 
75
    return 0;
 
76
  }
 
77
  return ftell(file);
 
78
}
 
79
 
 
80
 
 
81
long FileAccess::getByteLength() {
 
82
  return length;
 
83
}
 
84
 
 
85
long FileAccess::calcByteLength() {
 
86
  if (file == NULL) {
 
87
    return 0;
 
88
  }
 
89
  long pos=getBytePosition();
 
90
  fseek(file,0,SEEK_END);
 
91
  long back=getBytePosition();
 
92
  fseek(file,pos,SEEK_SET);
 
93
  return back;
 
94
}
 
95