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
1fe2fa08
Commit
1fe2fa08
authored
Nov 20, 2015
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
noerr: add free_noerr().
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
09378088
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
1 deletion
+21
-1
ccan/noerr/noerr.c
ccan/noerr/noerr.c
+8
-0
ccan/noerr/noerr.h
ccan/noerr/noerr.h
+8
-0
ccan/noerr/test/run.c
ccan/noerr/test/run.c
+5
-1
No files found.
ccan/noerr/noerr.c
View file @
1fe2fa08
...
...
@@ -2,6 +2,7 @@
#include "noerr.h"
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
int
close_noerr
(
int
fd
)
{
...
...
@@ -41,3 +42,10 @@ int unlink_noerr(const char *pathname)
errno
=
saved_errno
;
return
ret
;
}
void
free_noerr
(
void
*
p
)
{
int
saved_errno
=
errno
;
free
(
p
);
errno
=
saved_errno
;
}
ccan/noerr/noerr.h
View file @
1fe2fa08
...
...
@@ -30,4 +30,12 @@ int fclose_noerr(FILE *fp);
*/
int
unlink_noerr
(
const
char
*
pathname
);
/**
* free_noerr - free memory without stomping errno.
* @p: the pointer to free.
*
* errno is saved and restored across the call to free: the standard leaves
* that undefined.
*/
void
free_noerr
(
void
*
p
);
#endif
/* NOERR_H */
ccan/noerr/test/run.c
View file @
1fe2fa08
...
...
@@ -13,7 +13,7 @@ int main(int argc, char *argv[])
int
fd
;
FILE
*
fp
;
plan_tests
(
1
5
);
plan_tests
(
1
6
);
/* Should fail to unlink. */
ok1
(
unlink
(
name
)
!=
0
);
ok1
(
errno
==
ENOENT
);
...
...
@@ -59,5 +59,9 @@ int main(int argc, char *argv[])
ok1
(
errno
==
100
);
unlink
(
name
);
errno
=
101
;
free_noerr
(
malloc
(
7
));
ok1
(
errno
==
101
);
return
exit_status
();
}
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