We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
flush
close
ios_close
1 parent 5bd1d39 commit 8574e24Copy full SHA for 8574e24
NEWS.md
@@ -116,6 +116,8 @@ Standard library changes
116
order from `order` is used to compare the values of `by(element)`. In the latter case,
117
any order different from `Forward` or `Reverse` will raise an error about the
118
ambiguity.
119
+* `close` on a file (`IOStream`) can now throw an exception if an error occurs when trying
120
+ to flush buffered data to disk ([#35303]).
121
122
#### LinearAlgebra
123
* The BLAS submodule now supports the level-2 BLAS subroutine `hpmv!` ([#34211]).
base/iostream.jl
@@ -42,15 +42,23 @@ to synchronous `File`'s and `IOStream`'s not to any of the asynchronous streams.
42
fd(s::IOStream) = Int(ccall(:jl_ios_fd, Clong, (Ptr{Cvoid},), s.ios))
43
44
stat(s::IOStream) = stat(fd(s))
45
-close(s::IOStream) = @lock_nofail s.lock ccall(:ios_close, Cvoid, (Ptr{Cvoid},), s.ios)
+
46
isopen(s::IOStream) = ccall(:ios_isopen, Cint, (Ptr{Cvoid},), s.ios) != 0
47
48
+function close(s::IOStream)
49
+ bad = @lock_nofail s.lock ccall(:ios_close, Cint, (Ptr{Cvoid},), s.ios) != 0
50
+ systemerror("close", bad)
51
+end
52
53
function flush(s::IOStream)
54
sigatomic_begin()
55
bad = @lock_nofail s.lock ccall(:ios_flush, Cint, (Ptr{Cvoid},), s.ios) != 0
56
sigatomic_end()
57
systemerror("flush", bad)
58
end
59
60
iswritable(s::IOStream) = ccall(:ios_get_writable, Cint, (Ptr{Cvoid},), s.ios)!=0
61
62
isreadable(s::IOStream) = ccall(:ios_get_readable, Cint, (Ptr{Cvoid},), s.ios)!=0
63
64
"""
src/support/ios.c
@@ -648,17 +648,21 @@ int ios_flush(ios_t *s)
648
return 0;
649
}
650
651
-void ios_close(ios_t *s)
+int ios_close(ios_t *s)
652
{
653
- ios_flush(s);
654
- if (s->fd != -1 && s->ownfd)
655
- close(s->fd);
+ int err = ios_flush(s);
+ if (s->fd != -1 && s->ownfd) {
+ int err2 = close(s->fd);
656
+ if (err2 != 0)
657
+ err = err2;
658
+ }
659
s->fd = -1;
660
if (s->buf!=NULL && s->ownbuf && s->buf!=&s->local[0]) {
661
LLT_FREE(s->buf);
662
663
s->buf = NULL;
664
s->size = s->maxsize = s->bpos = 0;
665
+ return err;
666
667
668
int ios_isopen(ios_t *s)
src/support/ios.h
@@ -93,7 +93,7 @@ JL_DLLEXPORT int ios_trunc(ios_t *s, size_t size) JL_NOTSAFEPOINT;
93
JL_DLLEXPORT int ios_eof(ios_t *s);
94
JL_DLLEXPORT int ios_eof_blocking(ios_t *s);
95
JL_DLLEXPORT int ios_flush(ios_t *s);
96
-JL_DLLEXPORT void ios_close(ios_t *s);
+JL_DLLEXPORT int ios_close(ios_t *s);
97
JL_DLLEXPORT int ios_isopen(ios_t *s);
98
JL_DLLEXPORT char *ios_take_buffer(ios_t *s, size_t *psize); // release buffer to caller
99
// set buffer space to use
0 commit comments