Revised to prevent DHCPClient::discover from hanging.
Fork of WIZ820ioInterface by
pico_string.h@5:fb15c35d1e28, 2013-08-27 (annotated)
- Committer:
- va009039
- Date:
- Tue Aug 27 12:50:11 2013 +0000
- Revision:
- 5:fb15c35d1e28
- Child:
- 6:c466db1cd20b
WIZ820ioInterface?first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 5:fb15c35d1e28 | 1 | // pico_tring.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 | }; |