Commit 66f1fd2ad9f2a4e3172bd07f6d71bb1321b0dce0

Authored by Jay Berkenbilt
1 parent b0f054e6

Switch user-supplied functions in C API to return int

examples/qpdfjob-c-save-attachment.c
@@ -12,11 +12,11 @@ @@ -12,11 +12,11 @@
12 // something with QPDFJob. See qpdfjob-c-save-attachment.c for an 12 // something with QPDFJob. See qpdfjob-c-save-attachment.c for an
13 // implementation that uses the C API. 13 // implementation that uses the C API.
14 14
15 -static void 15 +static int
16 save_to_file(char const* data, size_t len, void* udata) 16 save_to_file(char const* data, size_t len, void* udata)
17 { 17 {
18 FILE* f = (FILE*)udata; 18 FILE* f = (FILE*)udata;
19 - fwrite(data, 1, len, f); 19 + return fwrite(data, 1, len, f) != len;
20 } 20 }
21 21
22 static FILE* 22 static FILE*
include/qpdf/qpdflogger-c.h
@@ -59,7 +59,8 @@ extern "C" { @@ -59,7 +59,8 @@ extern "C" {
59 qpdf_log_dest_custom = 4, 59 qpdf_log_dest_custom = 4,
60 }; 60 };
61 61
62 - typedef void (*qpdf_log_fn_t)(char const* data, size_t len, void* udata); 62 + /* Function should return 0 on success. */
  63 + typedef int (*qpdf_log_fn_t)(char const* data, size_t len, void* udata);
63 64
64 QPDF_DLL 65 QPDF_DLL
65 void qpdflogger_set_info( 66 void qpdflogger_set_info(
libqpdf/qpdflogger-c.cc
@@ -56,12 +56,7 @@ set_log_dest( @@ -56,12 +56,7 @@ set_log_dest(
56 method(l->discard()); 56 method(l->discard());
57 break; 57 break;
58 case qpdf_log_dest_custom: 58 case qpdf_log_dest_custom:
59 - method(std::make_shared<Pl_Function>(  
60 - identifier,  
61 - nullptr,  
62 - [fn, udata](unsigned char const* data, size_t len) {  
63 - fn(reinterpret_cast<char const*>(data), len, udata);  
64 - })); 59 + method(std::make_shared<Pl_Function>(identifier, nullptr, fn, udata));
65 break; 60 break;
66 } 61 }
67 } 62 }
libtests/logger_c.c
@@ -8,11 +8,11 @@ @@ -8,11 +8,11 @@
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 10
11 -static void 11 +static int
12 fn(char const* data, size_t len, void* udata) 12 fn(char const* data, size_t len, void* udata)
13 { 13 {
14 FILE* f = (FILE*)udata; 14 FILE* f = (FILE*)udata;
15 - fwrite(data, 1, len, f); 15 + return fwrite(data, 1, len, f) != len;
16 } 16 }
17 17
18 static void 18 static void