summaryrefslogtreecommitdiff
path: root/src/pack.c
diff options
context:
space:
mode:
authorjohannes <johannes.herman@gmail.com>2024-02-09 12:04:48 +0100
committerjohannes <johannes.herman@gmail.com>2024-02-09 12:04:48 +0100
commit999db06982c80bec25da63e95c47d5543c741c51 (patch)
treef67cd81abf806b3ee07accc6ba6164e290cdb88f /src/pack.c
parent8b39bbde8684a6524686ec55a6e189f226866934 (diff)
added read and write ctring from int
Diffstat (limited to 'src/pack.c')
-rw-r--r--src/pack.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/pack.c b/src/pack.c
index 561846d..9e1d4fe 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -106,3 +106,36 @@ void writeint(int i, char **cp)
(*cp)++;
}
}
+
+void intstostr(const int *ints, int num, char *str)
+{
+ while (num)
+ {
+ str[0] = (((*ints) >> 24) & 0xff) - 128;
+ str[1] = (((*ints) >> 16) & 0xff) - 128;
+ str[2] = (((*ints) >> 8) & 0xff) - 128;
+ str[3] = ((*ints) & 0xff) - 128;
+ str += 4;
+ ints++;
+ num--;
+ }
+}
+
+void strtoint(const char *str, int num, int *ints)
+{
+ int intloc = 3;
+ *ints = 0;
+ while (num)
+ {
+ if (intloc < 0)
+ {
+ ints++;
+ *ints = 0;
+ intloc = 3;
+ }
+ *ints |= (*str + 128) << (8 * intloc);
+ str++;
+ intloc--;
+ num--;
+ }
+}