@ -0,0 +1,12 @@ | |||
.TH case_diffb 3 | |||
.SH NAME | |||
case_diffb \- compare strings case-insensitively | |||
.SH SYNTAX | |||
.B #include <case.h> | |||
int \fBcase_diffb\fP(const char* \fIa\fR,const char* \fIb\fR); | |||
.SH DESCRIPTION | |||
case_diffb is similar to byte_diff. The difference is that for the | |||
comparison 'A' == 'a', 'B' == 'b', ..., 'Z' == 'z'. | |||
.SH "SEE ALSO" | |||
byte_diff(3) |
@ -0,0 +1,12 @@ | |||
.TH case_diffs 3 | |||
.SH NAME | |||
case_diffs \- compare strings case-insensitively | |||
.SH SYNTAX | |||
.B #include <case.h> | |||
int \fBcase_diffs\fP(const char* \fIa\fR,const char* \fIb\fR); | |||
.SH DESCRIPTION | |||
case_diffs is similar to str_diff. The difference is that for the | |||
comparison 'A' == 'a', 'B' == 'b', ..., 'Z' == 'z'. | |||
.SH "SEE ALSO" | |||
str_diff(3) |
@ -0,0 +1,12 @@ | |||
.TH case_lowerb 3 | |||
.SH NAME | |||
case_lowerb \- compare strings case-insensitively | |||
.SH SYNTAX | |||
.B #include <case.h> | |||
int \fBcase_lowerb\fP(char* \fIs\fR,unsigned int \fIlen\fR); | |||
.SH DESCRIPTION | |||
case_lowerb converts each 'A' to 'a', 'B' to 'b', ..., 'Z' to 'z' in | |||
\fIs\fR[0], \fIs\fR[1], ..., \fIs\fR[\fIlen\fR]. | |||
.SH "SEE ALSO" | |||
case_lowerb(3) |
@ -0,0 +1,12 @@ | |||
.TH case_lowers 3 | |||
.SH NAME | |||
case_lowers \- compare strings case-insensitively | |||
.SH SYNTAX | |||
.B #include <case.h> | |||
int \fBcase_lowers\fP(char* \fIs\fR); | |||
.SH DESCRIPTION | |||
case_lowers converts each 'A' to 'a', 'B' to 'b', ..., 'Z' to 'z' for | |||
each character in \fIs\fR until the first \\0. | |||
.SH "SEE ALSO" | |||
case_lowerb(3) |
@ -0,0 +1,12 @@ | |||
.TH case_starts 3 | |||
.SH NAME | |||
case_starts \- compare prefixes of strings case-insensitively | |||
.SH SYNTAX | |||
.B #include <case.h> | |||
int \fBcase_starts\fP(const char* \fIa\fR,const char* \fIb\fR); | |||
.SH DESCRIPTION | |||
case_starts returns 1 if \fIb\fR is a prefix of \fIa\fR, 0 otherwise. | |||
For this comparison, 'A' == 'a', 'B' == 'b', ..., 'Z' == 'z'. | |||
.SH "SEE ALSO" | |||
str_start(3) |
@ -0,0 +1,19 @@ | |||
#include "case.h" | |||
/* str_start returns 1 if the b is a prefix of a, 0 otherwise */ | |||
int case_starts(const char* a, const char* b) { | |||
register const char* s=a; | |||
register const char* t=b; | |||
for (;;) { | |||
register unsigned char x,y; | |||
if (!*t) return 1; | |||
x = *s - 'A'; | |||
if (x <= 'Z' - 'A') x += 'a'; else x += 'A'; | |||
y = *t - 'A'; | |||
if (y <= 'Z' - 'A') y += 'a'; else y += 'A'; | |||
if (x != y) break; | |||
if (!x) break; | |||
++s; ++t; | |||
} | |||
return 0; | |||
} |
@ -0,0 +1,16 @@ | |||
.TH openreadclose 3 | |||
.SH NAME | |||
openreadclose \- read a whole file into a stralloc | |||
.SH SYNTAX | |||
.B #include <openreadclose.h> | |||
extern int \fBopenreadclose\fP(const char *\fIfilename\fR, | |||
stralloc* \fIsa\fR,unsigned int \fIbufsize\fR); | |||
.SH DESCRIPTION | |||
openreadclose opens the file \fIfilename\fR for reading and reads the | |||
whole content into the stralloc \fIsa\fR. The file is read in chunks of | |||
\fIbufsize\fR bytes size. If everything worked fine, openreadclose | |||
returns 0. A not existing file is treated as an empty file. On error, | |||
openreadclose returns -1 and sets errno appropriately. | |||
.SH "SEE ALSO" | |||
open_read(3), readclose(3) |
@ -0,0 +1,14 @@ | |||
.TH readclose 3 | |||
.SH NAME | |||
readclose \- read a whole file into a stralloc | |||
.SH SYNTAX | |||
.B #include <readclose.h> | |||
int \fBreadclose\fP(int fd,stralloc* \fIsa\fR,unsigned int \fIbufsize\fR); | |||
.SH DESCRIPTION | |||
readclose reads the | |||
whole content into the stralloc \fIsa\fR. The file is read in chunks of | |||
\fIbufsize\fR bytes size. If everything worked fine, readclose returns | |||
0. On error, readclose returns -1 and sets errno appropriately. | |||
.SH "SEE ALSO" | |||
open_read(3), openreadclose(3), readclose_append(3) |
@ -0,0 +1,16 @@ | |||
.TH readclose_append 3 | |||
.SH NAME | |||
readclose_append \- read a whole file into a stralloc | |||
.SH SYNTAX | |||
.B #include <readclose.h> | |||
int \fBreadclose_append\fP(int fd,stralloc* \fIsa\fR, | |||
unsigned int \fIbufsize\fR); | |||
.SH DESCRIPTION | |||
readclose_append reads the | |||
whole content into the stralloc \fIsa\fR, appending it to the existing | |||
content. The file is read in chunks of | |||
\fIbufsize\fR bytes size. If everything worked fine, readclose_append returns | |||
0. On error, readclose_append returns -1 and sets errno appropriately. | |||
.SH "SEE ALSO" | |||
open_read(3), openreadclose(3), readclose(3) |
@ -0,0 +1,13 @@ | |||
.TH tai_add 3 | |||
.SH NAME | |||
tai_add \- add two struct tai | |||
.SH SYNTAX | |||
.B #include <tai.h> | |||
extern int \fBtai_add\fP(struct tai* \fIt\fR,const struct tai* \fIa\fR, | |||
const struct tai* \fIb\fR); | |||
.SH DESCRIPTION | |||
\fBtai_add\fR adds \fIa\fR to \fIb\fR and writes the result to \fIt\fR. | |||
The inputs and output may overlap. | |||
.SH "SEE ALSO" | |||
taia_add(3), tai_sub(3) |
@ -0,0 +1,12 @@ | |||
.TH tai_approx 3 | |||
.SH NAME | |||
tai_approx \- return double-precision approximation | |||
.SH SYNTAX | |||
.B #include <tai.h> | |||
extern int \fBtai_approx\fP(const struct tai* \fIt\fR); | |||
.SH DESCRIPTION | |||
tai_approx returns a double-precision approximation of \fIt\fR. The result of | |||
tai_approx is always nonnegative. | |||
.SH "SEE ALSO" | |||
taia_approx(3) |
@ -0,0 +1,12 @@ | |||
.TH tai_less 3 | |||
.SH NAME | |||
tai_less \- compare two struct tai | |||
.SH SYNTAX | |||
.B #include <tai.h> | |||
extern int \fBtai_less\fP(const struct tai* \fIa\fR, | |||
const struct tai* \fIb\fR); | |||
.SH DESCRIPTION | |||
\fBtai_less\fR returns 1 if \fIa\fR is less than \fIb\fR, 0 otherwise. | |||
.SH "SEE ALSO" | |||
taia_less(3) |
@ -0,0 +1,18 @@ | |||
.TH tai_now 3 | |||
.SH NAME | |||
tai_now \- get current time | |||
.SH SYNTAX | |||
.B #include <tai.h> | |||
extern int \fBtai_now\fP(struct tai* \fIt\fR); | |||
.SH DESCRIPTION | |||
tai_now puts the current time into \fIt\fR. More precisely: tai_now puts into | |||
\fIt\fR its best guess as to the TAI64 label for the 1-second interval that | |||
contains the current time. | |||
This implementation of tai_now assumes that the time_t returned from the | |||
time function represents the number of TAI seconds since 1970-01-01 | |||
00:00:10 TAI. This matches the convention used by the Olson tz library | |||
in ``right'' mode. | |||
.SH "SEE ALSO" | |||
taia_now(3) |
@ -0,0 +1,14 @@ | |||
.TH tai_pack 3 | |||
.SH NAME | |||
tai_pack \- convert to external TAI64 format | |||
.SH SYNTAX | |||
.B #include <tai.h> | |||
extern int \fBtai_pack\fP(char* buf,const struct tai* \fIt\fR); | |||
.SH DESCRIPTION | |||
tai_pack converts a TAI64 label from internal format in \fIt\fR to external | |||
TAI64 format in \fIbuf\fR. | |||
See http://cr.yp.to/libtai/tai64.html | |||
.SH "SEE ALSO" | |||
taia_pack(3), tai_unpack(3) |
@ -0,0 +1,13 @@ | |||
.TH tai_sub 3 | |||
.SH NAME | |||
tai_sub \- subtract two struct tai | |||
.SH SYNTAX | |||
.B #include <tai.h> | |||
extern int \fBtai_sub\fP(struct tai* \fIt\fR,const struct tai* \fIa\fR, | |||
const struct tai* \fIb\fR); | |||
.SH DESCRIPTION | |||
\fBtai_sub\fR subtracts \fIb\fR from \fIa\fR and writes the result to \fIt\fR. | |||
The inputs and output may overlap. | |||
.SH "SEE ALSO" | |||
taia_sub(3), tai_add(3) |
@ -0,0 +1,12 @@ | |||
.TH tai_unpack 3 | |||
.SH NAME | |||
tai_unpack \- convert to external TAI64 format | |||
.SH SYNTAX | |||
.B #include <tai.h> | |||
extern int \fBtai_unpack\fP(const char* buf,struct tai* \fIt\fR); | |||
.SH DESCRIPTION | |||
tai_unpack converts a TAI64 label from external TAI64 format in | |||
\fIbuf\fR to internal format in \fIt\fR. | |||
.SH "SEE ALSO" | |||
taia_unpack(3), tai_pack(3) |
@ -0,0 +1,13 @@ | |||
.TH taia_add 3 | |||
.SH NAME | |||
taia_add \- add two struct taia | |||
.SH SYNTAX | |||
.B #include <taia.h> | |||
extern int \fBtaia_add\fP(struct taia* \fIt\fR,const struct taia* \fIa\fR, | |||
const struct taia* \fIb\fR); | |||
.SH DESCRIPTION | |||
\fBtaia_add\fR adds \fIa\fR to \fIb\fR and writes the result to \fIt\fR. | |||
The inputs and output may overlap. | |||
.SH "SEE ALSO" | |||
tai_add(3), taia_sub(3), taia_addsec(3) |
@ -0,0 +1,13 @@ | |||
.TH taia_addsec 3 | |||
.SH NAME | |||
taia_addsec \- add n seconds to a struct taia | |||
.SH SYNTAX | |||
.B #include <taia.h> | |||
extern int \fBtaia_addsec\fP(struct taia* \fIt\fR,const struct taia* \fIs\fR, | |||
int \fIsecs\fR); | |||
.SH DESCRIPTION | |||
\fBtaia_addsec\fR adds \fIsecs\fR seconds to \fIs\fR and writes the result to \fIt\fR. | |||
The inputs and output may overlap. | |||
.SH "SEE ALSO" | |||
taia_sub(3), taia_add(3) |
@ -0,0 +1,12 @@ | |||
.TH taia_approx 3 | |||
.SH NAME | |||
taia_approx \- return double-precision approximation | |||
.SH SYNTAX | |||
.B #include <taia.h> | |||
extern int \fBtaia_approx\fP(const struct taia* \fIt\fR); | |||
.SH DESCRIPTION | |||
taia_approx returns a double-precision approximation of \fIt\fR. The result of | |||
taia_approx is always nonnegative. | |||
.SH "SEE ALSO" | |||
tai_approx(3) |
@ -0,0 +1,12 @@ | |||
.TH taia_frac 3 | |||
.SH NAME | |||
taia_frac \- get current time | |||
.SH SYNTAX | |||
.B #include <taia.h> | |||
int \fBtaia_frac\fP(const struct taia* \fIt\fR); | |||
.SH DESCRIPTION | |||
taia_frac returns a double-precision approximation to the fraction part | |||
of \fIt\fR. The result of taia_frac is always nonnegative. | |||
.SH "SEE ALSO" | |||
taia_approx(3) |
@ -0,0 +1,12 @@ | |||
.TH taia_less 3 | |||
.SH NAME | |||
taia_less \- compare two struct taia | |||
.SH SYNTAX | |||
.B #include <taia.h> | |||
extern int \fBtaia_less\fP(const struct tai* \fIa\fR, | |||
const struct tai* \fIb\fR); | |||
.SH DESCRIPTION | |||
\fBtaia_less\fR returns 1 if \fIa\fR is less than \fIb\fR, 0 otherwise. | |||
.SH "SEE ALSO" | |||
taia_less(3) |
@ -0,0 +1,22 @@ | |||
.TH taia_now 3 | |||
.SH NAME | |||
taia_now \- get current time | |||
.SH SYNTAX | |||
.B #include <taia.h> | |||
extern int \fBtaia_now\fP(struct taia* \fIt\fR); | |||
.SH DESCRIPTION | |||
taia_now puts the current time into \fIt\fR. More precisely: tai_now puts into | |||
\fIt\fR its best guess as to the TAI64NA label for the 1-attosecond interval that | |||
contains the current time. | |||
This implementation of taia_now assumes that the time_t returned from | |||
the time function represents the number of TAI seconds since 1970-01-01 | |||
00:00:10 TAI. This matches the convention used by the Olson tz library | |||
in ``right'' mode. | |||
Beware that many clocks are not set accurately, and even the best | |||
scientific clocks are nowhere near 1-attosecond accuracy; however, an | |||
inaccurate clock may still produce reasonably accurate time differences. | |||
.SH "SEE ALSO" | |||
tai_now(3) |
@ -0,0 +1,14 @@ | |||
.TH taia_pack 3 | |||
.SH NAME | |||
taia_pack \- convert to external TAI64NA format | |||
.SH SYNTAX | |||
.B #include <taia.h> | |||
extern int \fBtaia_pack\fP(char* buf,const struct taia* \fIt\fR); | |||
.SH DESCRIPTION | |||
taia_pack converts a TAI64NA label from internal format in \fIt\fR to external | |||
TAI64NA format in \fIbuf\fR. | |||
See http://cr.yp.to/libtai/tai64.html | |||
.SH "SEE ALSO" | |||
tai_pack(3), taia_unpack(3) |
@ -0,0 +1,13 @@ | |||
.TH taia_sub 3 | |||
.SH NAME | |||
taia_sub \- subtract two struct taia | |||
.SH SYNTAX | |||
.B #include <taia.h> | |||
extern int \fBtaia_sub\fP(struct taia* \fIt\fR,const struct taia* \fIa\fR, | |||
const struct taia* \fIb\fR); | |||
.SH DESCRIPTION | |||
\fBtaia_sub\fR subtracts \fIb\fR from \fIa\fR and writes the result to \fIt\fR. | |||
The inputs and output may overlap. | |||
.SH "SEE ALSO" | |||
tai_sub(3), taia_add(3) |
@ -0,0 +1,11 @@ | |||
.TH taia_tai 3 | |||
.SH NAME | |||
taia_tai \- get current time | |||
.SH SYNTAX | |||
.B #include <taia.h> | |||
extern int \fBtaia_tai\fP(const struct taia* \fIt\fR,struct tai* \fIsec\fR); | |||
.SH DESCRIPTION | |||
taia_tai places into \fIsec\fR the integer part of \fIt\fR. If \fIt\fR | |||
contains a TAI64NA label then \fIsec\fR will contain the corresponding | |||
TAI64 label. |
@ -0,0 +1,10 @@ | |||
.TH taia_uint 3 | |||
.SH NAME | |||
taia_uint \- convert seconds into struct taia | |||
.SH SYNTAX | |||
.B #include <taia.h> | |||
extern int \fBtaia_uint\fP(struct taia* \fIt\fR,unsigned int \fIsecs\fR); | |||
.SH DESCRIPTION | |||
taia_uint converts \fIsecs\fR into a struct taia (setting the fractional | |||
part to zero). |
@ -0,0 +1,12 @@ | |||
.TH taia_unpack 3 | |||
.SH NAME | |||
taia_unpack \- convert to external TAI64NA format | |||
.SH SYNTAX | |||
.B #include <taia.h> | |||
extern int \fBtaia_unpack\fP(const char* buf,struct taia* \fIt\fR); | |||
.SH DESCRIPTION | |||
taia_unpack converts a TAI64NA label from external TAI64NA format in | |||
\fIbuf\fR to internal format in \fIt\fR. | |||
.SH "SEE ALSO" | |||
tai_unpack(3), taia_pack(3) |
@ -0,0 +1,22 @@ | |||
#include "taia.h" | |||
void taia_unpack(s,t) | |||
char *s; | |||
struct taia *t; | |||
{ | |||
unsigned long x; | |||
tai_unpack(s,&t->sec); | |||
s += 8; | |||
x = (unsigned char) s[4]; | |||
x <<= 8; x += (unsigned char) s[5]; | |||
x <<= 8; x += (unsigned char) s[6]; | |||
x <<= 8; x += (unsigned char) s[7]; | |||
t->atto = x; | |||
x = (unsigned char) s[0]; | |||
x <<= 8; x += (unsigned char) s[1]; | |||
x <<= 8; x += (unsigned char) s[2]; | |||
x <<= 8; x += (unsigned char) s[3]; | |||
t->nano = x; | |||
} |
@ -0,0 +1,39 @@ | |||
#include <dns.h> | |||
#include <ip4.h> | |||
#include <buffer.h> | |||
#include <errno.h> | |||
#include <string.h> | |||
int main(int argc,char* argv[]) { | |||
static char seed[128]; | |||
static stralloc fqdn; | |||
static stralloc out; | |||
char str[IP4_FMT]; | |||
int i; | |||
dns_random_init(seed); | |||
if (*argv) ++argv; | |||
while (*argv) { | |||
if (!stralloc_copys(&fqdn,*argv)) { | |||
buffer_putsflush(buffer_2,"out of memory\n"); | |||
return 111; | |||
} | |||
if (dns_ip4(&out,&fqdn) == -1) { | |||
buffer_puts(buffer_2,"unable to find IP address for "); | |||
buffer_puts(buffer_2,*argv); | |||
buffer_puts(buffer_2,": "); | |||
buffer_puts(buffer_2,strerror(errno)); | |||
buffer_putnlflush(buffer_2); | |||
return 111; | |||
} | |||
for (i = 0;i + 4 <= out.len;i += 4) { | |||
buffer_put(buffer_1,str,ip4_fmt(str,out.s + i)); | |||
buffer_puts(buffer_1," "); | |||
} | |||
buffer_puts(buffer_1,"\n"); | |||
++argv; | |||
} | |||
buffer_flush(buffer_1); | |||
return 0; | |||
} |
@ -0,0 +1,51 @@ | |||
.TH iopause 3 | |||
.SH NAME | |||
iopause \- | |||
.SH SYNTAX | |||
.B #include <iopause.h> | |||
int \fBiopause\fP(iopause_fd** \fIx\fR,unsigned int \fIlen\fR, | |||
struct taia \fIdeadline\fR,struct taia \fIstamp\fR); | |||
.SH DESCRIPTION | |||
iopause checks for file descriptor readability or writability as specified | |||
by \fIx\fR[0].fd, \fIx\fR[0].events, \fIx\fR[1].fd, \fIx\fR[1].events, ..., \fIx\fR[\fIlen\fR-1].fd, | |||
\fIx\fR[\fIlen\fR-1].events. If \fIx\fR[i].events includes the bit IOPAUSE_READ, iopause | |||
checks for readability of the descriptor \fIx\fR[i].fd; if \fIx\fR[i].events includes | |||
the bit IOPAUSE_WRITE, iopause checks for writability of the descriptor | |||
\fIx\fR[i].fd; other bits in \fIx\fR[i].events have undefined effects. | |||
iopause sets the IOPAUSE_READ bit in \fIx\fR[i].revents if it finds that \fIx\fR[i].fd | |||
is readable, and it sets the IOPAUSE_WRITE bit in \fIx\fR[i].revents if it finds | |||
that \fIx\fR[i].fd is writable. Beware that readability and writability may be | |||
destroyed at any moment by other processes with access to the same ofile | |||
that \fIx\fR[i].fd refers to. | |||
If there is no readability or writability to report, iopause waits until | |||
\fIdeadline\fR for something to happen. iopause will return before \fIdeadline\fR if a | |||
descriptor becomes readable or writable, or an interrupting signal | |||
arrives, or some system-defined amount of time passes. iopause sets | |||
revents in any case. | |||
You must put a current timestamp into \fIstamp\fR before calling iopause. | |||
.SH "IMPLEMENTATION NOTES" | |||
The current implementation of iopause uses the \fBpoll\fR function if that is | |||
available. On some systems, \fBpoll\fR needs to dynamically allocate kernel | |||
memory; when not much memory is available, iopause will return | |||
immediately, and will report (often incorrectly) that no descriptors are | |||
readable or writable. This is a kernel bug, and I encourage vendors to fix | |||
it. | |||
If \fBpoll\fR is not available, iopause uses the \fBselect\fR function. This function | |||
cannot see descriptor numbers past a system-defined limit, typically 256 | |||
or 1024; iopause will artificially pretend that those descriptors are | |||
never readable or writable. | |||
Future implementations of iopause may work around these problems on some | |||
systems, at the expense of chewing up all available CPU time. | |||
Both \fBpoll\fR and \fBselect\fR use relative timeouts rather than absolute deadlines. | |||
Some kernels round the timeout down to a multiple of 10 milliseconds; this | |||
can burn quite a bit of CPU time as the deadline approaches. iopause | |||
compensates for this by adding 20 milliseconds to the timeout. | |||
.SH "SEE ALSO" | |||
select(2), poll(3), taia_now(3) |