diff options
author | Simon Rettberg | 2014-03-15 01:49:50 +0100 |
---|---|---|
committer | Simon Rettberg | 2014-03-15 01:49:50 +0100 |
commit | bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad (patch) | |
tree | c7d1995a09f6ed0c4e6873252e957d72f5d07d07 /fmt_asn1sintpayload.c | |
download | ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.gz ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.xz ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.zip |
Lean and mean initial commit
Not much functionality yet
Diffstat (limited to 'fmt_asn1sintpayload.c')
-rw-r--r-- | fmt_asn1sintpayload.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/fmt_asn1sintpayload.c b/fmt_asn1sintpayload.c new file mode 100644 index 0000000..257135e --- /dev/null +++ b/fmt_asn1sintpayload.c @@ -0,0 +1,22 @@ +#include "asn1.h" + +size_t fmt_asn1sintpayload(char* dest,signed long l) { + size_t needed=sizeof l,i; + signed long tmp=0x7f; + if (l>=0) return fmt_asn1intpayload(dest,l); + for (i=1; i<needed; ++i) { + /* assumes two's complement */ + if ((l|tmp) == -1) + break; + tmp=(tmp<<8)|0xff; + } + if (dest) { + size_t j=i; + while (j) { + --j; + *dest=(l>>(j*8))&0xff; + ++dest; + } + } + return i; +} |