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
b2def1c8
Commit
b2def1c8
authored
Jun 28, 2008
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add fclose_noerr()
parent
d4aa9aa3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
1 deletion
+39
-1
ccan/noerr/noerr.c
ccan/noerr/noerr.c
+13
-0
ccan/noerr/noerr.h
ccan/noerr/noerr.h
+10
-0
ccan/noerr/test/run.c
ccan/noerr/test/run.c
+16
-1
No files found.
ccan/noerr/noerr.c
View file @
b2def1c8
...
...
@@ -15,6 +15,19 @@ int close_noerr(int fd)
return
ret
;
}
int
fclose_noerr
(
FILE
*
fp
)
{
int
saved_errno
=
errno
,
ret
;
if
(
fclose
(
fp
)
!=
0
)
ret
=
errno
;
else
ret
=
0
;
errno
=
saved_errno
;
return
ret
;
}
int
unlink_noerr
(
const
char
*
pathname
)
{
int
saved_errno
=
errno
,
ret
;
...
...
ccan/noerr/noerr.h
View file @
b2def1c8
#ifndef NOERR_H
#define NOERR_H
#include <stdio.h>
/**
* close_noerr - close without stomping errno.
...
...
@@ -10,6 +11,15 @@
*/
int
close_noerr
(
int
fd
);
/**
* fclose_noerr - close without stomping errno.
* @fp: the FILE pointer.
*
* errno is saved and restored across the call to fclose: if an error occurs,
* the resulting (non-zero) errno is returned.
*/
int
fclose_noerr
(
FILE
*
fp
);
/**
* unlink_noerr - unlink a file without stomping errno.
* @pathname: the path to unlink.
...
...
ccan/noerr/test/run.c
View file @
b2def1c8
...
...
@@ -12,8 +12,9 @@ int main(int argc, char *argv[])
/* tempnam(3) is generally a bad idea, but OK here. */
char
*
name
=
tempnam
(
NULL
,
"noerr"
);
int
fd
;
FILE
*
fp
;
plan_tests
(
1
2
);
plan_tests
(
1
5
);
/* Should fail to unlink. */
ok1
(
unlink
(
name
)
!=
0
);
ok1
(
errno
==
ENOENT
);
...
...
@@ -44,5 +45,19 @@ int main(int argc, char *argv[])
ok1
(
unlink_noerr
(
name
)
==
0
);
ok1
(
errno
==
100
);
/* Test failing fclose */
fp
=
fopen
(
name
,
"wb"
);
assert
(
fp
);
close
(
fileno
(
fp
));
ok1
(
fclose_noerr
(
fp
)
==
EBADF
);
/* Test successful fclose */
fp
=
fopen
(
name
,
"wb"
);
assert
(
fp
);
errno
=
100
;
ok1
(
fclose_noerr
(
fp
)
==
0
);
ok1
(
errno
==
100
);
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