BDS Public
Beam-lib  2.16.3
This is the Beam C++ class library.
BFile.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * BFile.h BEAM BFile access class
3  * T.Barnaby, BEAM Ltd, 27/11/95
4  * Copyright (c) 2012 All Right Reserved, Beam Ltd, http://www.beam.ltd.uk
5  *******************************************************************************
6  */
7 #ifndef BFILE_H
8 #define BFILE_H 1
9 
10 #include <stdio.h>
11 #include <BTypes.h>
12 #include <BString.h>
13 #include <BError.h>
14 
16 class BFile {
17 public:
18  BFile();
19  BFile(const BFile& file);
20  ~BFile();
21 
22  BError open(BString name, BString mode);
23  BError open(FILE* file);
24  BError open(int fd, BString mode);
25  BError close();
26 
27  int isOpen();
28  int isEnd();
29  FILE* getFd();
30  BUInt64 length();
31  int setVBuf(char* buf, int mode, size_t size);
32 
33  int read(void* buf, int nbytes);
34  int readString(BString& str);
35  char* fgets(char* buf, size_t size);
36 
37  int write(const void* buf, int nbytes);
38  int writeString(const BString& str);
39 
40  int seek(BUInt64 pos);
41  BUInt64 position();
42 
43  int printf(const char* fmt, ...);
44 
45  BError truncate();
46  BError flush();
47  BString fileName();
48 
49  BFile& operator=(const BFile& file);
50 private:
51  FILE* ofile;
52  BString ofileName;
53  BString omode;
54 };
55 
56 #endif
char * fgets(char *buf, size_t size)
Definition: BFile.cpp:107
FILE * getFd()
File descriptor.
Definition: BFile.cpp:80
BError open(BString name, BString mode)
Open file.
Definition: BFile.cpp:32
Definition: BString.h:18
int write(const void *buf, int nbytes)
Write to file.
Definition: BFile.cpp:111
BFile()
Definition: BFile.cpp:15
int read(void *buf, int nbytes)
Read from file.
Definition: BFile.cpp:91
uint64_t BUInt64
Definition: BTypes.h:23
BFile & operator=(const BFile &file)
Definition: BFile.cpp:23
BUInt64 length()
File size in bytes.
Definition: BFile.cpp:84
int writeString(const BString &str)
Write string to file.
Definition: BFile.cpp:115
BError flush()
Flush the file.
Definition: BFile.cpp:146
int seek(BUInt64 pos)
Set seek position.
Definition: BFile.cpp:119
int isEnd()
Returns 1 if at the end of the file, 0 otherwise.
Definition: BFile.cpp:76
~BFile()
Definition: BFile.cpp:28
BUInt64 position()
The files position.
Definition: BFile.cpp:123
BError close()
Close file.
Definition: BFile.cpp:60
Definition: BError.h:25
File operations class.
Definition: BFile.h:16
BString fileName()
Return file name.
Definition: BFile.cpp:155
BError truncate()
Truncate the file.
Definition: BFile.cpp:138
int setVBuf(char *buf, int mode, size_t size)
Set stream buffering options.
Definition: BFile.cpp:127
int isOpen()
Returns 1 if the file is open.
Definition: BFile.cpp:72
int printf(const char *fmt,...)
Formated print into the file.
Definition: BFile.cpp:131
int readString(BString &str)
Read string. (ref fgets)
Definition: BFile.cpp:95