Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
ed1b25bb
Commit
ed1b25bb
authored
Oct 26, 2011
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
strmap: set errno on strmap_add() failures.
parent
2d31e99c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
4 deletions
+7
-4
ccan/strmap/strmap.c
ccan/strmap/strmap.c
+3
-1
ccan/strmap/strmap.h
ccan/strmap/strmap.h
+2
-2
ccan/strmap/test/run.c
ccan/strmap/test/run.c
+2
-1
No files found.
ccan/strmap/strmap.c
View file @
ed1b25bb
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include <ccan/ilog/ilog.h>
#include <ccan/ilog/ilog.h>
#include <assert.h>
#include <assert.h>
#include <stdlib.h>
#include <stdlib.h>
#include <errno.h>
struct
node
{
struct
node
{
/* These point to strings or nodes. */
/* These point to strings or nodes. */
...
@@ -72,6 +73,7 @@ bool strmap_add_(struct strmap *map, const char *member, const void *value)
...
@@ -72,6 +73,7 @@ bool strmap_add_(struct strmap *map, const char *member, const void *value)
for
(
byte_num
=
0
;
n
->
u
.
s
[
byte_num
]
==
member
[
byte_num
];
byte_num
++
)
{
for
(
byte_num
=
0
;
n
->
u
.
s
[
byte_num
]
==
member
[
byte_num
];
byte_num
++
)
{
if
(
member
[
byte_num
]
==
'\0'
)
{
if
(
member
[
byte_num
]
==
'\0'
)
{
/* All identical! */
/* All identical! */
errno
=
EEXIST
;
return
false
;
return
false
;
}
}
}
}
...
@@ -86,7 +88,7 @@ bool strmap_add_(struct strmap *map, const char *member, const void *value)
...
@@ -86,7 +88,7 @@ bool strmap_add_(struct strmap *map, const char *member, const void *value)
/* Allocate new node. */
/* Allocate new node. */
newn
=
malloc
(
sizeof
(
*
newn
));
newn
=
malloc
(
sizeof
(
*
newn
));
if
(
!
newn
)
{
if
(
!
newn
)
{
/* FIXME */
errno
=
ENOMEM
;
return
false
;
return
false
;
}
}
newn
->
byte_num
=
byte_num
;
newn
->
byte_num
=
byte_num
;
...
...
ccan/strmap/strmap.h
View file @
ed1b25bb
...
@@ -94,8 +94,8 @@ void *strmap_get_(const struct strmap *map, const char *member);
...
@@ -94,8 +94,8 @@ void *strmap_get_(const struct strmap *map, const char *member);
* @member: the string to place in the map.
* @member: the string to place in the map.
* @v: the (non-NULL) value.
* @v: the (non-NULL) value.
*
*
* This returns false if we run out of memory
, or (more normally) if that
* This returns false if we run out of memory
(errno = ENOMEM), or
*
string already appears in the map
.
*
(more normally) if that string already appears in the map (EEXIST)
.
*
*
* Note that the pointer is placed in the map, the string is not copied. If
* Note that the pointer is placed in the map, the string is not copied. If
* you want a copy in the map, use strdup(). Similarly for the value.
* you want a copy in the map, use strdup(). Similarly for the value.
...
...
ccan/strmap/test/run.c
View file @
ed1b25bb
...
@@ -14,7 +14,7 @@ int main(void)
...
@@ -14,7 +14,7 @@ int main(void)
char
*
v
;
char
*
v
;
/* This is how many tests you plan to run */
/* This is how many tests you plan to run */
plan_tests
(
3
1
);
plan_tests
(
3
2
);
strmap_init
(
&
map
);
strmap_init
(
&
map
);
...
@@ -31,6 +31,7 @@ int main(void)
...
@@ -31,6 +31,7 @@ int main(void)
/* Add a duplicate should fail. */
/* Add a duplicate should fail. */
ok1
(
!
strmap_add
(
&
map
,
dup
,
val
));
ok1
(
!
strmap_add
(
&
map
,
dup
,
val
));
ok1
(
errno
==
EEXIST
);
ok1
(
strmap_get
(
&
map
,
dup
)
==
val
);
ok1
(
strmap_get
(
&
map
,
dup
)
==
val
);
/* Delete should return original string. */
/* Delete should return original string. */
...
...
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