summaryrefslogtreecommitdiffstats
path: root/ffi
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2018-11-21 14:57:54 +0100
committerNeal H. Walfield <neal@pep.foundation>2018-11-22 08:55:31 +0100
commit0fad2b0ab90fc63306cd64be7e9de8524e47a30b (patch)
tree3be333fb59551fd10c2e2295490ef8bda26dd7f3 /ffi
parente968c1b5a3d1f319f59c2b4d0066fe63d9320473 (diff)
ffi: Add sq_writer_stack_write_all.
Diffstat (limited to 'ffi')
-rw-r--r--ffi/include/sequoia/openpgp.h13
-rw-r--r--ffi/src/openpgp.rs21
2 files changed, 33 insertions, 1 deletions
diff --git a/ffi/include/sequoia/openpgp.h b/ffi/include/sequoia/openpgp.h
index f09ff1ea..23959b4b 100644
--- a/ffi/include/sequoia/openpgp.h
+++ b/ffi/include/sequoia/openpgp.h
@@ -955,11 +955,22 @@ sq_writer_stack_t sq_writer_stack_message (sq_writer_t writer);
/*/
/// Writes up to `len` bytes of `buf` into `writer`.
-o/*/
+/*/
ssize_t sq_writer_stack_write (sq_context_t ctx, sq_writer_stack_t writer,
const uint8_t *buf, size_t len);
/*/
+/// Writes up to `len` bytes of `buf` into `writer`.
+///
+/// Unlike sq_writer_stack_write, unless an error occurs, the whole
+/// buffer will be written. Also, this version automatically catches
+/// EINTR.
+/*/
+sq_status_t sq_writer_stack_write_all (sq_context_t ctx,
+ sq_writer_stack_t writer,
+ const uint8_t *buf, size_t len);
+
+/*/
/// Finalizes this writer, returning the underlying writer.
/*/
sq_writer_stack_t sq_writer_stack_finalize_one (sq_context_t ctx,
diff --git a/ffi/src/openpgp.rs b/ffi/src/openpgp.rs
index 07bf359d..28cbc726 100644
--- a/ffi/src/openpgp.rs
+++ b/ffi/src/openpgp.rs
@@ -1593,6 +1593,27 @@ pub extern "system" fn sq_writer_stack_write
fry_or!(ctx, writer.write(buf).map_err(|e| e.into()), -1) as ssize_t
}
+/// Writes up to `len` bytes of `buf` into `writer`.
+///
+/// Unlike sq_writer_stack_write, unless an error occurs, the whole
+/// buffer will be written. Also, this version automatically catches
+/// EINTR.
+#[no_mangle]
+pub extern "system" fn sq_writer_stack_write_all
+ (ctx: Option<&mut Context>,
+ writer: Option<&mut writer::Stack<'static, Cookie>>,
+ buf: *const uint8_t, len: size_t)
+ -> Status
+{
+ let ctx = ctx.expect("Context is NULL");
+ let writer = writer.expect("Writer is NULL");
+ assert!(!buf.is_null());
+ let buf = unsafe {
+ slice::from_raw_parts(buf, len as usize)
+ };
+ fry_status!(ctx, writer.write_all(buf).map_err(|e| e.into()))
+}
+
/// Finalizes this writer, returning the underlying writer.
#[no_mangle]
pub extern "system" fn sq_writer_stack_finalize_one