Revised to prevent DHCPClient::discover from hanging.
Fork of WIZ820ioInterface by
pico_string.h@9:c1722862c13b, 2014-08-15 (annotated)
- Committer:
- rraab
- Date:
- Fri Aug 15 19:53:25 2014 +0000
- Revision:
- 9:c1722862c13b
- Parent:
- 6:c466db1cd20b
Fixed DHCPClient::discover calling rand, which hangs in an infinite loop.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ban4jp | 6:c466db1cd20b | 1 | // pico_string.h 2013/8/27 |
va009039 | 5:fb15c35d1e28 | 2 | #pragma once |
va009039 | 5:fb15c35d1e28 | 3 | class pico_string { |
va009039 | 5:fb15c35d1e28 | 4 | public: |
va009039 | 5:fb15c35d1e28 | 5 | pico_string(){ |
va009039 | 5:fb15c35d1e28 | 6 | _len = 0; |
va009039 | 5:fb15c35d1e28 | 7 | _buf = (char*)malloc(1); |
va009039 | 5:fb15c35d1e28 | 8 | if (_buf) { |
va009039 | 5:fb15c35d1e28 | 9 | _buf[0] = '\0'; |
va009039 | 5:fb15c35d1e28 | 10 | } |
va009039 | 5:fb15c35d1e28 | 11 | } |
va009039 | 5:fb15c35d1e28 | 12 | ~pico_string() { |
va009039 | 5:fb15c35d1e28 | 13 | if (_buf) { |
va009039 | 5:fb15c35d1e28 | 14 | free(_buf); |
va009039 | 5:fb15c35d1e28 | 15 | } |
va009039 | 5:fb15c35d1e28 | 16 | } |
va009039 | 5:fb15c35d1e28 | 17 | bool empty() { |
va009039 | 5:fb15c35d1e28 | 18 | return _len == 0; |
va009039 | 5:fb15c35d1e28 | 19 | } |
va009039 | 5:fb15c35d1e28 | 20 | void append(const char* s, int len) { |
va009039 | 5:fb15c35d1e28 | 21 | if (_buf == NULL) { |
va009039 | 5:fb15c35d1e28 | 22 | return; |
va009039 | 5:fb15c35d1e28 | 23 | } |
va009039 | 5:fb15c35d1e28 | 24 | char* p = (char*)malloc(_len+len+1); |
va009039 | 5:fb15c35d1e28 | 25 | if (p == NULL) { |
va009039 | 5:fb15c35d1e28 | 26 | return; |
va009039 | 5:fb15c35d1e28 | 27 | } |
va009039 | 5:fb15c35d1e28 | 28 | memcpy(p, _buf, _len); |
va009039 | 5:fb15c35d1e28 | 29 | memcpy(p+_len, s, len); |
va009039 | 5:fb15c35d1e28 | 30 | p[_len+len] = '\0'; |
va009039 | 5:fb15c35d1e28 | 31 | free(_buf); |
va009039 | 5:fb15c35d1e28 | 32 | _buf = p; |
va009039 | 5:fb15c35d1e28 | 33 | } |
va009039 | 5:fb15c35d1e28 | 34 | void append(const char* s) { |
va009039 | 5:fb15c35d1e28 | 35 | append(s, strlen(s)); |
va009039 | 5:fb15c35d1e28 | 36 | } |
va009039 | 5:fb15c35d1e28 | 37 | char* c_str() { |
va009039 | 5:fb15c35d1e28 | 38 | if (_buf) { |
va009039 | 5:fb15c35d1e28 | 39 | return _buf; |
va009039 | 5:fb15c35d1e28 | 40 | } |
va009039 | 5:fb15c35d1e28 | 41 | return ""; |
va009039 | 5:fb15c35d1e28 | 42 | } |
va009039 | 5:fb15c35d1e28 | 43 | private: |
va009039 | 5:fb15c35d1e28 | 44 | char* _buf; |
va009039 | 5:fb15c35d1e28 | 45 | int _len; |
va009039 | 5:fb15c35d1e28 | 46 | }; |