changeset 213:50bdc48e7487

libutil: gsm7_pack.c brought over from FC uptools
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Mar 2021 07:40:33 +0000
parents 43b57865fdb5
children 8b1eecb56cb5
files libutil/Makefile libutil/gsm7_pack.c
diffstat 2 files changed, 25 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libutil/Makefile	Sun Mar 07 06:46:21 2021 +0000
+++ b/libutil/Makefile	Sun Mar 07 07:40:33 2021 +0000
@@ -2,9 +2,9 @@
 CFLAGS=	-O2
 OBJS=	alpha_decode.o alpha_fromfile.o alpha_valid.o decimal_str.o \
 	filesearch.o gsm7_decode.o gsm7_encode.o gsm7_encode_table.o \
-	gsm7_unpack.o hexdigits.o hexread.o hexstr.o iccid_luhn.o nibbles2asc.o\
-	number_decode.o number_encode.o pinentry.o plmncodes.o plmnlist.o \
-	revnibbles.o shorthand.o
+	gsm7_pack.o gsm7_unpack.o hexdigits.o hexread.o hexstr.o iccid_luhn.o \
+	nibbles2asc.o number_decode.o number_encode.o pinentry.o plmncodes.o \
+	plmnlist.o revnibbles.o shorthand.o
 LIB=	libutil.a
 
 all:	${LIB}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libutil/gsm7_pack.c	Sun Mar 07 07:40:33 2021 +0000
@@ -0,0 +1,22 @@
+/*
+ * This library module implements the function for packing septets into octets.
+ */
+
+#include <sys/types.h>
+
+gsm7_pack(inbuf, outbuf, noctets)
+	u_char *inbuf, *outbuf;
+	unsigned noctets;
+{
+	u_char *ip = inbuf, *op = outbuf;
+	unsigned n, c;
+
+	for (n = 0; n < noctets; n++) {
+		c = n % 7;
+		*op++ = ((ip[1] << 7) | ip[0]) >> c;
+		if (c == 6)
+			ip += 2;
+		else
+			ip += 1;
+	}
+}