CernVM-FS
2.12.0
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
sink_file.cc
Go to the documentation of this file.
1
5
#include <cerrno>
6
#include <cstdio>
7
#include <string>
8
9
#include "
sink_file.h
"
10
11
namespace
cvmfs {
12
19
int64_t
FileSink::Write
(
const
void
*buf, uint64_t sz) {
20
size_t
ret = fwrite(buf, 1ul, sz,
file_
);
21
22
if
(ferror(
file_
) != 0) {
23
// ferror does not tell us what exactly the error is
24
// and errno is also not set
25
// so just return generic I/O error flag
26
return
-EIO;
27
}
28
29
return
static_cast<
int64_t
>
(ret);
30
}
31
38
int
FileSink::Reset
() {
39
return
((fflush(
file_
) == 0) &&
40
(ftruncate(fileno(
file_
), 0) == 0) &&
41
(freopen(NULL,
"w"
,
file_
) ==
file_
)) ? 0 : -errno;
42
}
43
53
int
FileSink::Purge
() {
54
if
(
is_owner_
&&
file_
) {
55
int
ret = fclose(
file_
);
56
file_
= NULL;
57
if
(ret != 0) {
58
return
-errno;
59
}
60
61
return
0;
62
}
else
{
63
return
Reset
();
64
}
65
}
66
70
std::string
FileSink::Describe
() {
71
std::string result =
"File sink with "
;
72
result +=
IsValid
() ?
" valid file pointer"
:
" invalid file pointer"
;
73
return
result;
74
}
75
void
FileSink::Adopt
(FILE *file,
bool
is_owner) {
76
if
(
is_owner_
&&
file_
) {
77
(void) fclose(
file_
);
78
}
79
80
is_owner_
= is_owner;
81
file_
=
file
;
82
}
83
}
// namespace cvmfs
cvmfs::FileSink::Purge
virtual int Purge()
Definition:
sink_file.cc:53
cvmfs::FileSink::file_
FILE * file_
Definition:
sink_file.h:114
cvmfs::FileSink::Describe
virtual std::string Describe()
Definition:
sink_file.cc:70
sink_file.h
cvmfs::FileSink::IsValid
virtual bool IsValid()
Definition:
sink_file.h:55
cvmfs::FileSink::Adopt
void Adopt(FILE *file, bool is_owner=true)
Definition:
sink_file.cc:75
cvmfs::FileSink::file
FILE * file()
Definition:
sink_file.h:109
cvmfs::FileSink::Write
virtual int64_t Write(const void *buf, uint64_t sz)
Definition:
sink_file.cc:19
cvmfs::FileSink::Reset
virtual int Reset()
Definition:
sink_file.cc:38
cvmfs::Sink::is_owner_
bool is_owner_
Definition:
sink.h:99
cvmfs
cvmfs
network
sink_file.cc
Generated on Sun Dec 22 2024 01:21:12 for CernVM-FS by
1.8.5