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
50c0fbcd
Commit
50c0fbcd
authored
Aug 23, 2022
by
Michael Tremer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
database: Refactor error handling on create
Signed-off-by:
Michael Tremer
<
michael.tremer@ipfire.org
>
parent
99a38c7f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
32 deletions
+42
-32
src/database.c
src/database.c
+42
-32
No files found.
src/database.c
View file @
50c0fbcd
...
...
@@ -409,38 +409,6 @@ static int loc_database_read(struct loc_database* db, FILE* f) {
return
0
;
}
LOC_EXPORT
int
loc_database_new
(
struct
loc_ctx
*
ctx
,
struct
loc_database
**
database
,
FILE
*
f
)
{
// Fail on invalid file handle
if
(
!
f
)
return
-
EINVAL
;
struct
loc_database
*
db
=
calloc
(
1
,
sizeof
(
*
db
));
if
(
!
db
)
return
-
ENOMEM
;
// Reference context
db
->
ctx
=
loc_ref
(
ctx
);
db
->
refcount
=
1
;
DEBUG
(
db
->
ctx
,
"Database object allocated at %p
\n
"
,
db
);
int
r
=
loc_database_read
(
db
,
f
);
if
(
r
)
{
loc_database_unref
(
db
);
return
r
;
}
*
database
=
db
;
return
0
;
}
LOC_EXPORT
struct
loc_database
*
loc_database_ref
(
struct
loc_database
*
db
)
{
db
->
refcount
++
;
return
db
;
}
static
void
loc_database_free
(
struct
loc_database
*
db
)
{
DEBUG
(
db
->
ctx
,
"Releasing database %p
\n
"
,
db
);
...
...
@@ -474,6 +442,48 @@ static void loc_database_free(struct loc_database* db) {
free
(
db
);
}
LOC_EXPORT
int
loc_database_new
(
struct
loc_ctx
*
ctx
,
struct
loc_database
**
database
,
FILE
*
f
)
{
struct
loc_database
*
db
=
NULL
;
int
r
;
// Fail on invalid file handle
if
(
!
f
)
{
errno
=
EINVAL
;
return
1
;
}
// Allocate the database object
db
=
calloc
(
1
,
sizeof
(
*
db
));
if
(
!
db
)
goto
ERROR
;
// Reference context
db
->
ctx
=
loc_ref
(
ctx
);
db
->
refcount
=
1
;
DEBUG
(
db
->
ctx
,
"Database object allocated at %p
\n
"
,
db
);
// Try to open the database
r
=
loc_database_read
(
db
,
f
);
if
(
r
)
goto
ERROR
;
*
database
=
db
;
return
0
;
ERROR:
if
(
db
)
loc_database_free
(
db
);
return
r
;
}
LOC_EXPORT
struct
loc_database
*
loc_database_ref
(
struct
loc_database
*
db
)
{
db
->
refcount
++
;
return
db
;
}
LOC_EXPORT
struct
loc_database
*
loc_database_unref
(
struct
loc_database
*
db
)
{
if
(
--
db
->
refcount
>
0
)
return
NULL
;
...
...
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