Lots of good clean-ups from Jukka Zitting!

master
leitner 23 years ago
parent ac331f66f6
commit 85c18a49cb

@ -1,6 +1,7 @@
#ifndef FMT_H #ifndef FMT_H
#define FMT_H #define FMT_H
#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_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 */ #define FMT_8LONG 44 /* enough space to hold 2^128 - 1 in octal, plus \0 */
#define FMT_XLONG 33 /* enough space to hold 2^128 - 1 in hexadecimal, plus \0 */ #define FMT_XLONG 33 /* enough space to hold 2^128 - 1 in hexadecimal, plus \0 */

@ -14,7 +14,7 @@ fmt_long does not append \\0.
If \fIdest\fR equals FMT_LEN (i.e. is zero), fmt_long returns the number If \fIdest\fR equals FMT_LEN (i.e. is zero), fmt_long returns the number
of bytes it would have written. of bytes it would have written.
For convenience, fmt.h defines the integer FMT_ULONG to be big enough to For convenience, fmt.h defines the integer FMT_LONG to be big enough to
contain every possible fmt_ulong output plus \\0. contain every possible fmt_long output plus \\0.
.SH "SEE ALSO" .SH "SEE ALSO"
scan_long(3) scan_long(3)

@ -3,12 +3,12 @@
unsigned int fmt_strn(char *out,const char *in,unsigned int limit) { unsigned int fmt_strn(char *out,const char *in,unsigned int limit) {
register char* s=out; register char* s=out;
register const char* t=in; register const char* t=in;
register const char* u=out+limit; register const char* u=in+limit;
for (;;) { for (;;) {
if (!*t) break; *s=*t; if (s==u) break; ++s; ++t; if (!*t) break; if (s) { *s=*t; ++s; } if (t==u) break; ++t;
if (!*t) break; *s=*t; if (s==u) break; ++s; ++t; if (!*t) break; if (s) { *s=*t; ++s; } if (t==u) break; ++t;
if (!*t) break; *s=*t; if (s==u) break; ++s; ++t; if (!*t) break; if (s) { *s=*t; ++s; } if (t==u) break; ++t;
if (!*t) break; *s=*t; if (s==u) break; ++s; ++t; if (!*t) break; if (s) { *s=*t; ++s; } if (t==u) break; ++t;
} }
return s-out; return t-in;
} }

@ -8,7 +8,7 @@ unsigned int fmt_ulong0(char *dest,unsigned long i,unsigned int pad) {
/* now see if we need to pad */ /* now see if we need to pad */
if (dest) { if (dest) {
while (len<pad) { *dest='0'; ++dest; ++len; } while (len<pad) { *dest='0'; ++dest; ++len; }
fmt_uint(dest,i); fmt_ulong(dest,i);
return len; return len;
} else } else
return (len<pad?pad:len); return (len<pad?pad:len);

@ -1,6 +1,8 @@
#ifndef IP6_H #ifndef IP6_H
#define IP6_H #define IP6_H
#include "byte.h"
extern unsigned int scan_ip6(const char *src,char *ip); extern unsigned int scan_ip6(const char *src,char *ip);
extern unsigned int fmt_ip6(char *dest,const char *ip); extern unsigned int fmt_ip6(char *dest,const char *ip);

@ -11,8 +11,8 @@ socket_send6 sends \fIlen\fR bytes starting at \fIbuf\fR in a UDP
datagram over the socket \fIs\fR to UDP port \fIport\fR on IP address datagram over the socket \fIs\fR to UDP port \fIport\fR on IP address
\fIip\fR. \fIip\fR.
You can call socket_send6 without calling socket_bind4. This has the You can call socket_send6 without calling socket_bind6. This has the
effect as first calling socket_bind4 with IP address :: and port 0. effect as first calling socket_bind6 with IP address :: and port 0.
The meaning of \fIscope_id\fR is dependent on the implementation and The meaning of \fIscope_id\fR is dependent on the implementation and
IPv6 IP. On link-local IPv6 addresses it specifies the outgoing IPv6 IP. On link-local IPv6 addresses it specifies the outgoing

@ -11,7 +11,7 @@ string \fIa\fR[0], \fIa\fR[1], ..., \fIa\fR[n]=='\\0' is
lexicographically smaller than, equal to, or greater than the string lexicographically smaller than, equal to, or greater than the string
\fIb\fR[0], \fIb\fR[1], ..., \fIb\fR[m-1]=='\\0'. \fIb\fR[0], \fIb\fR[1], ..., \fIb\fR[m-1]=='\\0'.
If the strings are different, str_diff does not read bytes past the If the strings are different, str_diffn does not read bytes past the
first difference. The strings will be considered equal if the first first difference. The strings will be considered equal if the first
\fIlimit\fR characters match. \fIlimit\fR characters match.
.SH "SEE ALSO" .SH "SEE ALSO"

@ -1,4 +1,4 @@
#include "byte.h" #include "str.h"
/* str_start returns 1 if the b is a prefix of a, 0 otherwise */ /* str_start returns 1 if the b is a prefix of a, 0 otherwise */
int str_start(const char* a, const char* b) { int str_start(const char* a, const char* b) {

@ -11,8 +11,8 @@ void \fBuint16_pack\fP(char \fIs\fR[2],uint16 \fIu\fR);
uint16 is a 16-bit unsigned integer type, normally either unsigned int uint16 is a 16-bit unsigned integer type, normally either unsigned int
or unsigned long. or unsigned long.
uint16_unpack portably reads a uint16 as stored on a little-endian uint16_pack portably writes a uint16 \fIu\fR to \fIs\fR in
architecture from \fIs\fR and writes it info \fIr\fR in the native byte order. little-endian byte order.
.SH "SEE ALSO" .SH "SEE ALSO"
uint16_unpack(3), uint16_pack_big(3) uint16_unpack(3), uint16_pack_big(3)

@ -11,9 +11,8 @@ void \fBuint16_pack_big\fP(char \fIs\fR[2],uint16 \fIu\fR);
uint16 is a 16-bit unsigned integer type, normally either unsigned int uint16 is a 16-bit unsigned integer type, normally either unsigned int
or unsigned long. or unsigned long.
uint16_unpack_big portably reads a uint16 as stored on a big-endian uint16_pack_big portably writes a uint16 \fIu\fR to \fIs\fR in
architecture (i.e. in network byte order) from \fIs\fR and writes it big-endian (i.e. network) byte order.
info \fIr\fR in the native byte order.
.SH "SEE ALSO" .SH "SEE ALSO"
uint16_unpack_big(3), uint16_pack(3) uint16_unpack_big(3), uint16_pack(3)

@ -12,7 +12,7 @@ uint16 is a 16-bit unsigned integer type, normally either unsigned int
or unsigned long. or unsigned long.
uint16_unpack portably reads a uint16 as stored on a little-endian uint16_unpack portably reads a uint16 as stored on a little-endian
architecture from \fIs\fR and writes it info \fIr\fR in the native byte order. architecture from \fIs\fR and writes it info \fIu\fR in the native byte order.
.SH "SEE ALSO" .SH "SEE ALSO"
uint16_pack(3), uint16_unpack_big(3) uint16_pack(3), uint16_unpack_big(3)

@ -13,7 +13,7 @@ or unsigned long.
uint16_unpack_big portably reads a uint16 as stored on a big-endian uint16_unpack_big portably reads a uint16 as stored on a big-endian
architecture (i.e. in network byte order) from \fIs\fR and writes it architecture (i.e. in network byte order) from \fIs\fR and writes it
info \fIr\fR in the native byte order. info \fIu\fR in the native byte order.
.SH "SEE ALSO" .SH "SEE ALSO"
uint16_pack_big(3), uint16_unpack(3) uint16_pack_big(3), uint16_unpack(3)

@ -11,8 +11,8 @@ void \fBuint32_pack\fP(char \fIs\fR[4],uint32 \fIu\fR);
uint32 is a 32-bit unsigned integer type, normally either unsigned int uint32 is a 32-bit unsigned integer type, normally either unsigned int
or unsigned long. or unsigned long.
uint32_unpack portably reads a uint32 as stored on a little-endian uint32_pack portably writes a uint32 \fIu\fR to \fIs\fR in
architecture from \fIs\fR and writes it info \fIr\fR in the native byte order. little-endian byte order.
.SH "SEE ALSO" .SH "SEE ALSO"
uint32_unpack(3), uint32_pack_big(3) uint32_unpack(3), uint32_pack_big(3)

@ -11,9 +11,8 @@ void \fBuint32_pack_big\fP(char \fIs\fR[4],uint32 \fIu\fR);
uint32 is a 32-bit unsigned integer type, normally either unsigned int uint32 is a 32-bit unsigned integer type, normally either unsigned int
or unsigned long. or unsigned long.
uint32_unpack_big portably reads a uint32 as stored on a big-endian uint32_pack_big portably writes a uint16 \fIu\fR to \fIs\fR in
architecture (i.e. in network byte order) from \fIs\fR and writes it big-endian (i.e. network) byte order.
info \fIr\fR in the native byte order.
.SH "SEE ALSO" .SH "SEE ALSO"
uint32_unpack_big(3), uint32_pack(3) uint32_unpack_big(3), uint32_pack(3)

@ -12,7 +12,7 @@ uint32 is a 32-bit unsigned integer type, normally either unsigned int
or unsigned long. or unsigned long.
uint32_unpack portably reads a uint32 as stored on a little-endian uint32_unpack portably reads a uint32 as stored on a little-endian
architecture from \fIs\fR and writes it info \fIr\fR in the native byte order. architecture from \fIs\fR and writes it info \fIu\fR in the native byte order.
.SH "SEE ALSO" .SH "SEE ALSO"
uint32_pack(3), uint32_unpack_big(3) uint32_pack(3), uint32_unpack_big(3)

@ -13,7 +13,7 @@ or unsigned long.
uint32_unpack_big portably reads a uint32 as stored on a big-endian uint32_unpack_big portably reads a uint32 as stored on a big-endian
architecture (i.e. in network byte order) from \fIs\fR and writes it architecture (i.e. in network byte order) from \fIs\fR and writes it
info \fIr\fR in the native byte order. info \fIu\fR in the native byte order.
.SH "SEE ALSO" .SH "SEE ALSO"
uint32_pack_big(3), uint32_unpack(3) uint32_pack_big(3), uint32_unpack(3)

@ -1,8 +1,6 @@
#ifndef UINT16_H #ifndef UINT16_H
#define UINT16_H #define UINT16_H
#include <sys/cdefs.h>
typedef unsigned short uint16; typedef unsigned short uint16;
#if defined(__i386__) && !defined(NO_UINT16_MACROS) #if defined(__i386__) && !defined(NO_UINT16_MACROS)

Loading…
Cancel
Save