+int
+readtxtbin(char *packet, char **src, size_t srcremain, char *dst, size_t dstremain)
+{
+ unsigned char *uc;
+ int tocopy;
+ int dstused = 0;
+
+ while (srcremain > 0)
+ {
+ uc = (unsigned char*) (*src);
+ tocopy = *uc;
+ (*src)++;
+ srcremain--;
+
+ if (tocopy > srcremain)
+ return 0; /* illegal, better have nothing */
+ if (tocopy > dstremain)
+ return 0; /* doesn't fit, better have nothing */
+
+ memcpy(dst, *src, tocopy);
+ dst += tocopy;
+ (*src) += tocopy;
+ srcremain -= tocopy;
+ dstremain -= tocopy;
+ dstused += tocopy;
+ }
+ return dstused;
+}
+