Browse Source

add uint16_read API like uint32_read

master
Felix von Leitner 20 years ago
parent
commit
fc731fac13
  1. 1
      CHANGES
  2. 16
      uint/uint16_read.3
  3. 6
      uint/uint16_read.c
  4. 16
      uint/uint16_read_big.3
  5. 6
      uint/uint16_read_big.c
  6. 37
      uint16.h

1
CHANGES

@ -1,6 +1,7 @@
0.13:
fixed several bugs in test/uudecode.c
add uninstall target
add uint16_read API like the uint32_read one
0.12:
add textcode api for uuencode/uudecode, base64, quoted printable,

16
uint/uint16_read.3

@ -0,0 +1,16 @@
.TH uint16_read 3
.SH NAME
uint16_read \- read an unsigned little-endian 16-bit integer
.SH SYNTAX
.B #include <uint16.h>
uint16 \fBuint16_read\fP(const char \fIs\fR[4]);
.SH DESCRIPTION
uint16 is a 16-bit unsigned integer type, normally either unsigned int
or unsigned long.
uint16_read portably reads a uint16 as stored on a little-endian
architecture from \fIs\fR and returns it.
.SH "SEE ALSO"
uint16_unpack(3), uint16_unpack_big(3)

6
uint/uint16_read.c

@ -0,0 +1,6 @@
#define NO_UINT16_MACROS
#include "uint16.h"
uint16 uint16_read(const char *in) {
return ((unsigned short)((unsigned char) in[1]) << 8) + (unsigned char)in[0];
}

16
uint/uint16_read_big.3

@ -0,0 +1,16 @@
.TH uint16_read_big 3
.SH NAME
uint16_read_big \- read an unsigned big-endian 16-bit integer
.SH SYNTAX
.B #include <uint16.h>
uint16 \fBuint16_read_big\fP(const char \fIs\fR[4]);
.SH DESCRIPTION
uint16 is a 16-bit unsigned integer type, normally either unsigned int
or unsigned long.
uint16_read_big portably reads a uint16 as stored on a big-endian
architecture from \fIs\fR and returns it.
.SH "SEE ALSO"
uint16_unpack(3), uint16_unpack_big(3)

6
uint/uint16_read_big.c

@ -0,0 +1,6 @@
#define NO_UINT16_MACROS
#include "uint16.h"
uint16 uint16_read_big(const char *in) {
return ((unsigned short)((unsigned char) in[0]) << 8) + (unsigned char)in[1];
}

37
uint16.h

@ -5,40 +5,21 @@
typedef unsigned short uint16;
#ifndef __linux__
#define NO_UINT16_MACROS
#endif
#ifdef NO_UINT16_MACROS
extern void uint16_pack(char *out,uint16 in);
#if defined(__i386__) && !defined(NO_UINT16_MACROS)
#define uint16_pack(out,in) (*(uint16*)(out)=(in))
#define uint16_unpack(in,out) (*(out)=*(uint16*)(in))
#define uint16_read(in) (*(uint16*)(in))
extern void uint16_pack_big(char *out,uint16 in);
extern void uint16_unpack(const char *in,uint16* out);
extern void uint16_unpack_big(const char *in,uint16* out);
#else
#include <endian.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define uint16_pack(out,in) (*(short*)(out)=(in))
extern void uint16_pack_big(char *out,uint16 in);
#define uint16_unpack(in,out) (*(out)=*(short*)(in))
extern void uint16_unpack_big(const char *in,uint16* out);
extern uint16 uint16_read_big(const char *in);
#else
extern void uint16_pack(char *out,uint16 in);
#define uint16_pack_big(out,in) (*(short*)(out)=(in))
extern void uint16_pack_big(char *out,uint16 in);
extern void uint16_unpack(const char *in,uint16* out);
#define uint16_unpack_big(in,out) (*(out)=*(short*)(in))
#endif
extern void uint16_unpack_big(const char *in,uint16* out);
extern uint16 uint16_read(const char *in);
extern uint16 uint16_read_big(const char *in);
#endif

Loading…
Cancel
Save