Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
edaf59a7
There was an error fetching the commit references. Please try again later.
Commit
edaf59a7
authored
10 years ago
by
Emmanuel Gil Peyrot
Browse files
Options
Downloads
Patches
Plain Diff
Common: Return the number of items read/written in IOFile’s methods instead of a boolean.
parent
1c79a4f1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/common/file_util.h
+20
-8
20 additions, 8 deletions
src/common/file_util.h
with
20 additions
and
8 deletions
src/common/file_util.h
+
20
−
8
View file @
edaf59a7
...
@@ -151,29 +151,41 @@ public:
...
@@ -151,29 +151,41 @@ public:
bool
Close
();
bool
Close
();
template
<
typename
T
>
template
<
typename
T
>
bool
ReadArray
(
T
*
data
,
size_t
length
)
size_t
ReadArray
(
T
*
data
,
size_t
length
)
{
{
if
(
!
IsOpen
()
||
length
!=
std
::
fread
(
data
,
sizeof
(
T
),
length
,
m_file
))
if
(
!
IsOpen
()
)
{
m_good
=
false
;
m_good
=
false
;
return
-
1
;
}
return
m_good
;
size_t
items_read
=
std
::
fread
(
data
,
sizeof
(
T
),
length
,
m_file
);
if
(
items_read
!=
length
)
m_good
=
false
;
return
items_read
;
}
}
template
<
typename
T
>
template
<
typename
T
>
bool
WriteArray
(
const
T
*
data
,
size_t
length
)
size_t
WriteArray
(
const
T
*
data
,
size_t
length
)
{
{
if
(
!
IsOpen
()
||
length
!=
std
::
fwrite
(
data
,
sizeof
(
T
),
length
,
m_file
))
if
(
!
IsOpen
())
{
m_good
=
false
;
return
-
1
;
}
size_t
items_written
=
std
::
fwrite
(
data
,
sizeof
(
T
),
length
,
m_file
);
if
(
items_written
!=
length
)
m_good
=
false
;
m_good
=
false
;
return
m_good
;
return
items_written
;
}
}
bool
ReadBytes
(
void
*
data
,
size_t
length
)
size_t
ReadBytes
(
void
*
data
,
size_t
length
)
{
{
return
ReadArray
(
reinterpret_cast
<
char
*>
(
data
),
length
);
return
ReadArray
(
reinterpret_cast
<
char
*>
(
data
),
length
);
}
}
bool
WriteBytes
(
const
void
*
data
,
size_t
length
)
size_t
WriteBytes
(
const
void
*
data
,
size_t
length
)
{
{
return
WriteArray
(
reinterpret_cast
<
const
char
*>
(
data
),
length
);
return
WriteArray
(
reinterpret_cast
<
const
char
*>
(
data
),
length
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment