Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libloc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
libloc
Commits
1642ccea
Commit
1642ccea
authored
Aug 23, 2022
by
Michael Tremer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
database: Break opening procedure into smaller parts
Signed-off-by:
Michael Tremer
<
michael.tremer@ipfire.org
>
parent
50c0fbcd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
7 deletions
+19
-7
src/database.c
src/database.c
+19
-7
No files found.
src/database.c
View file @
1642ccea
...
@@ -369,30 +369,42 @@ static int loc_database_read_header(struct loc_database* db) {
...
@@ -369,30 +369,42 @@ static int loc_database_read_header(struct loc_database* db) {
}
}
}
}
static
int
loc_database_read
(
struct
loc_database
*
db
,
FILE
*
f
)
{
static
int
loc_database_clone_handle
(
struct
loc_database
*
db
,
FILE
*
f
)
{
clock_t
start
=
clock
();
// Fetch the FD of the original handle
int
fd
=
fileno
(
f
);
int
fd
=
fileno
(
f
);
// Clone file descriptor
// Clone file descriptor
fd
=
dup
(
fd
);
fd
=
dup
(
fd
);
if
(
!
fd
)
{
if
(
!
fd
)
{
ERROR
(
db
->
ctx
,
"Could not duplicate file descriptor
\n
"
);
ERROR
(
db
->
ctx
,
"Could not duplicate file descriptor
\n
"
);
return
-
1
;
return
1
;
}
}
// Reopen the file so that we can keep our own file handle
// Reopen the file so that we can keep our own file handle
db
->
f
=
fdopen
(
fd
,
"r"
);
db
->
f
=
fdopen
(
fd
,
"r"
);
if
(
!
db
->
f
)
{
if
(
!
db
->
f
)
{
ERROR
(
db
->
ctx
,
"Could not re-open database file
\n
"
);
ERROR
(
db
->
ctx
,
"Could not re-open database file
\n
"
);
return
-
1
;
return
1
;
}
}
// Rewind to the start of the file
// Rewind to the start of the file
rewind
(
db
->
f
);
rewind
(
db
->
f
);
return
0
;
}
static
int
loc_database_open
(
struct
loc_database
*
db
,
FILE
*
f
)
{
int
r
;
clock_t
start
=
clock
();
// Clone the file handle
r
=
loc_database_clone_handle
(
db
,
f
);
if
(
r
)
return
r
;
// Read magic bytes
// Read magic bytes
int
r
=
loc_database_read_magic
(
db
);
r
=
loc_database_read_magic
(
db
);
if
(
r
)
if
(
r
)
return
r
;
return
r
;
...
@@ -464,7 +476,7 @@ LOC_EXPORT int loc_database_new(struct loc_ctx* ctx, struct loc_database** datab
...
@@ -464,7 +476,7 @@ LOC_EXPORT int loc_database_new(struct loc_ctx* ctx, struct loc_database** datab
DEBUG
(
db
->
ctx
,
"Database object allocated at %p
\n
"
,
db
);
DEBUG
(
db
->
ctx
,
"Database object allocated at %p
\n
"
,
db
);
// Try to open the database
// Try to open the database
r
=
loc_database_
read
(
db
,
f
);
r
=
loc_database_
open
(
db
,
f
);
if
(
r
)
if
(
r
)
goto
ERROR
;
goto
ERROR
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment