source: trunk/MagicSoft/Cosy/base/File.cc@ 744

Last change on this file since 744 was 732, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 1.1 KB
Line 
1#include "File.h"
2
3#include <stdlib.h>
4
5File::File(const char *name, const char *flags)
6{
7 f = fopen(name, flags);
8}
9
10File::~File()
11{
12 fclose(f);
13}
14
15char File::Getc() const
16{
17 return fgetc(f);
18}
19
20int File::Eof() const
21{
22 return feof(f);
23}
24
25void File::Seek(long pos) const
26{
27 fseek(f, pos, SEEK_SET);
28}
29
30void File::Reset() const
31{
32 fseek(f, 0, SEEK_SET);
33}
34
35long File::Tell() const
36{
37 return ftell(f);
38}
39
40long File::Size() const
41{
42 long l = ftell(f);
43 fseek(f, 0, SEEK_END);
44 long s = ftell(f);
45 fseek(f, l, SEEK_SET);
46 return s;
47}
48
49char *File::Gets(char *c, int cnt) const
50{
51 for (int i=0; i<cnt; i++)
52 *c++=fgetc(f);
53 *c='\0';
54
55 return c;
56}
57
58void File::Newline() const
59{
60 int g;
61 do g=fgetc(f);
62 while (g!=0x0A && g!=EOF);
63}
64
65int File::Geti(int cnt) const
66{
67 char *c = new char[cnt+1];
68 Gets(c, cnt);
69 int result = atoi(c);
70 delete c;
71 return result;
72}
73
74float File::Getf(int cnt) const
75{
76 char *c = new char[cnt+1];
77 Gets(c, cnt);
78 float result = atof(c);
79 delete c;
80 return result;
81}
82
83void File::Skip(int cnt) const
84{
85 char *c = new char[cnt+1];
86 Gets(c, cnt);
87 delete c;
88}
89
Note: See TracBrowser for help on using the repository browser.