Beamlib 3.1.1
This is the Beam C++ class library.
Loading...
Searching...
No Matches
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
17class BFile {
18public:
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 openTemp(BString name, BString mode);
27 BError close();
28
29 int isOpen();
30 int isEnd();
31 FILE* getFd();
32 BUInt64 length();
33 int setVBuf(char* buf, int mode, size_t size);
34
35 int read(void* buf, int nbytes);
36 int readString(BString& str);
37 char* fgets(char* buf, size_t size);
38
39 int write(const void* buf, int nbytes);
40 int writeString(const BString& str);
41
42 int seek(BUInt64 pos);
44
45 int printf(const char* fmt, ...);
46
48 BError flush();
50
51 BFile& operator=(const BFile& file);
52private:
53 FILE* ofile;
54 BString ofileName;
55 BString omode;
56};
57
58BError bcopyFile(BString source, BString dest);
59BError bcopyDir(BString source, BString dest);
60
61#endif
BError bcopyFile(BString source, BString dest)
Copy a file.
Definition: BFile.cpp:259
BError bcopyDir(BString source, BString dest)
Copy complete directory.
Definition: BFile.cpp:287
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:175
BError close()
Close file.
Definition: BFile.cpp:159
int write(const void *buf, int nbytes)
Write to file.
Definition: BFile.cpp:210
~BFile()
Definition: BFile.cpp:96
int writeString(const BString &str)
Write string to file.
Definition: BFile.cpp:214
BError openTemp(BString name, BString mode)
Open a tempory file with the given name prefix.
Definition: BFile.cpp:128
BUInt64 length()
File size in bytes.
Definition: BFile.cpp:183
int isOpen()
Returns 1 if the file is open.
Definition: BFile.cpp:171
FILE * getFd()
File descriptor.
Definition: BFile.cpp:179
int read(void *buf, int nbytes)
Read from file.
Definition: BFile.cpp:190
BUInt64 position()
The files position.
Definition: BFile.cpp:222
BString fileName()
Return file name.
Definition: BFile.cpp:254
BError truncate()
Truncate the file.
Definition: BFile.cpp:237
int printf(const char *fmt,...)
Formated print into the file.
Definition: BFile.cpp:230
char * fgets(char *buf, size_t size)
Definition: BFile.cpp:206
BFile & operator=(const BFile &file)
Definition: BFile.cpp:91
BError open(BString name, BString mode)
Open file.
Definition: BFile.cpp:100
int setVBuf(char *buf, int mode, size_t size)
Set stream buffering options.
Definition: BFile.cpp:226
BFile()
Definition: BFile.cpp:83
BError flush()
Flush the file.
Definition: BFile.cpp:245
int readString(BString &str)
Read string. (ref fgets)
Definition: BFile.cpp:194
int seek(BUInt64 pos)
Set seek position.
Definition: BFile.cpp:218
This class stores and manipulates ASCII strings.
Definition: BString.h:20