aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Touhey <thomas@touhey.fr>2019-04-25 12:57:14 +0200
committerThomas Touhey <thomas@touhey.fr>2019-04-25 12:57:14 +0200
commit4dd0d638a993aadca4a8920b5b9d198e00534f06 (patch)
tree3e2c99b0b629edbd83e0393d36a5fec6915aed16
parent2974766ae3e6eb176529563f09d7e34d7835047b (diff)
Modified cdefs macros for functions and data
-rw-r--r--include/libtio.h6
-rw-r--r--include/libtio/cdefs.h26
-rw-r--r--include/libtio/error.h4
-rw-r--r--include/libtio/iter.h14
-rw-r--r--include/libtio/log.h12
-rw-r--r--include/libtio/native.h14
-rw-r--r--include/libtio/stream.h118
-rw-r--r--lib/alloc.c4
-rw-r--r--lib/error.c6
-rw-r--r--lib/exec.c9
-rw-r--r--lib/init.c16
-rw-r--r--lib/internals.h23
-rw-r--r--lib/iter.c12
-rw-r--r--lib/log/conv.c4
-rw-r--r--lib/log/iter.c14
-rw-r--r--lib/log/manage.c8
-rw-r--r--lib/log/mem.c6
-rw-r--r--lib/log/msg.c4
-rw-r--r--lib/stream/attrs.c2
-rw-r--r--lib/stream/builtin/libusb.c.draft37
-rw-r--r--lib/stream/builtin/limited.c10
-rw-r--r--lib/stream/builtin/memory.c14
-rw-r--r--lib/stream/builtin/std.c16
-rw-r--r--lib/stream/builtin/unix.c17
-rw-r--r--lib/stream/builtin/windows.c21
-rw-r--r--lib/stream/get.c14
-rw-r--r--lib/stream/open.c12
-rw-r--r--lib/stream/read.c2
-rw-r--r--lib/stream/read_tm.c2
-rw-r--r--lib/stream/scsi.c2
-rw-r--r--lib/stream/seek.c8
-rw-r--r--lib/stream/serial.c4
-rw-r--r--lib/stream/tm.c2
-rw-r--r--lib/stream/usb.c6
-rw-r--r--lib/stream/write.c2
-rw-r--r--lib/stream/write_tm.c2
36 files changed, 262 insertions, 211 deletions
diff --git a/include/libtio.h b/include/libtio.h
index efd7a94..1d0708b 100644
--- a/include/libtio.h
+++ b/include/libtio.h
@@ -10,12 +10,12 @@
/* Define what is required to use the library facilities. */
-TIO_EXTERN int TIO_EXPORT tio_check_version
+TIO_EXTERN(int) tio_check_version
OF((unsigned long version));
-TIO_EXTERN int TIO_EXPORT tio_init
+TIO_EXTERN(int) tio_init
OF((void));
-TIO_EXTERN void TIO_EXPORT tio_exit
+TIO_EXTERN(void) tio_exit
OF((void));
# define TIO_INIT \
diff --git a/include/libtio/cdefs.h b/include/libtio/cdefs.h
index a4a1854..bba459a 100644
--- a/include/libtio/cdefs.h
+++ b/include/libtio/cdefs.h
@@ -63,9 +63,19 @@
/* Some platforms require more than simply 'extern'.
* Here are macros to control this. */
-# define TIO_EXTERN extern
-# define TIO_EXPORT
-# define TIO_LOCAL static
+# define TIO_EXTERN(TYPE) \
+ extern TYPE
+# define TIO_NORETURN \
+ __attribute__((noreturn)) extern void
+# define TIO_LOCAL(TYPE) \
+ static TYPE
+# define TIO_HOOK(TYPE) \
+ static TYPE
+# define TIO_HOOK_TYPE(TYPE) \
+ TYPE
+
+# define TIO_LOCAL_DATA(TYPE) \
+ static TYPE
/* Also, libtio is made in C, so we might as well define what we want
* for C++. */
@@ -82,6 +92,12 @@
# define TIO_END_NAMESPACE
# endif
+/* Forward declare a structure. */
+
+# define TIO_STRUCT(STRUCT_NAME, STRUCT_TYPEDEF) \
+struct STRUCT_NAME; \
+typedef struct STRUCT_NAME STRUCT_TYPEDEF;
+
/* ---
* Native platform support.
* --- */
@@ -110,9 +126,9 @@ TIO_BEGIN_DECLS
/* Memory allocation utilities. */
-TIO_EXTERN void *TIO_EXPORT tio_alloc
+TIO_EXTERN(void *) tio_alloc
OF((size_t tio__count, size_t tio__size));
-TIO_EXTERN void TIO_EXPORT tio_free
+TIO_EXTERN(void) tio_free
OF((void *tio__mem));
TIO_END_DECLS
diff --git a/include/libtio/error.h b/include/libtio/error.h
index cca471b..6d6a63d 100644
--- a/include/libtio/error.h
+++ b/include/libtio/error.h
@@ -53,9 +53,9 @@ typedef int tio_error_t;
/* Get the error name or description. */
-TIO_EXTERN char const *TIO_EXPORT tio_error_name
+TIO_EXTERN(char const *) tio_error_name
OF((int tio__code));
-TIO_EXTERN char const *TIO_EXPORT tio_error_desc
+TIO_EXTERN(char const *) tio_error_desc
OF((int tio__code));
TIO_END_NAMESPACE
diff --git a/include/libtio/iter.h b/include/libtio/iter.h
index 7a4bdd5..89d3f0c 100644
--- a/include/libtio/iter.h
+++ b/include/libtio/iter.h
@@ -28,11 +28,11 @@ typedef struct tio_iter_functions tio_iter_functions_t;
* When `tio_end()` is called, the `tio_end_t` callback, if not NULL,
* will be called. */
-typedef int TIO_EXPORT tio_next_t
+typedef TIO_HOOK_TYPE(int) tio_next_t
OF((void *tio__cookie, void **tio__ptr));
-typedef void TIO_EXPORT tio_nextfree_t
+typedef TIO_HOOK_TYPE(void) tio_nextfree_t
OF((void *tio__cookie, void *tio__ptr));
-typedef void TIO_EXPORT tio_end_t
+typedef TIO_HOOK_TYPE(void) tio_end_t
OF((void *tio__cookie));
struct tio_iter_functions {
@@ -58,21 +58,21 @@ TIO_BEGIN_DECLS
* element might be free'd or re-used, so if you are interested in what is
* in it, copy the data before using one of the previous functions. */
-TIO_EXTERN int TIO_EXPORT tio_iter
+TIO_EXTERN(int) tio_iter
OF((tio_iter_t **tio__iterp, void *tio__cookie,
tio_iter_functions_t const *tio__funcs));
-TIO_EXTERN int TIO_EXPORT tio_next
+TIO_EXTERN(int) tio_next
OF((tio_iter_t *tio__iter, void **tio__ptr));
-TIO_EXTERN void TIO_EXPORT tio_end
+TIO_EXTERN(void) tio_end
OF((tio_iter_t *tio__iter));
/* You can make a “super iterator” that makes an iterator out of two
* iterators! It will empty the first one, then the second one.
* It will also take care of closing them. */
-TIO_EXTERN int TIO_EXPORT tio_combine_iterators
+TIO_EXTERN(int) tio_combine_iterators
OF((tio_iter_t **tio__iterp,
tio_iter_t *tio__first,
tio_iter_t *tio__second));
diff --git a/include/libtio/log.h b/include/libtio/log.h
index fb18e07..2882566 100644
--- a/include/libtio/log.h
+++ b/include/libtio/log.h
@@ -8,23 +8,23 @@ TIO_BEGIN_DECLS
/* Get and set the log level at runtime. */
-TIO_EXTERN void TIO_EXPORT tio_setlog
+TIO_EXTERN(void) tio_setlog
OF((char const *tio__level));
-TIO_EXTERN char const *TIO_EXPORT tio_getlog
+TIO_EXTERN(char const *) tio_getlog
OF((void));
/* List log levels (deprecated interface) */
-typedef void tio_log_list_t OF((void *tio__cookie,
- char const *tio__str));
+typedef TIO_HOOK_TYPE(void) tio_log_list_t
+ OF((void *tio__cookie, char const *tio__str));
-TIO_EXTERN TIO_DEPRECATED void TIO_EXPORT tio_listlog
+TIO_DEPRECATED TIO_EXTERN(void) tio_listlog
OF((tio_log_list_t *tio__callback, void *tio__cookie));
/* List log levels (new interface).
* This iterator yields strings (`const char *`). */
-TIO_EXTERN int TIO_EXPORT tio_iter_log
+TIO_EXTERN(int) tio_iter_log
OF((tio_iter_t **tio__iter));
# define tio_next_log(ITER, PTRP) (tio_next((ITER), (void **)(PTRP)))
diff --git a/include/libtio/native.h b/include/libtio/native.h
index 84aae12..0b7e899 100644
--- a/include/libtio/native.h
+++ b/include/libtio/native.h
@@ -10,7 +10,7 @@ TIO_BEGIN_DECLS
# if !defined(LIBTIO_DISABLED_UNIX)
-TIO_EXTERN int TIO_EXPORT tio_open_unix_fd
+TIO_EXTERN(int) tio_open_unix_fd
OF((tio_stream_t **tio__streamp, int tio__fd, int tio__close));
# endif
@@ -20,9 +20,9 @@ TIO_EXTERN int TIO_EXPORT tio_open_unix_fd
# ifndef LIBTIO_DISABLED_LIBUSB
# include <libusb.h>
-TIO_EXTERN int TIO_EXPORT tio_open_libusb
+TIO_EXTERN(int) tio_open_libusb
OF((tio_stream_t **streamp, int bus, int addr));
-TIO_EXTERN int TIO_EXPORT tio_open_libusb_device
+TIO_EXTERN(int) tio_open_libusb_device
OF((tio_stream_t **streamp, libusb_device_handle *handle));
# endif
@@ -32,15 +32,15 @@ TIO_EXTERN int TIO_EXPORT tio_open_libusb_device
# ifndef LIBTIO_DISABLED_FILE
# include <stdio.h>
-TIO_EXTERN int TIO_EXPORT tio_open_std
+TIO_EXTERN(int) tio_open_std
OF((tio_stream_t **tio__stream,
FILE *tio__fl, int tio__close));
-TIO_EXTERN int TIO_EXPORT tio_open_stdout
+TIO_EXTERN(int) tio_open_stdout
OF((tio_stream_t **tio__stream));
-TIO_EXTERN int TIO_EXPORT tio_open_stderr
+TIO_EXTERN(int) tio_open_stderr
OF((tio_stream_t **tio__stream));
-TIO_EXTERN int TIO_EXPORT tio_open_stdin
+TIO_EXTERN(int) tio_open_stdin
OF((tio_stream_t **tio__stream));
# endif
diff --git a/include/libtio/stream.h b/include/libtio/stream.h
index d58fd41..aec0e4f 100644
--- a/include/libtio/stream.h
+++ b/include/libtio/stream.h
@@ -13,24 +13,16 @@ TIO_BEGIN_NAMESPACE
* written, but not all of it), you shall return an error, because there
* is no partial success. */
-struct tio_stream;
-typedef struct tio_stream tio_stream_t;
-struct tio_timeouts;
-typedef struct tio_timeouts tio_timeouts_t;
-
-struct tio_serial_attrs;
-typedef struct tio_serial_attrs tio_serial_attrs_t;
-struct tio_scsi_request;
-typedef struct tio_scsi_request tio_scsi_request_t;
-
-struct tio_functions;
-typedef struct tio_functions tio_functions_t;
-struct tio_serial_functions;
-typedef struct tio_serial_functions tio_serial_functions_t;
-struct tio_usb_functions;
-typedef struct tio_usb_functions tio_usb_functions_t;
-struct tio_scsi_functions;
-typedef struct tio_scsi_functions tio_scsi_functions_t;
+TIO_STRUCT(tio_stream, tio_stream_t)
+TIO_STRUCT(tio_timeouts, tio_timeouts_t)
+
+TIO_STRUCT(tio_serial_attrs, tio_serial_attrs_t)
+TIO_STRUCT(tio_scsi_request, tio_scsi_request_t)
+
+TIO_STRUCT(tio_functions, tio_functions_t)
+TIO_STRUCT(tio_serial_functions, tio_serial_functions_t)
+TIO_STRUCT(tio_usb_functions, tio_usb_functions_t)
+TIO_STRUCT(tio_scsi_functions, tio_scsi_functions_t)
/* Timeouts. */
@@ -291,39 +283,39 @@ struct tio_scsi_request {
* (some are common to several types of stream). All the structures have
* the `close` callback first. */
-typedef void tio_close_t
+typedef TIO_HOOK_TYPE(void) tio_close_t
OF((void *));
-typedef int tio_read_t
+typedef TIO_HOOK_TYPE(int) tio_read_t
OF((void *, unsigned char *, size_t));
-typedef int tio_read_tm_t
+typedef TIO_HOOK_TYPE(int) tio_read_tm_t
OF((void *, unsigned char *, size_t,
tio_timeouts_t const *));
-typedef int tio_write_t
+typedef TIO_HOOK_TYPE(int) tio_write_t
OF((void *, unsigned char const *, size_t));
-typedef int tio_write_tm_t
+typedef TIO_HOOK_TYPE(int) tio_write_tm_t
OF((void *, unsigned char const *, size_t,
tio_timeouts_t const *));
-typedef int tio_set_tm_t
+typedef TIO_HOOK_TYPE(int) tio_set_tm_t
OF((void *,
tio_timeouts_t const * /* read */,
tio_timeouts_t const * /* write */));
-typedef int tio_seek_t
+typedef TIO_HOOK_TYPE(int) tio_seek_t
OF((void *, tio_off_t *, tio_whence_t));
-typedef int tio_set_serial_attrs_t
+typedef TIO_HOOK_TYPE(int) tio_set_serial_attrs_t
OF((void *, tio_serial_attrs_t const *));
-typedef int tio_scsi_t
+typedef TIO_HOOK_TYPE(int) tio_scsi_t
OF((void *, tio_scsi_request_t *));
-typedef int tio_usb_send_bulk_t
+typedef TIO_HOOK_TYPE(int) tio_usb_send_bulk_t
OF((void *, unsigned char const *, size_t,
unsigned int /* total timeout in ms */));
-typedef int tio_usb_recv_bulk_t
+typedef TIO_HOOK_TYPE(int) tio_usb_recv_bulk_t
OF((void *, unsigned char *, size_t,
unsigned int /* total timeout in ms */));
@@ -376,7 +368,7 @@ TIO_BEGIN_DECLS
/* Default stream serial settings utilities. */
-TIO_EXTERN int TIO_EXPORT tio_make_serial_attrs
+TIO_EXTERN(int) tio_make_serial_attrs
OF((tio_serial_attrs_t *tio__attrs, char const *tio__raw));
/* Open and close a stream.
@@ -387,37 +379,37 @@ TIO_EXTERN int TIO_EXPORT tio_make_serial_attrs
* `tio__over` stream if present, so that you can still access USB
* functions behind an SCSI stream for example. */
-TIO_EXTERN int TIO_EXPORT tio_open
+TIO_EXTERN(int) tio_open
OF((tio_stream_t **tio__streamp, tio_stream_t *tio__parent,
void *tio__cookie, unsigned int tio__flags,
tio_functions_t const *tio__functions, tio_off_t tio__offset));
-TIO_EXTERN int TIO_EXPORT tio_open_serial
+TIO_EXTERN(int) tio_open_serial
OF((tio_stream_t **tio__streamp, tio_stream_t *tio__parent,
void *tio__cookie, unsigned int tio__flags,
tio_serial_functions_t const *tio__functions,
tio_serial_attrs_t const *tio__attrs));
-TIO_EXTERN int TIO_EXPORT tio_open_usb
+TIO_EXTERN(int) tio_open_usb
OF((tio_stream_t **tio__streamp, tio_stream_t *tio__parent,
void *tio__cookie, unsigned int tio__flags,
tio_usb_functions_t const *tio__functions));
-TIO_EXTERN int TIO_EXPORT tio_open_scsi
+TIO_EXTERN(int) tio_open_scsi
OF((tio_stream_t **tio__streamp, tio_stream_t *tio__parent,
void *tio__cookie, unsigned int tio__flags,
tio_scsi_functions_t const *tio__functions));
-TIO_EXTERN void TIO_EXPORT tio_close
+TIO_EXTERN(void) tio_close
OF((tio_stream_t *tio__stream));
/* Get various stream data. */
-TIO_EXTERN int TIO_EXPORT tio_isreadable
+TIO_EXTERN(int) tio_isreadable
OF((tio_stream_t *tio__stream));
-TIO_EXTERN int TIO_EXPORT tio_iswritable
+TIO_EXTERN(int) tio_iswritable
OF((tio_stream_t *tio__stream));
-TIO_EXTERN int TIO_EXPORT tio_isseekable
+TIO_EXTERN(int) tio_isseekable
OF((tio_stream_t *tio__stream));
# define tio_is_readable(TIO__STREAM) \
@@ -427,81 +419,81 @@ TIO_EXTERN int TIO_EXPORT tio_isseekable
# define tio_is_seekable(TIO__STREAM) \
tio_isseekable(TIO__STREAM)
-TIO_EXTERN int TIO_EXPORT tio_has_read_timeouts
+TIO_EXTERN(int) tio_has_read_timeouts
OF((tio_stream_t *tio__stream));
-TIO_EXTERN int TIO_EXPORT tio_has_write_timeouts
+TIO_EXTERN(int) tio_has_write_timeouts
OF((tio_stream_t *tio__stream));
-TIO_EXTERN int TIO_EXPORT tio_get_type
+TIO_EXTERN(int) tio_get_type
OF((tio_stream_t *tio__stream));
-TIO_EXTERN void *TIO_EXPORT tio_get_cookie
+TIO_EXTERN(void *) tio_get_cookie
OF((tio_stream_t *tio__stream));
-TIO_EXTERN int TIO_EXPORT tio_get_lasterr
+TIO_EXTERN(int) tio_get_lasterr
OF((tio_stream_t *tio__stream));
-TIO_EXTERN int TIO_EXPORT tio_get_parent
+TIO_EXTERN(int) tio_get_parent
OF((tio_stream_t *tio__stream, tio_stream_t **tio__parent));
/* Read and write data from and to a stream.
* Timeouts are in milliseconds (ms). */
-TIO_EXTERN int TIO_EXPORT tio_read
+TIO_EXTERN(int) tio_read
OF((tio_stream_t *tio__stream, void *tio__dest,
size_t tio__count));
-TIO_EXTERN int TIO_EXPORT tio_read_tm
+TIO_EXTERN(int) tio_read_tm
OF((tio_stream_t *tio__stream, void *tio__dest,
size_t tio__count, tio_timeouts_t const *tio__tm));
-TIO_EXTERN int TIO_EXPORT tio_write
+TIO_EXTERN(int) tio_write
OF((tio_stream_t *tio__stream, void const *tio__data,
size_t tio__count));
-TIO_EXTERN int TIO_EXPORT tio_write_tm
+TIO_EXTERN(int) tio_write_tm
OF((tio_stream_t *tio__stream, void const *tio__data,
size_t tio__count, tio_timeouts_t const *tio__tm));
-TIO_EXTERN int TIO_EXPORT tio_write_char
+TIO_EXTERN(int) tio_write_char
OF((tio_stream_t *tio__stream, int tio__char));
/* Move within a stream. */
-TIO_EXTERN int TIO_EXPORT tio_seek
+TIO_EXTERN(int) tio_seek
OF((tio_stream_t *tio__stream,
tio_off_t tio__offset, tio_whence_t tio__whence));
-TIO_EXTERN tio_off_t TIO_EXPORT tio_tell
+TIO_EXTERN(tio_off_t) tio_tell
OF((tio_stream_t *tio__stream));
-TIO_EXTERN int TIO_EXPORT tio_skip
+TIO_EXTERN(int) tio_skip
OF((tio_stream_t *tio__stream, tio_off_t tio__size));
-TIO_EXTERN int TIO_EXPORT tio_get_size
+TIO_EXTERN(int) tio_get_size
OF((tio_stream_t *tio__stream, tio_off_t *tio__size));
/* Set and get the serial attributes of a stream. */
-TIO_EXTERN int TIO_EXPORT tio_set_serial_attrs
+TIO_EXTERN(int) tio_set_serial_attrs
OF((tio_stream_t *tio__stream, unsigned int tio__flags,
tio_serial_attrs_t const *tio__attrs));
-TIO_EXTERN int TIO_EXPORT tio_get_serial_attrs
+TIO_EXTERN(int) tio_get_serial_attrs
OF((tio_stream_t *tio__stream, unsigned int tio__flags,
tio_serial_attrs_t *tio__attrs));
/* Set the timeouts of a stream. */
-TIO_EXTERN int TIO_EXPORT tio_set_timeouts
+TIO_EXTERN(int) tio_set_timeouts
OF((tio_stream_t *tio__stream,
tio_timeouts_t const *tio__read,
tio_timeouts_t const *tio__write));
/* Make USB-related operations. */
-TIO_EXTERN int TIO_EXPORT tio_usb_send_bulk
+TIO_EXTERN(int) tio_usb_send_bulk
OF((tio_stream_t *tio__stream, unsigned char const *tio__data,
size_t tio__size, unsigned int tio__timeout));
-TIO_EXTERN int TIO_EXPORT tio_usb_recv_bulk
+TIO_EXTERN(int) tio_usb_recv_bulk
OF((tio_stream_t *tio__stream, unsigned char *tio__buf,
size_t tio__size, unsigned int tio__timeout));
/* Make an SCSI request. */
-TIO_EXTERN int TIO_EXPORT tio_scsi_request
+TIO_EXTERN(int) tio_scsi_request
OF((tio_stream_t *tio__stream, tio_scsi_request_t *tio__request));
/* ---
@@ -510,19 +502,19 @@ TIO_EXTERN int TIO_EXPORT tio_scsi_request
/* Make a stream out of memory. */
-TIO_EXTERN int TIO_EXPORT tio_open_memory
+TIO_EXTERN(int) tio_open_memory
OF((tio_stream_t **tio__stream,
void *tio__zone, size_t tio__size));
-TIO_EXTERN int TIO_EXPORT tio_open_readonly_memory
+TIO_EXTERN(int) tio_open_readonly_memory
OF((tio_stream_t **tio__stream,
void const *tio__zone, size_t tio__size));
/* Make a stream out of another, with a limit (and empty it). */
-TIO_EXTERN int TIO_EXPORT tio_open_limited
+TIO_EXTERN(int) tio_open_limited
OF((tio_stream_t **tio__stream,
tio_stream_t *tio__original, size_t tio__limit));
-TIO_EXTERN int TIO_EXPORT tio_empty_limited
+TIO_EXTERN(int) tio_empty_limited
OF((tio_stream_t *tio__stream));
TIO_END_DECLS
diff --git a/lib/alloc.c b/lib/alloc.c
index 64992b2..ec8b6a4 100644
--- a/lib/alloc.c
+++ b/lib/alloc.c
@@ -3,14 +3,14 @@
/* `tio_alloc()`: allocate memory dynamically. */
-TIO_EXTERN void *TIO_EXPORT tio_alloc(size_t count, size_t size)
+TIO_EXTERN(void *) tio_alloc(size_t count, size_t size)
{
return (calloc(count, size));
}
/* `tio_free()`: free allocated memory. */
-TIO_EXTERN void TIO_EXPORT tio_free(void *mem)
+TIO_EXTERN(void) tio_free(void *mem)
{
free(mem);
}
diff --git a/lib/error.c b/lib/error.c
index e05fa8a..bad0620 100644
--- a/lib/error.c
+++ b/lib/error.c
@@ -5,7 +5,7 @@
#define ARR_SIZE 0x18
#define UNKNOWN NULL, NULL
-char const *errors[] = {
+TIO_LOCAL_DATA(char const *) errors[] = {
"tio_error_none", "everything is okay",
"tio_error_unknown", "an unknown error has occurred",
"tio_error_alloc", "a memory allocation has failed",
@@ -33,7 +33,7 @@ char const *errors[] = {
/* `tio_error_name()`: get the error name. */
-char const *TIO_EXPORT tio_error_name(int code)
+TIO_EXTERN(char const *) tio_error_name(int code)
{
char const *nm;
@@ -44,7 +44,7 @@ char const *TIO_EXPORT tio_error_name(int code)
/* `tio_error_desc()`: get the error description. */
-char const *TIO_EXPORT tio_error_desc(int code)
+TIO_EXTERN(char const *) tio_error_desc(int code)
{
char const *ds;
diff --git a/lib/exec.c b/lib/exec.c
index fbbb88f..313ff75 100644
--- a/lib/exec.c
+++ b/lib/exec.c
@@ -8,7 +8,7 @@
* The message that should be displayed when the library is executed.
*/
-TIO_LOCAL char const version_message[] =
+TIO_LOCAL_DATA(char const) version_message[] =
"libtio v" LIBTIO_VERSION " (licensed under LGPL3)\n"
"Maintained by " LIBTIO_MAINTAINER ".\n"
"\n"
@@ -21,9 +21,10 @@ TIO_LOCAL char const version_message[] =
* Display version when the library is executed.
*/
-extern void libtio__version(void)
- __attribute__((noreturn));
-void libtio__version(void)
+TIO_NORETURN libtio__version
+ OF((void));
+
+TIO_NORETURN libtio__version(void)
{
puts(version_message);
_exit(0);
diff --git a/lib/init.c b/lib/init.c
index d720f6c..0f754c9 100644
--- a/lib/init.c
+++ b/lib/init.c
@@ -2,7 +2,7 @@
#define EX_COUNT 16
struct exit_node {
- void (*func)(void *);
+ tio_exit_t *func;
void *cookie;
};
@@ -13,13 +13,13 @@ struct exit_queue_chunk {
struct exit_node nodes[EX_COUNT];
};
-int tio_initialized = 0;
-struct exit_queue_chunk tio_exit_queue_first_node;
-struct exit_queue_chunk *tio_exit_queue;
+TIO_LOCAL_DATA(int) tio_initialized = 0;
+TIO_LOCAL_DATA(struct exit_queue_chunk) tio_exit_queue_first_node;
+TIO_LOCAL_DATA(struct exit_queue_chunk *) tio_exit_queue;
/* `tio_init()`: initialize libtio. */
-int TIO_EXPORT tio_init(void)
+TIO_EXTERN(int) tio_init(void)
{
if (tio_initialized)
return (0);
@@ -35,7 +35,7 @@ int TIO_EXPORT tio_init(void)
/* `tio_exit()`: exit libtio. */
-void TIO_EXPORT tio_exit(void)
+TIO_EXTERN(void) tio_exit(void)
{
/* Nothing for now. */
@@ -59,7 +59,7 @@ void TIO_EXPORT tio_exit(void)
/* `tio_add_exit()`: add an exit function. */
-int TIO_EXPORT tio_add_exit(void (*func)(void *), void *cookie)
+TIO_EXTERN(int) tio_add_exit(void (*func)(void *), void *cookie)
{
if (tio_exit_queue->count == EX_COUNT) {
struct exit_queue_chunk *chunk;
@@ -88,7 +88,7 @@ int TIO_EXPORT tio_add_exit(void (*func)(void *), void *cookie)
* If both are 0.x, check that the subversions are the same.
* Otherwise, check that the major versions are the same. */
-int TIO_EXPORT tio_check_version(unsigned long version)
+TIO_EXTERN(int) tio_check_version(unsigned long version)
{
if ((version | LIBTIO_VERNUM) & 0xFF000000) {
if ((version ^ LIBTIO_VERNUM) & 0xFF000000) {
diff --git a/lib/internals.h b/lib/internals.h
index 3f1901f..8cc7991 100644
--- a/lib/internals.h
+++ b/lib/internals.h
@@ -8,8 +8,11 @@
((TIO__A) > (TIO__B) ? (TIO__B) : (TIO__A))
# endif
-int TIO_EXPORT tio_add_exit
- OF((void (*func)(void *), void *cookie));
+typedef TIO_HOOK_TYPE(void) tio_exit_t
+ OF((void *));
+
+TIO_EXTERN(int) tio_add_exit
+ OF((tio_exit_t func, void *cookie));
/* ---
* Logging system.
@@ -106,33 +109,33 @@ typedef int tio_loglevel_t;
/* Conversion functions between strings and numbers.
* Strings are for the external API, numbers for the internal one. */
-TIO_EXTERN char const *TIO_EXPORT tio_loglevel_tostring
+TIO_EXTERN(char const *) tio_loglevel_tostring
OF((tio_loglevel_t tio__level));
-TIO_EXTERN tio_loglevel_t TIO_EXPORT tio_loglevel_fromstring
+TIO_EXTERN(tio_loglevel_t) tio_loglevel_fromstring
OF((const char *tio__string));
/* Here are the main functions. Don't use them directly, prefer the
* `msg` and `mem` macros as they are sensible to the fact that logging
* is enabled or not. */
-TIO_EXTERN int TIO_EXPORT tio_islog
+TIO_EXTERN(int) tio_islog
OF((tio_loglevel_t tio__level, char const *tio__func));
-TIO_EXTERN void TIO_EXPORT tio_log_prefix
+TIO_EXTERN(void) tio_log_prefix
OF((tio_loglevel_t tio__loglevel, char const *tio__func));
# if defined(__STDC__) && __STDC__
-TIO_EXTERN void TIO_EXPORT tio_log_msg
+TIO_EXTERN(void) tio_log_msg
(tio_loglevel_t tio__loglevel, char const *tio__func,
char const *tio__format, ...);
-TIO_EXTERN void TIO_EXPORT tio_log_mem
+TIO_EXTERN(void) tio_log_mem
(tio_loglevel_t tio__loglevel, char const *tio__func,
void const *tio__m, size_t tio__n);
# else
-TIO_EXTERN void TIO_EXPORT tio_log_msg();
-TIO_EXTERN void TIO_EXPORT tio_log_mem();
+TIO_EXTERN(void) tio_log_msg();
+TIO_EXTERN(void) tio_log_mem();
# endif
# endif
diff --git a/lib/iter.c b/lib/iter.c
index db2a44a..6c4f07d 100644
--- a/lib/iter.c
+++ b/lib/iter.c
@@ -15,7 +15,7 @@ struct tio_iter {
/* `default_next()`: default next callback. */
-TIO_LOCAL int default_next(void *cookie, void **ptr)
+TIO_HOOK(int) default_next(void *cookie, void **ptr)
{
(void)cookie;
(void)ptr;
@@ -25,7 +25,7 @@ TIO_LOCAL int default_next(void *cookie, void **ptr)
/* `default_nextfree()`: default nextfree callback. */
-TIO_LOCAL void default_nextfree(void *cookie, void *ptr)
+TIO_HOOK(void) default_nextfree(void *cookie, void *ptr)
{
/* Do not free. */
@@ -35,14 +35,14 @@ TIO_LOCAL void default_nextfree(void *cookie, void *ptr)
/* `default_end()`: default iterator ending function. */
-TIO_LOCAL void default_end(void *cookie)
+TIO_HOOK(void) default_end(void *cookie)
{
(void)cookie;
}
/* `tio_iter()`: create an iterator. */
-int TIO_EXPORT tio_iter(tio_iter_t **iterp, void *cookie,
+TIO_EXTERN(int) tio_iter(tio_iter_t **iterp, void *cookie,
tio_iter_functions_t const *funcs)
{
tio_iter_t *iter;
@@ -77,7 +77,7 @@ int TIO_EXPORT tio_iter(tio_iter_t **iterp, void *cookie,
/* `tio_next()`: get the next element from an iterator. */
-int TIO_EXPORT tio_next(tio_iter_t *iter, void **ptrp)
+TIO_EXTERN(int) tio_next(tio_iter_t *iter, void **ptrp)
{
int err;
@@ -103,7 +103,7 @@ int TIO_EXPORT tio_next(tio_iter_t *iter, void **ptrp)
/* `tio_end()`: end and free an iterator. */
-void TIO_EXPORT tio_end(tio_iter_t *iter)
+TIO_EXTERN(void) tio_end(tio_iter_t *iter)
{
if (iter->tio_iter_has_last) {
(*iter->tio_iter_nextfree)(iter->tio_iter_cookie, iter->tio_iter_last);
diff --git a/lib/log/conv.c b/lib/log/conv.c
index 3edf86f..1fe0893 100644
--- a/lib/log/conv.c
+++ b/lib/log/conv.c
@@ -3,7 +3,7 @@
/* `tio_loglevel_tostring()`: make a string out of a log level. */
-char const *TIO_EXPORT tio_loglevel_tostring(tio_loglevel_t level)
+TIO_EXTERN(char const *) tio_loglevel_tostring(tio_loglevel_t level)
{
if (level >= 0 && level < 10)
return ("info");
@@ -18,7 +18,7 @@ char const *TIO_EXPORT tio_loglevel_tostring(tio_loglevel_t level)
/* `tio_loglevel_fromstring()`: make a log level out of a string. */
-tio_loglevel_t TIO_EXPORT tio_loglevel_fromstring(char const *string)
+TIO_EXTERN(tio_loglevel_t) tio_loglevel_fromstring(char const *string)
{
if (!strcmp(string, "info"))
return (tio_loglevel_info);
diff --git a/lib/log/iter.c b/lib/log/iter.c
index 1c74687..9d363a0 100644
--- a/lib/log/iter.c
+++ b/lib/log/iter.c
@@ -1,6 +1,6 @@
#include "../internals.h"
-TIO_LOCAL const char *log_levels[] = {
+TIO_LOCAL_DATA(const char *) log_levels[] = {
"none",
#if !defined(LIBTIO_DISABLED_LOG)
"info",
@@ -13,7 +13,7 @@ TIO_LOCAL const char *log_levels[] = {
/* `next_log()`: next log level. */
-TIO_LOCAL int TIO_EXPORT next_log(const char ***cookie, const char **level)
+TIO_HOOK(int) next_log(const char ***cookie, const char **level)
{
if (!**cookie)
return (tio_error_iter);
@@ -24,14 +24,14 @@ TIO_LOCAL int TIO_EXPORT next_log(const char ***cookie, const char **level)
/* `end_log_iter()`: end the iteration log. */
-TIO_LOCAL void TIO_EXPORT end_log_iter(char const ***cookie)
+TIO_HOOK(void) end_log_iter(char const ***cookie)
{
tio_free(cookie);
}
/* Functions. */
-TIO_LOCAL tio_iter_functions_t log_funcs = {
+TIO_LOCAL_DATA(tio_iter_functions_t) log_funcs = {
(tio_next_t *)next_log,
NULL,
(tio_end_t *)end_log_iter
@@ -39,9 +39,9 @@ TIO_LOCAL tio_iter_functions_t log_funcs = {
/* `tio_iter_log()`: make a loglevels iterator. */
-int TIO_EXPORT tio_iter_log(tio_iter_t **iterp)
+TIO_EXTERN(int) tio_iter_log(tio_iter_t **iterp)
{
- const char ***ptr;
+ char const ***ptr;
ptr = tio_alloc(1, sizeof(char **));
if (!ptr)
@@ -57,7 +57,7 @@ int TIO_EXPORT tio_iter_log(tio_iter_t **iterp)
/* `tio_listlog()`: list log levels. */
-void TIO_EXPORT tio_listlog(tio_log_list_t *callback, void *cookie)
+TIO_EXTERN(void) tio_listlog(tio_log_list_t *callback, void *cookie)
{
tio_iter_t *iter;
const char *level;
diff --git a/lib/log/manage.c b/lib/log/manage.c
index 30c5d44..1192402 100644
--- a/lib/log/manage.c
+++ b/lib/log/manage.c
@@ -3,13 +3,13 @@
/* The log setting. */
-TIO_LOCAL tio_loglevel_t log_setting = LOGLEVEL;
+TIO_LOCAL_DATA(tio_loglevel_t) log_setting = LOGLEVEL;
#endif
/* `tio_setlog()`: set the log level at runtime. */
-void TIO_EXPORT tio_setlog(char const *level)
+TIO_EXTERN(void) tio_setlog(char const *level)
{
#if !defined(LIBTIO_DISABLED_LOG)
log_setting = tio_loglevel_fromstring(level);
@@ -20,7 +20,7 @@ void TIO_EXPORT tio_setlog(char const *level)
/* `tio_getlog()`: get the log level at runtime. */
-char const *TIO_EXPORT tio_getlog(void)
+TIO_EXTERN(char const *) tio_getlog(void)
{
#if !defined(LIBTIO_DISABLED_LOG)
return (tio_loglevel_tostring(log_setting));
@@ -33,7 +33,7 @@ char const *TIO_EXPORT tio_getlog(void)
/* `tio_islog()`: get the log level out of the `ll_*` tuples. */
-int TIO_EXPORT tio_islog(tio_loglevel_t level, char const *func)
+TIO_EXTERN(int) tio_islog(tio_loglevel_t level, char const *func)
{
(void)func;
return (log_setting <= level);
diff --git a/lib/log/mem.c b/lib/log/mem.c
index 8546e59..815c46d 100644
--- a/lib/log/mem.c
+++ b/lib/log/mem.c
@@ -6,7 +6,7 @@
/* `log_mem_hex()`: prints the octal interpretation of a max of
* two bytes. */
-TIO_LOCAL void log_mem_hex(char *s, const unsigned char *m, size_t n)
+TIO_LOCAL(void) log_mem_hex(char *s, const unsigned char *m, size_t n)
{
size_t l = 0;
@@ -32,7 +32,7 @@ TIO_LOCAL void log_mem_hex(char *s, const unsigned char *m, size_t n)
/* `log_mem_asc()`: prints the ASCII representation of a max of two bytes. */
-TIO_LOCAL void log_mem_asc(char *s, unsigned char const *m, size_t n)
+TIO_LOCAL(void) log_mem_asc(char *s, unsigned char const *m, size_t n)
{
size_t l = 0;
@@ -53,7 +53,7 @@ TIO_LOCAL void log_mem_asc(char *s, unsigned char const *m, size_t n)
/* `tio_log_mem()`: print the contents of a memory zone. */
-void TIO_EXPORT tio_log_mem(tio_loglevel_t loglevel, char const *func,
+TIO_EXTERN(void) tio_log_mem(tio_loglevel_t loglevel, char const *func,
void const *m, size_t n)
{
char linebuf[58];
diff --git a/lib/log/msg.c b/lib/log/msg.c
index 0d80c90..4848fa3 100644
--- a/lib/log/msg.c
+++ b/lib/log/msg.c
@@ -5,7 +5,7 @@
/* `tio_log_prefix()`: put the prefix. */
-void TIO_EXPORT tio_log_prefix(tio_loglevel_t loglevel, char const *func)
+TIO_EXTERN(void) tio_log_prefix(tio_loglevel_t loglevel, char const *func)
{
if (func && !strncmp(func, "tio_", 6))
func = &func[6];
@@ -18,7 +18,7 @@ void TIO_EXPORT tio_log_prefix(tio_loglevel_t loglevel, char const *func)
/* `tio_log_msg()`: log a simple message with a printf-like format. */
-void TIO_EXPORT tio_log_msg(tio_loglevel_t loglevel,
+TIO_EXTERN(void) tio_log_msg(tio_loglevel_t loglevel,
char const *func, char const *format, ...)
{
va_list args;
diff --git a/lib/stream/attrs.c b/lib/stream/attrs.c
index 5e7ddfe..67ae7d4 100644
--- a/lib/stream/attrs.c
+++ b/lib/stream/attrs.c
@@ -6,7 +6,7 @@
/* `tio_make_serial_attrs()`: make serial attributes out of an attributes
* string. */
-int TIO_EXPORT tio_make_serial_attrs(tio_serial_attrs_t *attrs,
+TIO_EXTERN(int) tio_make_serial_attrs(tio_serial_attrs_t *attrs,
char const *raw)
{
unsigned int speed;
diff --git a/lib/stream/builtin/libusb.c.draft b/lib/stream/builtin/libusb.c.draft
index 43f692d..122859d 100644
--- a/lib/stream/builtin/libusb.c.draft
+++ b/lib/stream/builtin/libusb.c.draft
@@ -2,16 +2,51 @@
#ifndef LIBTIO_DISABLED_LIBUSB
# include <libusb.h>
+/* `free_context()`: free the libusb context passed as a `void *`. */
+
+TIO_HOOK(void) free_context(void *vcontext)
+{
+ libusb_exit((libusb_context *)context);
+}
+
+/* `get_context()`: get the default libusb context. */
+
+TIO_LOCAL libusb_context *tio_libusb_context = NULL;
+
+TIO_LOCAL int get_context(libusb_context **context)
+{
+ libusb_context *ctx;
+ int lerr, err;
+
+ if (tio_libusb_context) {
+ *context = tio_libusb_context;
+ return (tio_ok);
+ }
+
+ if ((lerr = libusb_init(&ctx)))
+ return (tio_error_unknown);
+ if ((err = tio_add_exit(free_context, ctx))) {
+ libusb_exit(&ctx);
+ return (err);
+ }
+
+ tio_libusb_context = ctx;
+ *context = ctx;
+ return (tio_ok);
+}
+
/* `find_descriptor()`: find a descriptor out of bus/host number. */
TIO_LOCAL int find_descriptor(int bus, int addr,
libusb_device *device, struct libusb_device_descriptor *descp)
{
- libusb_context *context = NULL;
+ libusb_context *ctx = NULL;
int device_count, err;
/* Open up the context. */
+ if ((err = get_context(&ctx)
+
if (libusb_init(&context)) {
msg((ll_fatal, "Couldn't create a libusb context."));
err = tio_error_alloc;
diff --git a/lib/stream/builtin/limited.c b/lib/stream/builtin/limited.c
index 57a9fa4..8f16d0c 100644
--- a/lib/stream/builtin/limited.c
+++ b/lib/stream/builtin/limited.c
@@ -14,7 +14,7 @@ typedef struct {
/* `tio_limited_read()`: read from a limited stream. */
-TIO_LOCAL int tio_limited_read(void *vcookie, unsigned char *dest,
+TIO_HOOK(int) tio_limited_read(void *vcookie, unsigned char *dest,
size_t count)
{
limited_cookie_t *cookie = (void*)vcookie;
@@ -46,14 +46,14 @@ TIO_LOCAL int tio_limited_read(void *vcookie, unsigned char *dest,
/* `tio_limited_close()`: close a limited stream. */
-TIO_LOCAL void tio_limited_close(void *vcookie)
+TIO_HOOK(void) tio_limited_close(void *vcookie)
{
tio_free(vcookie);
}
/* Callbacks. */
-TIO_LOCAL const tio_functions_t tio_limited_callbacks = {
+TIO_LOCAL_DATA(tio_functions_t const) tio_limited_callbacks = {
(tio_close_t *)tio_limited_close,
(tio_read_t *)tio_limited_read,
NULL, NULL
@@ -65,7 +65,7 @@ TIO_LOCAL const tio_functions_t tio_limited_callbacks = {
/* `tio_open_limited()`: open a limited stream. */
-int TIO_EXPORT tio_open_limited(tio_stream_t **streamp,
+TIO_EXTERN(int) tio_open_limited(tio_stream_t **streamp,
tio_stream_t *parent, size_t size)
{
limited_cookie_t *cookie = NULL;
@@ -93,7 +93,7 @@ int TIO_EXPORT tio_open_limited(tio_stream_t **streamp,
/* `tio_empty_limited()`: empty a limited stream by reading what's left. */
-int TIO_EXPORT tio_empty_limited(tio_stream_t *stream)
+TIO_EXTERN(int) tio_empty_limited(tio_stream_t *stream)
{
limited_cookie_t *cookie = (void *)tio_get_cookie(stream);
int err;
diff --git a/lib/stream/builtin/memory.c b/lib/stream/builtin/memory.c
index 09ca118..1ecf543 100644
--- a/lib/stream/builtin/memory.c
+++ b/lib/stream/builtin/memory.c
@@ -13,7 +13,7 @@ typedef struct {
/* `tio_memory_read()`: read from a memory area. */
-TIO_LOCAL int tio_memory_read(void *vcookie, unsigned char *dest,
+TIO_HOOK(int) tio_memory_read(void *vcookie, unsigned char *dest,
size_t count)
{
memory_cookie_t *cookie = (void*)vcookie;
@@ -33,7 +33,7 @@ TIO_LOCAL int tio_memory_read(void *vcookie, unsigned char *dest,
/* `tio_memory_write()`: write to a memory area. */
-TIO_LOCAL int tio_memory_write(void *vcookie, const unsigned char *data,
+TIO_HOOK(int) tio_memory_write(void *vcookie, const unsigned char *data,
size_t count)
{
memory_cookie_t *cookie = (void*)vcookie;
@@ -53,7 +53,7 @@ TIO_LOCAL int tio_memory_write(void *vcookie, const unsigned char *data,
/* `tio_memory_seek()`: seeking in a memory area. */
-TIO_LOCAL int tio_memory_seek(void *vcookie, tio_off_t *offset,
+TIO_HOOK(int) tio_memory_seek(void *vcookie, tio_off_t *offset,
tio_whence_t whence)
{
memory_cookie_t *cookie = (void*)vcookie;
@@ -89,14 +89,14 @@ TIO_LOCAL int tio_memory_seek(void *vcookie, tio_off_t *offset,
/* `tio_memory_close()`: close the stream. */
-TIO_LOCAL void tio_memory_close(void *vcookie)
+TIO_HOOK(void) tio_memory_close(void *vcookie)
{
tio_free(vcookie);
}
/* Callbacks. */
-TIO_LOCAL tio_functions_t const tio_memory_callbacks = {
+TIO_LOCAL_DATA(tio_functions_t const) tio_memory_callbacks = {
(tio_close_t *)tio_memory_close,
(tio_read_t *)tio_memory_read,
(tio_write_t *)tio_memory_write,
@@ -109,7 +109,7 @@ TIO_LOCAL tio_functions_t const tio_memory_callbacks = {
/* `tio_open_memory()`: open a memory area as a stream. */
-int TIO_EXPORT tio_open_memory(tio_stream_t **streamp,
+TIO_EXTERN(int) tio_open_memory(tio_stream_t **streamp,
void *memory, size_t size)
{
memory_cookie_t *cookie = NULL;
@@ -140,7 +140,7 @@ int TIO_EXPORT tio_open_memory(tio_stream_t **streamp,
/* `tio_open_readonly_memory()`: open a read-only memory area as a stream. */
-int TIO_EXPORT tio_open_readonly_memory(tio_stream_t **streamp,
+TIO_EXTERN(int) tio_open_readonly_memory(tio_stream_t **streamp,
void const *memory, size_t size)
{
memory_cookie_t *cookie = NULL;
diff --git a/lib/stream/builtin/std.c b/lib/stream/builtin/std.c
index 290a3fc..12f851a 100644
--- a/lib/stream/builtin/std.c
+++ b/lib/stream/builtin/std.c
@@ -21,7 +21,7 @@ typedef struct {
/* `tio_std_close()`: close the standard stream wrapper. */
-TIO_LOCAL void tio_std_close(void *vcookie)
+TIO_HOOK(void) tio_std_close(void *vcookie)
{
std_cookie_t *cookie = (void *)vcookie;
@@ -32,7 +32,7 @@ TIO_LOCAL void tio_std_close(void *vcookie)
/* `tio_std_read()`: read from a standard stream. */
-TIO_LOCAL int tio_std_read(void *vcookie, unsigned char *dest,
+TIO_HOOK(int) tio_std_read(void *vcookie, unsigned char *dest,
size_t count)
{
std_cookie_t *cookie = (void *)vcookie;
@@ -47,7 +47,7 @@ TIO_LOCAL int tio_std_read(void *vcookie, unsigned char *dest,
/* `tio_std_write()`: write to the standard stream. */
-TIO_LOCAL int tio_std_write(void *vcookie, unsigned char const *dest,
+TIO_HOOK(int) tio_std_write(void *vcookie, unsigned char const *dest,
size_t count)
{
std_cookie_t *cookie = (void *)vcookie;
@@ -62,7 +62,7 @@ TIO_LOCAL int tio_std_write(void *vcookie, unsigned char const *dest,
/* `tio_std_seek()`: seek within the standard stream. */
-TIO_LOCAL int tio_std_seek(void *vcookie, tio_off_t *offp,
+TIO_HOOK(int) tio_std_seek(void *vcookie, tio_off_t *offp,
tio_whence_t whence)
{
std_cookie_t *cookie = (void *)vcookie;
@@ -82,7 +82,7 @@ TIO_LOCAL int tio_std_seek(void *vcookie, tio_off_t *offp,
* Opening functions.
* --- */
-TIO_LOCAL tio_functions_t tio_std_functions = {
+TIO_LOCAL_DATA(tio_functions_t const) tio_std_functions = {
&tio_std_close,
&tio_std_read,
&tio_std_write,
@@ -91,7 +91,7 @@ TIO_LOCAL tio_functions_t tio_std_functions = {
/* `tio_open_std()`: open a libtio stream from a standard stream. */
-int TIO_EXPORT tio_open_std(tio_stream_t **streamp, FILE *filep, int cl)
+TIO_EXTERN(int) tio_open_std(tio_stream_t **streamp, FILE *filep, int cl)
{
std_cookie_t *cookie = NULL;
unsigned int flags = 0;
@@ -139,8 +139,8 @@ int TIO_EXPORT tio_open_std(tio_stream_t **streamp, FILE *filep, int cl)
* --- */
# define BUILTIN_STREAM(NAME, GLOBAL, STREAM_NAME) \
-TIO_LOCAL tio_stream_t *GLOBAL = NULL; \
-int TIO_EXPORT NAME(tio_stream_t **streamp) \
+TIO_LOCAL_DATA(tio_stream_t *) GLOBAL = NULL; \
+TIO_EXTERN(int) NAME(tio_stream_t **streamp) \
{ \
int err; \
\
diff --git a/lib/stream/builtin/unix.c b/lib/stream/builtin/unix.c
index f6ec3a2..1843292 100644
--- a/lib/stream/builtin/unix.c
+++ b/lib/stream/builtin/unix.c
@@ -13,6 +13,8 @@
# define BUFSIZE 2048
+TIO_STRUCT(cookie, cookie_t)
+
struct cookie {
/* File descriptor, a boolean to know if we ought to close the
* file descriptor at stream closing, and the timeout. */
@@ -25,7 +27,6 @@ struct cookie {
ssize_t _str, _end;
unsigned char _buf[BUFSIZE];
};
-typedef struct cookie cookie_t;
/* ---
* Callbacks.
@@ -33,7 +34,7 @@ typedef struct cookie cookie_t;
/* `unix_read()`: read from a UNIX stream. */
-TIO_LOCAL int TIO_EXPORT unix_read(cookie_t *cookie, unsigned char *dest,
+TIO_HOOK(int) unix_read(cookie_t *cookie, unsigned char *dest,
size_t size)
{
int fd = cookie->_fd;
@@ -103,7 +104,7 @@ TIO_LOCAL int TIO_EXPORT unix_read(cookie_t *cookie, unsigned char *dest,
/* `unix_write()`: write to a UNIX stream. */
-TIO_LOCAL int TIO_EXPORT unix_write(cookie_t *cookie,
+TIO_HOOK(int) unix_write(cookie_t *cookie,
unsigned char const *data, size_t size)
{
int fd = cookie->_fd;
@@ -135,7 +136,7 @@ TIO_LOCAL int TIO_EXPORT unix_write(cookie_t *cookie,
# define SEEK(TIO, NATIVE) case TIO: wh = NATIVE; break;
-TIO_LOCAL int TIO_EXPORT unix_seek(cookie_t *cookie, tio_off_t *offp,
+TIO_HOOK(int) unix_seek(cookie_t *cookie, tio_off_t *offp,
tio_whence_t whence)
{
int fd = cookie->_fd;
@@ -182,7 +183,7 @@ TIO_LOCAL int TIO_EXPORT unix_seek(cookie_t *cookie, tio_off_t *offp,
# define SPEED(TIO, NATIVE) case TIO: speed = NATIVE; break;
-TIO_LOCAL int TIO_EXPORT unix_set_attrs(cookie_t *cookie,
+TIO_HOOK(int) unix_set_attrs(cookie_t *cookie,
tio_serial_attrs_t const *settings)
{
struct termios term;
@@ -273,7 +274,7 @@ TIO_LOCAL int TIO_EXPORT unix_set_attrs(cookie_t *cookie,
/* `unix_close()`: close the stream. */
-TIO_LOCAL void TIO_EXPORT unix_close(cookie_t *cookie)
+TIO_HOOK(void) unix_close(cookie_t *cookie)
{
/* Close the file descriptors if necessary. */
@@ -291,7 +292,7 @@ TIO_LOCAL void TIO_EXPORT unix_close(cookie_t *cookie)
/* The callbacks. */
-TIO_LOCAL tio_functions_t const unix_callbacks = {
+TIO_LOCAL_DATA(tio_functions_t const) unix_callbacks = {
(tio_close_t *)unix_close,
(tio_read_t *)unix_read,
(tio_write_t *)unix_write,
@@ -300,7 +301,7 @@ TIO_LOCAL tio_functions_t const unix_callbacks = {
/* `tio_open_unix_fd()`: open the UNIX stream from a file descriptor. */
-int TIO_EXPORT tio_open_unix_fd(tio_stream_t **streamp, int fd, int cl)
+TIO_EXTERN(int) tio_open_unix_fd(tio_stream_t **streamp, int fd, int cl)
{
cookie_t *cookie = NULL;
unsigned int mode = TIO_OPENFLAG_READ | TIO_OPENFLAG_WRITE
diff --git a/lib/stream/builtin/windows.c b/lib/stream/builtin/windows.c
index 6aaf07c..82ac529 100644
--- a/lib/stream/builtin/windows.c
+++ b/lib/stream/builtin/windows.c
@@ -18,12 +18,15 @@
# define BUFSIZE 2048
-typedef struct {
+TIO_STRUCT(cookie, cookie_t);
+typedef cookie_t *PSP_COOKIE;
+
+struct cookie {
HANDLE _handle;
long _srt, _end;
unsigned char buf[BUFSIZE];
-} cookie_t, *PSP_COOKIE;
+};
/* ---
* Callbacks.
@@ -31,7 +34,7 @@ typedef struct {
/* `win_read()`: read from a Windows stream. */
-TIO_LOCAL int TIO_EXPORT win_read(cookie_t *cookie,
+TIO_HOOK(int) win_read(cookie_t *cookie,
unsigned char *dest, size_t size)
{
/* TODO */
@@ -39,7 +42,7 @@ TIO_LOCAL int TIO_EXPORT win_read(cookie_t *cookie,
/* `win_write()`: write to a Windows stream. */
-TIO_LOCAL int TIO_EXPORT win_write(cookie_t *cookie,
+TIO_HOOK(int) win_write(cookie_t *cookie,
unsigned char const *data, size_t size)
{
/* TODO */
@@ -47,7 +50,7 @@ TIO_LOCAL int TIO_EXPORT win_write(cookie_t *cookie,
/* `win_seek()`: seek within the Windows stream. */
-TIO_LOCAL int TIO_EXPORT win_seek(cookie_t *cookie,
+TIO_HOOK(int) win_seek(cookie_t *cookie,
tio_off_t *offp, tio_whence_t whence)
{
/* TODO */
@@ -55,7 +58,7 @@ TIO_LOCAL int TIO_EXPORT win_seek(cookie_t *cookie,
/* `win_set_attrs()`: set the serial attributes of a Windows stream. */
-TIO_LOCAL int TIO_EXPORT win_set_attrs(cookie_t *cookie,
+TIO_HOOK(int) win_set_attrs(cookie_t *cookie,
tio_serial_attrs_t const *settings)
{
/* TODO */
@@ -63,7 +66,7 @@ TIO_LOCAL int TIO_EXPORT win_set_attrs(cookie_t *cookie,
/* `win_close()`: close a Windows stream. */
-TIO_LOCAL int TIO_EXPORT win_close(cookie_t *cookie)
+TIO_HOOK(int) win_close(cookie_t *cookie)
{
/* TODO */
}
@@ -74,7 +77,7 @@ TIO_LOCAL int TIO_EXPORT win_close(cookie_t *cookie)
/* The callbacks. */
-TIO_LOCAL tio_functions_t const win_callbacks = {
+TIO_LOCAL_DATA(tio_functions_t const) win_callbacks = {
(tio_close_t *)win_close,
(tio_read_t *)win_read,
(tio_write_t *)win_write,
@@ -83,7 +86,7 @@ TIO_LOCAL tio_functions_t const win_callbacks = {
/* `tio_open_windows_handle()`: open a Windows stream out of a handle. */
-TIO_EXTERN int TIO_EXPORT tio_open_windows_handle(tio_stream_t **streamp,
+TIO_EXTERN(int) tio_open_windows_handle(tio_stream_t **streamp,
HANDLE handle, int cl)
{
/* TODO */
diff --git a/lib/stream/get.c b/lib/stream/get.c
index 8476d84..6810983 100644
--- a/lib/stream/get.c
+++ b/lib/stream/get.c
@@ -2,7 +2,7 @@
/* `tio_isreadable()`: check if the stream is readable. */
-int TIO_EXPORT tio_isreadable(tio_stream_t *stream)
+TIO_EXTERN(int) tio_isreadable(tio_stream_t *stream)
{
if (stream->tio_stream_dead_parent)
return (0);
@@ -12,7 +12,7 @@ int TIO_EXPORT tio_isreadable(tio_stream_t *stream)
/* `tio_iswritable()`: check if the stream is writable. */
-int TIO_EXPORT tio_iswritable(tio_stream_t *stream)
+TIO_EXTERN(int) tio_iswritable(tio_stream_t *stream)
{
if (stream->tio_stream_dead_parent)
return (0);
@@ -22,7 +22,7 @@ int TIO_EXPORT tio_iswritable(tio_stream_t *stream)
/* `tio_isseekable()`: check if the stream is seekable. */
-int TIO_EXPORT tio_isseekable(tio_stream_t *stream)
+TIO_EXTERN(int) tio_isseekable(tio_stream_t *stream)
{
if (stream->tio_stream_dead_parent)
return (0);
@@ -32,28 +32,28 @@ int TIO_EXPORT tio_isseekable(tio_stream_t *stream)
/* `tio_get_type()`: access the private structure's type member. */
-int TIO_EXPORT tio_get_type(tio_stream_t *stream)
+TIO_EXTERN(int) tio_get_type(tio_stream_t *stream)
{
return (stream->tio_stream_type);
}
/* `tio_get_cookie()`: access the private structure's cookie. */
-void *TIO_EXPORT tio_get_cookie(tio_stream_t *stream)
+TIO_EXTERN(void *) tio_get_cookie(tio_stream_t *stream)
{
return (stream->tio_stream_cookie);
}
/* `tio_get_lasterr()`: access the private structure's last error. */
-int TIO_EXPORT tio_get_lasterr(tio_stream_t *stream)
+TIO_EXTERN(int) tio_get_lasterr(tio_stream_t *stream)
{
return (stream->tio_stream_lasterr);
}
/* `tio_get_parent()`: access the private structure's parent. */
-int TIO_EXPORT tio_get_parent(tio_stream_t *stream, tio_stream_t **parent)
+TIO_EXTERN(int) tio_get_parent(tio_stream_t *stream, tio_stream_t **parent)
{
tio_stream_t *p = stream->tio_stream_parent;
diff --git a/lib/stream/open.c b/lib/stream/open.c
index db9e8e1..1355986 100644
--- a/lib/stream/open.c
+++ b/lib/stream/open.c
@@ -48,7 +48,7 @@
/* `tio_open()`: open a generic libtio stream. */
-int TIO_EXPORT tio_open(tio_stream_t **streamp,
+TIO_EXTERN(int) tio_open(tio_stream_t **streamp,
tio_stream_t *parent, void *cookie, unsigned int flags,
tio_functions_t const *functions, tio_off_t offset)
{
@@ -73,7 +73,7 @@ int TIO_EXPORT tio_open(tio_stream_t **streamp,
/* `tio_open_serial()`: open a serial libtio stream. */
-int TIO_EXPORT tio_open_serial(tio_stream_t **streamp,
+TIO_EXTERN(int) tio_open_serial(tio_stream_t **streamp,
tio_stream_t *parent, void *cookie, unsigned int flags,
tio_serial_functions_t const *functions, tio_serial_attrs_t const *attrs)
{
@@ -107,7 +107,7 @@ int TIO_EXPORT tio_open_serial(tio_stream_t **streamp,
/* `tio_open_usb()`: open a USB libtio stream. */
-int TIO_EXPORT tio_open_usb(tio_stream_t **streamp,
+TIO_EXTERN(int) tio_open_usb(tio_stream_t **streamp,
tio_stream_t *parent, void *cookie, unsigned int flags,
tio_usb_functions_t const *functions)
{
@@ -127,7 +127,7 @@ int TIO_EXPORT tio_open_usb(tio_stream_t **streamp,
/* `tio_open_scsi()`: open an SCSI libtio stream. */
-int TIO_EXPORT tio_open_scsi(tio_stream_t **streamp,
+TIO_EXTERN(int) tio_open_scsi(tio_stream_t **streamp,
tio_stream_t *parent, void *cookie, unsigned int flags,
tio_scsi_functions_t const *functions)
{
@@ -143,7 +143,7 @@ int TIO_EXPORT tio_open_scsi(tio_stream_t **streamp,
/* `tio_warn()`: warn a stream about a dead parent. */
-TIO_LOCAL void tio_warn(tio_stream_t *stream)
+TIO_LOCAL(void) tio_warn(tio_stream_t *stream)
{
tio_stream_t *ch;
@@ -154,7 +154,7 @@ TIO_LOCAL void tio_warn(tio_stream_t *stream)
/* `tio_close()`: close a stream. */
-void TIO_EXPORT tio_close(tio_stream_t *stream)
+TIO_EXTERN(void) tio_close(tio_stream_t *stream)
{
tio_close_t *cl;
diff --git a/lib/stream/read.c b/lib/stream/read.c
index 02a6afd..6c4d7e7 100644
--- a/lib/stream/read.c
+++ b/lib/stream/read.c
@@ -2,7 +2,7 @@
/* `tio_read()`: read from a stream. */
-int TIO_EXPORT tio_read(tio_stream_t *stream, void *dest, size_t count)
+TIO_EXTERN(int) tio_read(tio_stream_t *stream, void *dest, size_t count)
{
int err;
tio_read_tm_t *rdt;
diff --git a/lib/stream/read_tm.c b/lib/stream/read_tm.c
index 539d99b..8affbea 100644
--- a/lib/stream/read_tm.c
+++ b/lib/stream/read_tm.c
@@ -2,7 +2,7 @@
/* `tio_read_tm()`: read from a stream, with timeouts. */
-int TIO_EXPORT tio_read_tm(tio_stream_t *stream, void *dest,
+TIO_EXTERN(int) tio_read_tm(tio_stream_t *stream, void *dest,
size_t count, tio_timeouts_t const *tm)
{
tio_timeouts_t orig;
diff --git a/lib/stream/scsi.c b/lib/stream/scsi.c
index 6c6d8bf..8728cd9 100644
--- a/lib/stream/scsi.c
+++ b/lib/stream/scsi.c
@@ -2,7 +2,7 @@
/* `tio_scsi_request()`: make an SCSI request. */
-int TIO_EXPORT tio_scsi_request(tio_stream_t *stream,
+TIO_EXTERN(int) tio_scsi_request(tio_stream_t *stream,
tio_scsi_request_t *request)
{
int err;
diff --git a/lib/stream/seek.c b/lib/stream/seek.c
index 7461e59..480fc29 100644
--- a/lib/stream/seek.c
+++ b/lib/stream/seek.c
@@ -2,7 +2,7 @@
/* `tio_seek()`: move the cursor of the stream. */
-int TIO_EXPORT tio_seek(tio_stream_t *stream, tio_off_t offset,
+TIO_EXTERN(int) tio_seek(tio_stream_t *stream, tio_off_t offset,
tio_whence_t whence)
{
int err;
@@ -65,14 +65,14 @@ fail:
/* `tio_tell()`: get the offset. */
-tio_off_t TIO_EXPORT tio_tell(tio_stream_t *stream)
+TIO_EXTERN(tio_off_t) tio_tell(tio_stream_t *stream)
{
return (stream->tio_stream_offset);
}
/* `tio_skip()`: skip bytes. */
-int TIO_EXPORT tio_skip(tio_stream_t *stream, tio_off_t size)
+TIO_EXTERN(int) tio_skip(tio_stream_t *stream, tio_off_t size)
{
/* Use what has been implemented in `tio_seek()` function to
* skip N bytes. */
@@ -82,7 +82,7 @@ int TIO_EXPORT tio_skip(tio_stream_t *stream, tio_off_t size)
/* `tio_get_size()`: get the size of a stream (e.g. file). */
-int TIO_EXPORT tio_get_size(tio_stream_t *stream, tio_off_t *size)
+TIO_EXTERN(int) tio_get_size(tio_stream_t *stream, tio_off_t *size)
{
int err;
tio_off_t offset;
diff --git a/lib/stream/serial.c b/lib/stream/serial.c
index 8c6bb75..fec72e6 100644
--- a/lib/stream/serial.c
+++ b/lib/stream/serial.c
@@ -3,7 +3,7 @@
/* `tio_set_serial_attrs()`: set the serial attributes. */
-int TIO_EXPORT tio_set_serial_attrs(tio_stream_t *stream,
+TIO_EXTERN(int) tio_set_serial_attrs(tio_stream_t *stream,
unsigned int flags, tio_serial_attrs_t const *attrs)
{
tio_set_serial_attrs_t *st;
@@ -65,7 +65,7 @@ fail:
/* `tio_get_serial_attrs()`: get the serial attributes. */
-int TIO_EXPORT tio_get_serial_attrs(tio_stream_t *stream,
+TIO_EXTERN(int) tio_get_serial_attrs(tio_stream_t *stream,
unsigned int flags, tio_serial_attrs_t *attrs)
{
if (stream->tio_stream_type != TIO_TYPE_SERIAL) {
diff --git a/lib/stream/tm.c b/lib/stream/tm.c
index 02118d6..6e4067a 100644
--- a/lib/stream/tm.c
+++ b/lib/stream/tm.c
@@ -2,7 +2,7 @@
/* `tio_set_timeouts()`: set the timeouts for the stream. */
-int TIO_EXPORT tio_set_timeouts(tio_stream_t *stream,
+TIO_EXTERN(int) tio_set_timeouts(tio_stream_t *stream,
tio_timeouts_t const *readtm, tio_timeouts_t const *writetm)
{
int err;
diff --git a/lib/stream/usb.c b/lib/stream/usb.c
index 2224f43..84238ad 100644
--- a/lib/stream/usb.c
+++ b/lib/stream/usb.c
@@ -2,8 +2,8 @@
/* `tio_usb_send_bulk()`: send a USB bulk packet. */
-int tio_usb_send_bulk(tio_stream_t *stream, unsigned char const *data,
- size_t size, unsigned int timeout /* in ms */)
+TIO_EXTERN(int) tio_usb_send_bulk(tio_stream_t *stream,
+ unsigned char const *data, size_t size, unsigned int timeout /* in ms */)
{
int err;
tio_usb_send_bulk_t *func;
@@ -34,7 +34,7 @@ fail:
/* `tio_usb_recv_bulk()`: receive an USB bulk packet. */
-int tio_usb_recv_bulk(tio_stream_t *stream, unsigned char *buf,
+TIO_EXTERN(int) tio_usb_recv_bulk(tio_stream_t *stream, unsigned char *buf,
size_t size, unsigned int timeout /* in ms */)
{
int err;
diff --git a/lib/stream/write.c b/lib/stream/write.c
index 199477d..bc1f01c 100644
--- a/lib/stream/write.c
+++ b/lib/stream/write.c
@@ -2,7 +2,7 @@
/* `tio_write()`: write to a stream. */
-int TIO_EXPORT tio_write(tio_stream_t *stream, void const *data,
+TIO_EXTERN(int) tio_write(tio_stream_t *stream, void const *data,
size_t count)
{
int err;
diff --git a/lib/stream/write_tm.c b/lib/stream/write_tm.c
index cbf7312..84c80ba 100644
--- a/lib/stream/write_tm.c
+++ b/lib/stream/write_tm.c
@@ -2,7 +2,7 @@
/* `tio_write_tm()`: write to a stream, with timeouts. */
-int TIO_EXPORT tio_write_tm(tio_stream_t *stream, void const *data,
+TIO_EXTERN(int) tio_write_tm(tio_stream_t *stream, void const *data,
size_t count, tio_timeouts_t const *tm)
{
tio_timeouts_t orig;