aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-09-09 14:30:19 -0400
committerDavid Robillard <d@drobilla.net>2022-01-28 21:57:07 -0500
commit5ea7c0d763685c23dc6933e273dfa11eec5bec14 (patch)
treec858abf15eae4f98472796aff3d05e4aadc51bc1
parentbd24b8f6d558bafbbb16d9490ebe3478dbf130bd (diff)
downloadserd-5ea7c0d763685c23dc6933e273dfa11eec5bec14.tar.gz
serd-5ea7c0d763685c23dc6933e273dfa11eec5bec14.tar.bz2
serd-5ea7c0d763685c23dc6933e273dfa11eec5bec14.zip
Use simpler names for I/O function types
-rw-r--r--include/serd/serd.h51
-rw-r--r--src/input_stream.c12
-rw-r--r--src/output_stream.c8
-rw-r--r--test/test_reader.c17
-rw-r--r--tools/console.c4
5 files changed, 46 insertions, 46 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index b70500c1..d606f4bb 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -311,7 +311,7 @@ serd_strncasecmp(const char* SERD_NONNULL s1,
Source function for raw string input.
Identical semantics to `fread`, but may set errno for more informative error
- reporting than supported by SerdStreamErrorFunc.
+ reporting than supported by #SerdErrorFunc.
@param buf Output buffer.
@param size Size of a single element of data in bytes (always 1).
@@ -328,7 +328,7 @@ typedef size_t (*SerdReadFunc)(void* SERD_NONNULL buf,
Sink function for raw string output.
Identical semantics to `fwrite`, but may set errno for more informative
- error reporting than supported by SerdStreamErrorFunc.
+ error reporting than supported by #SerdErrorFunc.
@param buf Input buffer.
@param size Size of a single element of data in bytes (always 1).
@@ -342,22 +342,25 @@ typedef size_t (*SerdWriteFunc)(const void* SERD_NONNULL buf,
void* SERD_NONNULL stream);
/**
- Function to detect I/O stream errors.
+ Function for detecting I/O stream errors.
- Identical semantics to `ferror`.
+ This has identical semantics to `ferror`.
@return Non-zero if `stream` has encountered an error.
*/
-typedef int (*SerdStreamErrorFunc)(void* SERD_NONNULL stream);
+typedef int (*SerdErrorFunc)(void* SERD_NONNULL stream);
/**
- Function to close an I/O stream.
+ Function for closing an I/O stream.
- Identical semantics to `fclose`.
+ This has identical semantics to `fclose`. Note that when writing, this may
+ flush the stream which can cause errors, including errors caused by previous
+ writes that appeared successful at the time. Therefore it is necessary to
+ check the return value of this function to properly detect write errors.
@return Non-zero if `stream` has encountered an error.
*/
-typedef int (*SerdStreamCloseFunc)(void* SERD_NONNULL stream);
+typedef int (*SerdCloseFunc)(void* SERD_NONNULL stream);
/**
@}
@@ -2197,10 +2200,10 @@ serd_node_to_syntax(const SerdNode* SERD_NONNULL node,
/// An input stream that produces bytes
typedef struct {
- void* SERD_NULLABLE stream; ///< Opaque parameter for functions
- SerdReadFunc SERD_NULLABLE read; ///< Read bytes to input
- SerdStreamErrorFunc SERD_NONNULL error; ///< Stream error accessor
- SerdStreamCloseFunc SERD_NULLABLE close; ///< Close input
+ void* SERD_NULLABLE stream; ///< Opaque parameter for functions
+ SerdReadFunc SERD_NULLABLE read; ///< Read bytes to input
+ SerdErrorFunc SERD_NONNULL error; ///< Stream error accessor
+ SerdCloseFunc SERD_NULLABLE close; ///< Close input
} SerdInputStream;
/**
@@ -2215,10 +2218,10 @@ typedef struct {
*/
SERD_CONST_API
SerdInputStream
-serd_open_input_stream(SerdReadFunc SERD_NONNULL read_func,
- SerdStreamErrorFunc SERD_NONNULL error_func,
- SerdStreamCloseFunc SERD_NULLABLE close_func,
- void* SERD_NULLABLE stream);
+serd_open_input_stream(SerdReadFunc SERD_NONNULL read_func,
+ SerdErrorFunc SERD_NONNULL error_func,
+ SerdCloseFunc SERD_NULLABLE close_func,
+ void* SERD_NULLABLE stream);
/**
Open a stream that reads from a string.
@@ -2410,8 +2413,8 @@ serd_reader_free(SerdReader* SERD_NULLABLE reader);
@defgroup serd_buffer Buffer
The #SerdBuffer type represents a writable area of memory with a known size.
- An implementation of #SerdWriteFunc, #SerdStreamErrorFunc, and
- #SerdStreamCloseFunc are provided which allow output to be written to a
+ An implementation of #SerdWriteFunc, #SerdErrorFunc, and
+ #SerdCloseFunc are provided which allow output to be written to a
buffer in memory instead of to a file as with `fwrite`, `ferror`, and
`fclose`.
@@ -2464,9 +2467,9 @@ serd_buffer_close(void* SERD_NONNULL stream);
/// An output stream that receives bytes
typedef struct {
- void* SERD_NULLABLE stream; ///< Opaque parameter for functions
- SerdWriteFunc SERD_NULLABLE write; ///< Write bytes to output
- SerdStreamCloseFunc SERD_NULLABLE close; ///< Close output
+ void* SERD_NULLABLE stream; ///< Opaque parameter for functions
+ SerdWriteFunc SERD_NULLABLE write; ///< Write bytes to output
+ SerdCloseFunc SERD_NULLABLE close; ///< Close output
} SerdOutputStream;
/**
@@ -2480,9 +2483,9 @@ typedef struct {
*/
SERD_CONST_API
SerdOutputStream
-serd_open_output_stream(SerdWriteFunc SERD_NONNULL write_func,
- SerdStreamCloseFunc SERD_NULLABLE close_func,
- void* SERD_NULLABLE stream);
+serd_open_output_stream(SerdWriteFunc SERD_NONNULL write_func,
+ SerdCloseFunc SERD_NULLABLE close_func,
+ void* SERD_NULLABLE stream);
/**
Open a stream that writes to a buffer.
diff --git a/src/input_stream.c b/src/input_stream.c
index 5755ccc3..e83f9e6a 100644
--- a/src/input_stream.c
+++ b/src/input_stream.c
@@ -64,10 +64,10 @@ serd_string_close(void* const stream)
}
SerdInputStream
-serd_open_input_stream(SerdReadFunc SERD_NONNULL read_func,
- SerdStreamErrorFunc SERD_NONNULL error_func,
- SerdStreamCloseFunc SERD_NULLABLE close_func,
- void* const stream)
+serd_open_input_stream(SerdReadFunc SERD_NONNULL read_func,
+ SerdErrorFunc SERD_NONNULL error_func,
+ SerdCloseFunc SERD_NULLABLE close_func,
+ void* const stream)
{
assert(read_func);
assert(error_func);
@@ -126,8 +126,8 @@ serd_open_input_file(const char* const path)
input.stream = file;
input.read = (SerdReadFunc)fread;
- input.error = (SerdStreamErrorFunc)ferror;
- input.close = (SerdStreamCloseFunc)fclose;
+ input.error = (SerdErrorFunc)ferror;
+ input.close = (SerdCloseFunc)fclose;
return input;
}
diff --git a/src/output_stream.c b/src/output_stream.c
index 7beb5e2f..b98c834a 100644
--- a/src/output_stream.c
+++ b/src/output_stream.c
@@ -29,9 +29,9 @@
#endif
SerdOutputStream
-serd_open_output_stream(SerdWriteFunc const write_func,
- SerdStreamCloseFunc const close_func,
- void* const stream)
+serd_open_output_stream(SerdWriteFunc const write_func,
+ SerdCloseFunc const close_func,
+ void* const stream)
{
assert(write_func);
@@ -68,7 +68,7 @@ serd_open_output_file(const char* const path)
#endif
return serd_open_output_stream(
- (SerdWriteFunc)fwrite, (SerdStreamCloseFunc)fclose, file);
+ (SerdWriteFunc)fwrite, (SerdCloseFunc)fclose, file);
}
SerdStatus
diff --git a/test/test_reader.c b/test/test_reader.c
index 37e645e3..d9edc294 100644
--- a/test/test_reader.c
+++ b/test/test_reader.c
@@ -202,7 +202,7 @@ test_read_eof_by_page(void)
SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0u, env, sink, 4096);
SerdInputStream in = serd_open_input_stream(
- (SerdReadFunc)fread, (SerdStreamErrorFunc)ferror, NULL, temp);
+ (SerdReadFunc)fread, (SerdErrorFunc)ferror, NULL, temp);
assert(serd_reader_start(reader, &in, NULL, 4096) == SERD_SUCCESS);
assert(serd_reader_read_chunk(reader) == SERD_SUCCESS);
@@ -230,11 +230,8 @@ test_read_eof_by_byte(void)
SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0u, env, sink, 4096);
size_t n_reads = 0u;
- SerdInputStream in =
- serd_open_input_stream((SerdReadFunc)eof_test_read,
- (SerdStreamErrorFunc)eof_test_error,
- NULL,
- &n_reads);
+ SerdInputStream in = serd_open_input_stream(
+ (SerdReadFunc)eof_test_read, (SerdErrorFunc)eof_test_error, NULL, &n_reads);
assert(serd_reader_start(reader, &in, NULL, 1) == SERD_SUCCESS);
assert(serd_reader_read_chunk(reader) == SERD_SUCCESS);
@@ -267,8 +264,8 @@ test_read_chunks(void)
assert(reader);
- SerdInputStream in = serd_open_input_stream(
- (SerdReadFunc)fread, (SerdStreamErrorFunc)ferror, NULL, f);
+ SerdInputStream in =
+ serd_open_input_stream((SerdReadFunc)fread, (SerdErrorFunc)ferror, NULL, f);
SerdStatus st = serd_reader_start(reader, &in, NULL, 1);
assert(st == SERD_SUCCESS);
@@ -336,8 +333,8 @@ test_read_empty(void)
assert(reader);
- SerdInputStream in = serd_open_input_stream(
- (SerdReadFunc)fread, (SerdStreamErrorFunc)ferror, NULL, f);
+ SerdInputStream in =
+ serd_open_input_stream((SerdReadFunc)fread, (SerdErrorFunc)ferror, NULL, f);
SerdStatus st = serd_reader_start(reader, &in, NULL, 1);
assert(!st);
diff --git a/tools/console.c b/tools/console.c
index 0e41a2a0..3b209273 100644
--- a/tools/console.c
+++ b/tools/console.c
@@ -358,7 +358,7 @@ serd_open_tool_input(const char* const filename)
{
if (!strcmp(filename, "-")) {
const SerdInputStream in = serd_open_input_stream(
- serd_file_read_byte, (SerdStreamErrorFunc)ferror, NULL, stdin);
+ serd_file_read_byte, (SerdErrorFunc)ferror, NULL, stdin);
serd_set_stream_utf8_mode(stdin);
return in;
@@ -373,7 +373,7 @@ serd_open_tool_output(const char* const filename)
if (!filename || !strcmp(filename, "-")) {
serd_set_stream_utf8_mode(stdout);
return serd_open_output_stream(
- (SerdWriteFunc)fwrite, (SerdStreamCloseFunc)fclose, stdout);
+ (SerdWriteFunc)fwrite, (SerdCloseFunc)fclose, stdout);
}
return serd_open_output_file(filename);