Beamlib  3.0.1
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) 2022 All Right Reserved, Beam Ltd, https://www.beam.ltd.uk
5  * For license see LICENSE.txt at the root of the beamlib source tree.
6  *******************************************************************************
7  */
8 #ifndef BFILE_H
9 #define BFILE_H 1
10 
11 #include <stdio.h>
12 #include <BTypes.h>
13 #include <BString.h>
14 #include <BError.h>
15 
17 class BFile {
18 public:
19  BFile();
20  BFile(const BFile& file);
21  ~BFile();
22 
23  BError open(BString name, BString mode);
24  BError open(FILE* file);
25  BError open(int fd, BString mode);
26  BError close();
27 
28  int isOpen();
29  int isEnd();
30  FILE* getFd();
31  BUInt64 length();
32  int setVBuf(char* buf, int mode, size_t size);
33 
34  int read(void* buf, int nbytes);
35  int readString(BString& str);
36  char* fgets(char* buf, size_t size);
37 
38  int write(const void* buf, int nbytes);
39  int writeString(const BString& str);
40 
41  int seek(BUInt64 pos);
42  BUInt64 position();
43 
44  int printf(const char* fmt, ...);
45 
46  BError truncate();
47  BError flush();
48  BString fileName();
49 
50  BFile& operator=(const BFile& file);
51 private:
52  FILE* ofile;
53  BString ofileName;
54  BString omode;
55 };
56 
57 #endif
uint64_t BUInt64
Definition: BTypes.h:26
Error return class. This class is used to return the error status from a function....
Definition: BError.h:31
File operations class.
Definition: BFile.h:17
int isEnd()
Returns 1 if at the end of the file, 0 otherwise.
Definition: BFile.cpp:78
BError close()
Close file.
Definition: BFile.cpp:62
int write(const void *buf, int nbytes)
Write to file.
Definition: BFile.cpp:113
~BFile()
Definition: BFile.cpp:30
int writeString(const BString &str)
Write string to file.
Definition: BFile.cpp:117
BUInt64 length()
File size in bytes.
Definition: BFile.cpp:86
int isOpen()
Returns 1 if the file is open.
Definition: BFile.cpp:74
FILE * getFd()
File descriptor.
Definition: BFile.cpp:82
int read(void *buf, int nbytes)
Read from file.
Definition: BFile.cpp:93
BUInt64 position()
The files position.
Definition: BFile.cpp:125
BString fileName()
Return file name.
Definition: BFile.cpp:157
BError truncate()
Truncate the file.
Definition: BFile.cpp:140
int printf(const char *fmt,...)
Formated print into the file.
Definition: BFile.cpp:133
char * fgets(char *buf, size_t size)
Definition: BFile.cpp:109
BFile & operator=(const BFile &file)
Definition: BFile.cpp:25
BError open(BString name, BString mode)
Open file.
Definition: BFile.cpp:34
int setVBuf(char *buf, int mode, size_t size)
Set stream buffering options.
Definition: BFile.cpp:129
BFile()
Definition: BFile.cpp:17
BError flush()
Flush the file.
Definition: BFile.cpp:148
int readString(BString &str)
Read string. (ref fgets)
Definition: BFile.cpp:97
int seek(BUInt64 pos)
Set seek position.
Definition: BFile.cpp:121
This class stores and manipulates ASCII strings.
Definition: BString.h:20