From 4f1e1d300ca97579edbb6484f79a9b6ed986460a Mon Sep 17 00:00:00 2001 From: leitner Date: Tue, 7 Feb 2012 17:02:40 +0000 Subject: [PATCH] make headers work in C++ add two more variable length integer encoding functions --- array.h | 8 ++++++++ buffer.h | 8 ++++++++ byte.h | 8 ++++++++ case.h | 8 ++++++++ cdb.h | 8 ++++++++ cdb_make.h | 8 ++++++++ dns.h | 8 ++++++++ errmsg.h | 8 ++++++++ fmt.h | 12 +++++++++++- fmt/fmt_asn1derlength.3 | 5 +++-- fmt/fmt_asn1dertag.3 | 18 ++++++++++++++++++ fmt/fmt_asn1dertag.c | 15 +++++++++++++++ io.h | 11 ++++++++++- io_internal.h | 26 ++++++++++++++++++++++---- iob.h | 8 ++++++++ ip4.h | 8 ++++++++ ip6.h | 8 ++++++++ mmap.h | 8 ++++++++ ndelay.h | 8 ++++++++ open.h | 8 ++++++++ openreadclose.h | 8 ++++++++ rangecheck.h | 8 ++++++++ readclose.h | 8 ++++++++ safemult.h | 8 ++++++++ scan.h | 11 +++++++++++ scan/scan_asn1derlength.3 | 14 +++++++------- scan/scan_asn1dertag.3 | 20 ++++++++++++++++++++ scan/scan_asn1dertag.c | 14 ++++++++++++++ socket.h | 8 ++++++++ str.h | 9 +++++++++ stralloc.h | 9 +++++++++ tai.h | 8 ++++++++ taia.h | 8 ++++++++ textcode.h | 8 ++++++++ uint16.h | 8 ++++++++ uint32.h | 8 ++++++++ uint64.h | 8 ++++++++ windoze.h | 8 ++++++++ 38 files changed, 357 insertions(+), 15 deletions(-) create mode 100644 fmt/fmt_asn1dertag.3 create mode 100644 fmt/fmt_asn1dertag.c create mode 100644 scan/scan_asn1dertag.3 create mode 100644 scan/scan_asn1dertag.c diff --git a/array.h b/array.h index a2bec14..0a212d7 100644 --- a/array.h +++ b/array.h @@ -5,6 +5,10 @@ #include #include "uint64.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { char* p; int64 allocated; /* in bytes */ @@ -40,4 +44,8 @@ void array_chop(array* x,uint64 membersize,uint64 members); #define array_failed(x) (array_bytes(x)==-1) #define array_unallocated(x) (array_bytes(x)==0) +#ifdef __cplusplus +} +#endif + #endif diff --git a/buffer.h b/buffer.h index ce1b895..76e6d20 100644 --- a/buffer.h +++ b/buffer.h @@ -7,6 +7,10 @@ /* for ssize_t: */ #include +#ifdef __cplusplus +extern "C" { +#endif + typedef struct buffer { char *x; /* actual buffer space */ size_t p; /* current position */ @@ -139,4 +143,8 @@ void buffer_fromsa(buffer* b,stralloc* sa); /* read from sa */ int buffer_tosa(buffer*b,stralloc* sa); /* write to sa, auto-growing it */ #endif +#ifdef __cplusplus +} +#endif + #endif diff --git a/byte.h b/byte.h index 4f93815..3cf802a 100644 --- a/byte.h +++ b/byte.h @@ -5,6 +5,10 @@ /* for size_t: */ #include +#ifdef __cplusplus +extern "C" { +#endif + #ifndef __pure__ #define __pure__ #endif @@ -37,4 +41,8 @@ void byte_zero(void* out, size_t len); #define byte_equal(s,n,t) (!byte_diff((s),(n),(t))) +#ifdef __cplusplus +} +#endif + #endif diff --git a/case.h b/case.h index 77676ca..59d9470 100644 --- a/case.h +++ b/case.h @@ -4,6 +4,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* turn upper case letters to lower case letters, ASCIIZ */ void case_lowers(char *s); /* turn upper case letters to lower case letters, binary */ @@ -20,4 +24,8 @@ int case_starts(const char *,const char *); #define case_equals(s,t) (!case_diffs((s),(t))) #define case_equalb(s,n,t) (!case_diffb((s),(n),(t))) +#ifdef __cplusplus +} +#endif + #endif diff --git a/cdb.h b/cdb.h index 4135a20..667013a 100644 --- a/cdb.h +++ b/cdb.h @@ -5,6 +5,10 @@ #include "uint32.h" #include "uint64.h" +#ifdef __cplusplus +extern "C" { +#endif + #define CDB_HASHSTART 5381 extern uint32 cdb_hashadd(uint32 h,unsigned char c); extern uint32 cdb_hash(const unsigned char *buf,unsigned long int len); @@ -41,4 +45,8 @@ extern int cdb_successor(struct cdb *c,const unsigned char *,unsigned long int); #define cdb_keypos(c) ((c)->kpos) #define cdb_keylen(c) ((c)->dpos-(c)->kpos) +#ifdef __cplusplus +} +#endif + #endif diff --git a/cdb_make.h b/cdb_make.h index 5baf90e..f7e6e70 100644 --- a/cdb_make.h +++ b/cdb_make.h @@ -6,6 +6,10 @@ #include "uint64.h" #include "uint32.h" +#ifdef __cplusplus +extern "C" { +#endif + #define CDB_HPLIST 1000 struct cdb_hp { uint32 h; uint32 p; } ; @@ -36,4 +40,8 @@ extern int cdb_make_addend(struct cdb_make *,unsigned long int,unsigned long int extern int cdb_make_add(struct cdb_make *,const unsigned char *,unsigned long int,const unsigned char *,unsigned long int); extern int cdb_make_finish(struct cdb_make *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/dns.h b/dns.h index 90c3514..3dfcc0e 100644 --- a/dns.h +++ b/dns.h @@ -6,6 +6,10 @@ #include "iopause.h" #include "taia.h" +#ifdef __cplusplus +extern "C" { +#endif + #define DNS_C_IN "\0\1" #define DNS_C_ANY "\0\377" @@ -92,4 +96,8 @@ void dns_name6_domain(char *,const char *); #define DNS_NAME6_DOMAIN (4*16+11) int dns_name6(stralloc *,const char *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/errmsg.h b/errmsg.h index 575f1d5..096bd24 100644 --- a/errmsg.h +++ b/errmsg.h @@ -5,6 +5,10 @@ /* for exit(): */ #include +#ifdef __cplusplus +extern "C" { +#endif + /* These use file descriptor 2, not buffer_2! * Call buffer_flush(buffer_2) before calling these! */ @@ -27,4 +31,8 @@ void errmsg_infosys(const char* message, ...); #define msg(...) errmsg_info(__VA_ARGS__,(char*)0); #define msgsys(...) errmsg_infosys(__VA_ARGS__,(char*)0); +#ifdef __cplusplus +} +#endif + #endif diff --git a/fmt.h b/fmt.h index cabc550..4249880 100644 --- a/fmt.h +++ b/fmt.h @@ -9,6 +9,10 @@ /* for time_t: */ #include +#ifdef __cplusplus +extern "C" { +#endif + #define FMT_LONG 41 /* enough space to hold -2^127 in decimal, plus \0 */ #define FMT_ULONG 40 /* enough space to hold 2^128 - 1 in decimal, plus \0 */ #define FMT_8LONG 44 /* enough space to hold 2^128 - 1 in octal, plus \0 */ @@ -92,9 +96,11 @@ size_t fmt_httpdate(char* dest,time_t t); #define FMT_UTF8 5 #define FMT_ASN1LENGTH 17 /* enough space to hold 2^128-1 */ +#define FMT_ASN1TAG 19 /* enough space to hold 2^128-1 */ /* some variable length encodings for integers */ size_t fmt_utf8(char* dest,uint32_t n); /* can store 0-0x7fffffff */ -size_t fmt_asn1derlength(char* dest,unsigned long long l); +size_t fmt_asn1derlength(char* dest,unsigned long long l); /* 0-0x7f: 1 byte, above that 1+bytes_needed bytes */ +size_t fmt_asn1dertag(char* dest,unsigned long long l); /* 1 byte for each 7 bits; upper bit = more bytes coming */ /* internal functions, may be independently useful */ char fmt_tohex(char c); @@ -107,4 +113,8 @@ size_t fmt_strm_internal(char* dest,...); #endif #define fmt_strm_alloca(a,...) ({ size_t len=fmt_strm((char*)0,a,__VA_ARGS__)+1; char* c=(len + +size_t \fBfmt_asn1dertag\fP(char *\fIdest\fR,unsigned long long \fIsource\fR); +.SH DESCRIPTION +fmt_asn1dertag encodes an unsigned integer using the ASN.1 DER for +encoding tag. This takes one byte for every 7 bits in the number. + +If \fIdest\fR equals FMT_LEN (i.e. is NULL), fmt_asn1dertag returns the +number of bytes it would have written. + +For convenience, fmt.h defines the integer FMT_ASN1TAG to be big +enough to contain every possible fmt_asn1dertag output. +.SH "SEE ALSO" +scan_asn1dertag(3) diff --git a/fmt/fmt_asn1dertag.c b/fmt/fmt_asn1dertag.c new file mode 100644 index 0000000..dc5452f --- /dev/null +++ b/fmt/fmt_asn1dertag.c @@ -0,0 +1,15 @@ +#include "fmt.h" + +/* write int in least amount of bytes, return number of bytes */ +/* as used in ASN.1 DER tag */ +size_t fmt_asn1dertag(char* dest,unsigned long long l) { + /* encoding is either l%128 or (0x80+number of bytes,bytes) */ + size_t n=0,i; + unsigned long long t; + for (t=l, n=1; t>0x7f; t>>=7) ++n; + for (i=0; i>=7; + } + return i; +} diff --git a/io.h b/io.h index 5b78793..6c4bf6c 100644 --- a/io.h +++ b/io.h @@ -7,6 +7,10 @@ #include "uint64.h" #include "taia.h" +#ifdef __cplusplus +extern "C" { +#endif + /* like open(s,O_RDONLY) */ /* return 1 if ok, 0 on error */ int io_readfile(int64* d,const char* s); @@ -72,7 +76,8 @@ int64 io_canwrite(); int64 io_timeouted(); /* put d on internal data structure, return 1 on success, 0 on error */ -int io_fd(int64 d); +int io_fd(int64 d); /* use this for sockets before you called connect() or accept() */ +int io_fd_connected(int64 d); /* use this for connected sockets (assumes socket is writable) */ void io_setcookie(int64 d,void* cookie); void* io_getcookie(int64 d); @@ -115,4 +120,8 @@ int64 io_mmapwritefile(int64 out,int64 in,uint64 off,uint64 bytes,io_write_callb #include_next #endif +#ifdef __cplusplus +} +#endif + #endif diff --git a/io_internal.h b/io_internal.h index eea698a..0092cc9 100644 --- a/io_internal.h +++ b/io_internal.h @@ -18,14 +18,32 @@ my_extern HANDLE io_comport; #endif #endif +/* We simulate a level-triggered API on top of an event signalling + * mechanism that can be level-triggered (epoll/kqueue/poll) or + * edge-triggered (SIGIO). + * Difficulty: we want to avoid unnecessary syscalls, so we keep state + * internally. If the user says he does not want to read/write anymore, + * we don't tell the kernel straight away. The rationale is that the + * typical protocol consists of interleaved reading and writing, so + * after each read you'd call io_dontwantread, io_wantwrite, io_wait, + * io_dontwantwrite, io_wantread, and in the regular case there is no + * incoming data between io_dontwantread and io_wantread, so we might as + * well optimistically not do those syscalls and then handle the + * complexity if there is more incoming data. */ + +/* Basically, we tell the kernel that we want to read if !canread, + * and we tell the kernel that we want to write if !canwrite. */ + typedef struct { tai6464 timeout; - unsigned int wantread:1; + unsigned int wantread:1; /* does the app want to read/write? */ unsigned int wantwrite:1; - unsigned int canread:1; + unsigned int canread:1; /* do we know we can read/write? */ unsigned int canwrite:1; - unsigned int nonblock:1; - unsigned int inuse:1; + unsigned int nonblock:1; /* is this socket non-blocking? */ + unsigned int inuse:1; /* internal consistency checking */ + unsigned int kernelwantread:1; /* did we tell the kernel we want to read/write? */ + unsigned int kernelwantwrite:1; #ifdef __MINGW32__ unsigned int readqueued:2; unsigned int writequeued:2; diff --git a/iob.h b/iob.h index 8983b05..585ddee 100644 --- a/iob.h +++ b/iob.h @@ -16,6 +16,10 @@ #include "io.h" #include "array.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef struct io_batch { array b; uint64 bytesleft; @@ -37,4 +41,8 @@ void iob_free(io_batch* b); void iob_prefetch(io_batch* b,uint64 bytes); uint64 iob_bytesleft(const io_batch* b); +#ifdef __cplusplus +} +#endif + #endif diff --git a/ip4.h b/ip4.h index 8da0385..cbb7435 100644 --- a/ip4.h +++ b/ip4.h @@ -2,6 +2,10 @@ #ifndef IP4_H #define IP4_H +#ifdef __cplusplus +extern "C" { +#endif + unsigned int scan_ip4(const char *src,char *ip); unsigned int fmt_ip4(char *dest,const char *ip); @@ -14,4 +18,8 @@ unsigned int fmt_ip4(char *dest,const char *ip); extern const char ip4loopback[4]; /* = {127,0,0,1};*/ +#ifdef __cplusplus +} +#endif + #endif diff --git a/ip6.h b/ip6.h index 6128a60..482a582 100644 --- a/ip6.h +++ b/ip6.h @@ -5,6 +5,10 @@ #include "byte.h" #include "uint32.h" +#ifdef __cplusplus +extern "C" { +#endif + unsigned int scan_ip6(const char* src,char* ip); unsigned int fmt_ip6(char* dest,const char* ip); unsigned int fmt_ip6c(char* dest,const char* ip); @@ -33,4 +37,8 @@ extern const char V6any[16]; /*={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; */ #define ip6_isv4mapped(ip) (byte_equal(ip,12,V4mappedprefix)) +#ifdef __cplusplus +} +#endif + #endif diff --git a/mmap.h b/mmap.h index d29f1a7..bd95d16 100644 --- a/mmap.h +++ b/mmap.h @@ -4,6 +4,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* open file for reading, mmap whole file, close file, write length of * map in filesize and return pointer to map. */ char* mmap_read(const char *filename,size_t* filesize); @@ -20,4 +24,8 @@ char* mmap_shared(const char *filename,size_t* filesize); /* unmap a mapped region */ int mmap_unmap(char* mapped,size_t maplen); +#ifdef __cplusplus +} +#endif + #endif diff --git a/ndelay.h b/ndelay.h index a72eb3e..9fc8433 100644 --- a/ndelay.h +++ b/ndelay.h @@ -2,7 +2,15 @@ #ifndef NDELAY_H #define NDELAY_H +#ifdef __cplusplus +extern "C" { +#endif + int ndelay_on(int); int ndelay_off(int); +#ifdef __cplusplus +} +#endif + #endif diff --git a/open.h b/open.h index 169f6fa..045f0e3 100644 --- a/open.h +++ b/open.h @@ -2,6 +2,10 @@ #ifndef OPEN_H #define OPEN_H +#ifdef __cplusplus +extern "C" { +#endif + /* open filename for reading and return the file handle or -1 on error */ int open_read(const char* filename); @@ -29,4 +33,8 @@ int open_write(const char* filename); * Return file handle or -1 on error. */ int open_rw(const char* filename); +#ifdef __cplusplus +} +#endif + #endif diff --git a/openreadclose.h b/openreadclose.h index d340232..c30daad 100644 --- a/openreadclose.h +++ b/openreadclose.h @@ -4,6 +4,14 @@ #include "stralloc.h" +#ifdef __cplusplus +extern "C" { +#endif + int openreadclose(const char *filename,stralloc *buf,size_t initiallength); +#ifdef __cplusplus +} +#endif + #endif diff --git a/rangecheck.h b/rangecheck.h index c23b08b..d6de88d 100644 --- a/rangecheck.h +++ b/rangecheck.h @@ -5,6 +5,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* We are trying to achieve that gcc has to inline the function and we * don't want it to emit a copy of the function. This can be done with * static inline or with extern inline. static inline tells gcc to not @@ -151,4 +155,8 @@ int range_str4inbuf(const void* buf,size_t len,const void* stringstart); #undef __static +#ifdef __cplusplus +} +#endif + #endif diff --git a/readclose.h b/readclose.h index cceb301..4f75a90 100644 --- a/readclose.h +++ b/readclose.h @@ -3,7 +3,15 @@ #include "stralloc.h" +#ifdef __cplusplus +extern "C" { +#endif + int readclose_append(int fd,stralloc *buf,size_t initlen); int readclose(int fd,stralloc *buf,size_t initlen); +#ifdef __cplusplus +} +#endif + #endif diff --git a/safemult.h b/safemult.h index bf4c4be..3e81f29 100644 --- a/safemult.h +++ b/safemult.h @@ -6,6 +6,10 @@ #include "uint32.h" #include "uint64.h" +#ifdef __cplusplus +extern "C" { +#endif + /* return 0 for overflow, 1 for ok */ int umult16(uint16 a,uint16 b,uint16* c); int imult16( int16 a, int16 b, int16* c); @@ -16,4 +20,8 @@ int imult32( int32 a, int32 b, int32* c); int umult64(uint64 a,uint64 b,uint64* c); int imult64( int64 a, int64 b, int64* c); +#ifdef __cplusplus +} +#endif + #endif diff --git a/scan.h b/scan.h index 29ca4bb..1fd7e73 100644 --- a/scan.h +++ b/scan.h @@ -4,9 +4,15 @@ /* for size_t: */ #include +/* for uint32_t: */ +#include /* for time_t: */ #include +#ifdef __cplusplus +extern "C" { +#endif + #ifndef __pure__ #define __pure__ #endif @@ -76,9 +82,14 @@ size_t scan_httpdate(const char *in,time_t *t) __pure__; /* some variable length encodings for integers */ size_t scan_utf8(const char* in,size_t len,uint32_t* n) __pure__; size_t scan_asn1derlength(const char* in,size_t len,unsigned long long* n) __pure__; +size_t scan_asn1dertag(const char* in,size_t len,unsigned long long* n) __pure__; /* a few internal function that might be useful independently */ /* convert from hex ASCII, return 0 to 15 for success or -1 for failure */ int scan_fromhex(unsigned char c); +#ifdef __cplusplus +} +#endif + #endif diff --git a/scan/scan_asn1derlength.3 b/scan/scan_asn1derlength.3 index 9f5dcb6..068edd9 100644 --- a/scan/scan_asn1derlength.3 +++ b/scan/scan_asn1derlength.3 @@ -1,20 +1,20 @@ -.TH scan_asn1length 3 +.TH scan_asn1derlength 3 .SH NAME -scan_asn1length \- decode an unsigned integer from ASN.1 DER length encoding +scan_asn1derlength \- decode an unsigned integer from ASN.1 DER length encoding .SH SYNTAX .B #include -size_t \fBscan_asn1length\fP(const char *\fIsrc\fR,size_t \fIlen\fR,unsigned long long *\fIdest\fR); +size_t \fBscan_asn1derlength\fP(const char *\fIsrc\fR,size_t \fIlen\fR,unsigned long long *\fIdest\fR); .SH DESCRIPTION -scan_asn1length decodes an unsigned integer in ASN.1 DER length encoding +scan_asn1derlength decodes an unsigned integer in ASN.1 DER length encoding from a memory area holding binary data. It writes the decode value in \fIdest\fR and returns the number of bytes it read from \fIsrc\fR. -scan_asn1length never reads more than \fIlen\fR bytes from \fIsrc\fR. If the +scan_asn1derlength never reads more than \fIlen\fR bytes from \fIsrc\fR. If the sequence is longer than that, or the memory area contains an invalid -sequence, scan_asn1length returns 0 and does not touch \fIdest\fR. +sequence, scan_asn1derlength returns 0 and does not touch \fIdest\fR. The length of the longest ASN.1 DER length sequence is 128 bytes. In practice the largest sequence is sizeof(*dest)+1. .SH "SEE ALSO" -fmt_asn1length(3) +fmt_asn1derlength(3) diff --git a/scan/scan_asn1dertag.3 b/scan/scan_asn1dertag.3 new file mode 100644 index 0000000..c111642 --- /dev/null +++ b/scan/scan_asn1dertag.3 @@ -0,0 +1,20 @@ +.TH scan_asn1dertag 3 +.SH NAME +scan_asn1dertag \- decode an unsigned integer from ASN.1 DER length encoding +.SH SYNTAX +.B #include + +size_t \fBscan_asn1dertag\fP(const char *\fIsrc\fR,size_t \fIlen\fR,unsigned long long *\fIdest\fR); +.SH DESCRIPTION +scan_asn1dertag decodes an unsigned integer in ASN.1 DER tag encoding +from a memory area holding binary data. It writes the decode value in +\fIdest\fR and returns the number of bytes it read from \fIsrc\fR. + +scan_asn1dertag never reads more than \fIlen\fR bytes from \fIsrc\fR. If the +sequence is longer than that, or the memory area contains an invalid +sequence, scan_asn1dertag returns 0 and does not touch \fIdest\fR. + +The length of the longest ASN.1 DER length sequence is 128 bytes. In +practice the largest sequence is sizeof(*dest)+1. +.SH "SEE ALSO" +fmt_asn1dertag(3) diff --git a/scan/scan_asn1dertag.c b/scan/scan_asn1dertag.c new file mode 100644 index 0000000..7b13a27 --- /dev/null +++ b/scan/scan_asn1dertag.c @@ -0,0 +1,14 @@ +#include "scan.h" + +size_t scan_asn1dertag(const char* src,size_t len,unsigned long long* length) { + size_t n; + unsigned long long l=0; + for (n=0; n + +#ifdef __cplusplus +extern "C" { +#endif + #ifndef __pure__ #define __pure__ #endif @@ -46,4 +51,8 @@ int str_start(const char *a,const char *b) __pure__; /* convenience shortcut to test for string equality */ #define str_equal(s,t) (!str_diff((s),(t))) +#ifdef __cplusplus +} +#endif + #endif diff --git a/stralloc.h b/stralloc.h index 6904889..1c4d990 100644 --- a/stralloc.h +++ b/stralloc.h @@ -3,6 +3,11 @@ #define STRALLOC_H #include + +#ifdef __cplusplus +extern "C" { +#endif + #ifndef __pure__ #define __pure__ #endif @@ -158,4 +163,8 @@ int buffer_get_new_token_sa_pred(buffer* b,stralloc* sa,sa_predicate p); void buffer_fromsa(buffer* b,stralloc* sa); #endif +#ifdef __cplusplus +} +#endif + #endif diff --git a/tai.h b/tai.h index 79ced33..7607e27 100644 --- a/tai.h +++ b/tai.h @@ -6,6 +6,10 @@ #include "uint64.h" +#ifdef __cplusplus +extern "C" { +#endif + /* A struct tai value is an integer between 0 inclusive and 2^64 * exclusive. The format of struct tai is designed to speed up common * operations; applications should not look inside struct tai. @@ -58,4 +62,8 @@ void tai_unpack(const char *,struct tai *); void tai_uint(struct tai *,unsigned int); +#ifdef __cplusplus +} +#endif + #endif diff --git a/taia.h b/taia.h index fd68633..ee4c8a9 100644 --- a/taia.h +++ b/taia.h @@ -7,6 +7,10 @@ #include "tai.h" #include "uint32.h" +#ifdef __cplusplus +extern "C" { +#endif + /* A struct taia value is a number between 0 inclusive and 2^64 * exclusive. The number is a multiple of 10^-18. The format of struct * taia is designed to speed up common operations; applications should @@ -67,4 +71,8 @@ unsigned int taia_fmtfrac(char *s,const tai6464 *t); /* initialize t to secs seconds. */ void taia_uint(tai6464 *t,unsigned int secs); +#ifdef __cplusplus +} +#endif + #endif diff --git a/textcode.h b/textcode.h index d4c2b00..2c26c17 100644 --- a/textcode.h +++ b/textcode.h @@ -4,6 +4,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* These take len bytes from src and write them in encoded form to * dest (if dest != NULL), returning the number of bytes written. */ @@ -111,4 +115,8 @@ size_t scan_tofrom_array(size_t (*func)(const char*,char*,size_t*), extern const char base64[64]; +#ifdef __cplusplus +} +#endif + #endif diff --git a/uint16.h b/uint16.h index 024ed4b..e1479ac 100644 --- a/uint16.h +++ b/uint16.h @@ -4,6 +4,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + typedef uint16_t uint16; typedef int16_t int16; @@ -35,4 +39,8 @@ uint16 uint16_read_big(const char *in); #endif +#ifdef __cplusplus +} +#endif + #endif diff --git a/uint32.h b/uint32.h index 57aff72..fc775e2 100644 --- a/uint32.h +++ b/uint32.h @@ -4,6 +4,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + typedef uint32_t uint32; typedef int32_t int32; @@ -35,4 +39,8 @@ uint32 uint32_read_big(const char *in); #endif +#ifdef __cplusplus +} +#endif + #endif diff --git a/uint64.h b/uint64.h index 4f6d580..fef8c54 100644 --- a/uint64.h +++ b/uint64.h @@ -4,6 +4,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + typedef uint64_t uint64; typedef int64_t int64; @@ -25,4 +29,8 @@ uint64 uint64_read_big(const char *in); #endif +#ifdef __cplusplus +} +#endif + #endif diff --git a/windoze.h b/windoze.h index 4655086..80fd9ce 100644 --- a/windoze.h +++ b/windoze.h @@ -1,5 +1,9 @@ #ifdef __MINGW32__ +#ifdef __cplusplus +extern "C" { +#endif + /* set errno to WSAGetLastError() */ int winsock2errno(long l); void __winsock_init(void); @@ -9,4 +13,8 @@ void __winsock_init(void); #define winsock2errno(fnord) (fnord) #define __winsock_init() +#ifdef __cplusplus +} +#endif + #endif