Everything Example
Dependencies: EthernetInterface mbed-rtos mbed
Fork of TCPEthernet by
util.cpp@9:b08a28f659eb, 2017-01-24 (annotated)
- Committer:
- lachu
- Date:
- Tue Jan 24 22:17:00 2017 +0000
- Revision:
- 9:b08a28f659eb
Working Program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lachu | 9:b08a28f659eb | 1 | /* |
lachu | 9:b08a28f659eb | 2 | * (c) Copyright 2012 EVRYTHNG Ltd London / Zurich |
lachu | 9:b08a28f659eb | 3 | * www.evrythng.com |
lachu | 9:b08a28f659eb | 4 | * |
lachu | 9:b08a28f659eb | 5 | * --- DISCLAIMER --- |
lachu | 9:b08a28f659eb | 6 | * |
lachu | 9:b08a28f659eb | 7 | * EVRYTHNG provides this source code "as is" and without warranty of any kind, |
lachu | 9:b08a28f659eb | 8 | * and hereby disclaims all express or implied warranties, including without |
lachu | 9:b08a28f659eb | 9 | * limitation warranties of merchantability, fitness for a particular purpose, |
lachu | 9:b08a28f659eb | 10 | * performance, accuracy, reliability, and non-infringement. |
lachu | 9:b08a28f659eb | 11 | * |
lachu | 9:b08a28f659eb | 12 | * Author: Michel Yerly |
lachu | 9:b08a28f659eb | 13 | * |
lachu | 9:b08a28f659eb | 14 | */ |
lachu | 9:b08a28f659eb | 15 | #include "util.h" |
lachu | 9:b08a28f659eb | 16 | |
lachu | 9:b08a28f659eb | 17 | Serial dbg(USBTX, USBRX); |
lachu | 9:b08a28f659eb | 18 | |
lachu | 9:b08a28f659eb | 19 | |
lachu | 9:b08a28f659eb | 20 | void sprinti64(char* dest, int64_t v, char** end) |
lachu | 9:b08a28f659eb | 21 | { |
lachu | 9:b08a28f659eb | 22 | int len; |
lachu | 9:b08a28f659eb | 23 | if (v != 0x8000000000000000LL) { |
lachu | 9:b08a28f659eb | 24 | char str[20]; |
lachu | 9:b08a28f659eb | 25 | int p = sizeof(str); |
lachu | 9:b08a28f659eb | 26 | str[--p] = '\0'; |
lachu | 9:b08a28f659eb | 27 | str[p-1] = '0'; |
lachu | 9:b08a28f659eb | 28 | bool neg = false; |
lachu | 9:b08a28f659eb | 29 | if (v < 0) { |
lachu | 9:b08a28f659eb | 30 | v = -v; |
lachu | 9:b08a28f659eb | 31 | neg = true; |
lachu | 9:b08a28f659eb | 32 | } |
lachu | 9:b08a28f659eb | 33 | while (v > 0) { |
lachu | 9:b08a28f659eb | 34 | str[--p] = '0' + (v % 10); |
lachu | 9:b08a28f659eb | 35 | v /= 10; |
lachu | 9:b08a28f659eb | 36 | } |
lachu | 9:b08a28f659eb | 37 | if (neg) { |
lachu | 9:b08a28f659eb | 38 | str[--p] = '-'; |
lachu | 9:b08a28f659eb | 39 | } |
lachu | 9:b08a28f659eb | 40 | len = sizeof(str) - p; |
lachu | 9:b08a28f659eb | 41 | strncpy(dest, str + p, len); |
lachu | 9:b08a28f659eb | 42 | } else { |
lachu | 9:b08a28f659eb | 43 | len = 20; |
lachu | 9:b08a28f659eb | 44 | strncpy(dest, "-9223372036854775808", len); |
lachu | 9:b08a28f659eb | 45 | } *end = dest + len; |
lachu | 9:b08a28f659eb | 46 | } |