123r
Dependencies: WNC14A2AInterface
esp8266-driver/ESP8266/ATParser/BufferedSerial/BufferedPrint.c@0:2563b0415d1f, 2017-04-19 (annotated)
- Committer:
- JMF
- Date:
- Wed Apr 19 01:13:10 2017 +0000
- Revision:
- 0:2563b0415d1f
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JMF | 0:2563b0415d1f | 1 | /* |
JMF | 0:2563b0415d1f | 2 | * Copyright (c) 2014-2015 ARM Limited. All rights reserved. |
JMF | 0:2563b0415d1f | 3 | * SPDX-License-Identifier: Apache-2.0 |
JMF | 0:2563b0415d1f | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
JMF | 0:2563b0415d1f | 5 | * not use this file except in compliance with the License. |
JMF | 0:2563b0415d1f | 6 | * You may obtain a copy of the License at |
JMF | 0:2563b0415d1f | 7 | * |
JMF | 0:2563b0415d1f | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
JMF | 0:2563b0415d1f | 9 | * |
JMF | 0:2563b0415d1f | 10 | * Unless required by applicable law or agreed to in writing, software |
JMF | 0:2563b0415d1f | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
JMF | 0:2563b0415d1f | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
JMF | 0:2563b0415d1f | 13 | * See the License for the specific language governing permissions and |
JMF | 0:2563b0415d1f | 14 | * limitations under the License. |
JMF | 0:2563b0415d1f | 15 | */ |
JMF | 0:2563b0415d1f | 16 | |
JMF | 0:2563b0415d1f | 17 | #include <stdarg.h> |
JMF | 0:2563b0415d1f | 18 | #include <stdint.h> |
JMF | 0:2563b0415d1f | 19 | #include <stdio.h> |
JMF | 0:2563b0415d1f | 20 | #include <string.h> |
JMF | 0:2563b0415d1f | 21 | |
JMF | 0:2563b0415d1f | 22 | #include "mbed_error.h" |
JMF | 0:2563b0415d1f | 23 | |
JMF | 0:2563b0415d1f | 24 | size_t BufferedSerialThunk(void *buf_serial, const void *s, size_t length); |
JMF | 0:2563b0415d1f | 25 | |
JMF | 0:2563b0415d1f | 26 | int BufferedPrintfC(void *stream, int size, const char* format, va_list arg) |
JMF | 0:2563b0415d1f | 27 | { |
JMF | 0:2563b0415d1f | 28 | int r; |
JMF | 0:2563b0415d1f | 29 | char buffer[512]; |
JMF | 0:2563b0415d1f | 30 | if (size >= 512) { |
JMF | 0:2563b0415d1f | 31 | return -1; |
JMF | 0:2563b0415d1f | 32 | } |
JMF | 0:2563b0415d1f | 33 | memset(buffer, 0, size); |
JMF | 0:2563b0415d1f | 34 | r = vsprintf(buffer, format, arg); |
JMF | 0:2563b0415d1f | 35 | // this may not hit the heap but should alert the user anyways |
JMF | 0:2563b0415d1f | 36 | if(r > (int32_t) size) { |
JMF | 0:2563b0415d1f | 37 | error("%s %d buffer overwrite (max_buf_size: %d exceeded: %d)!\r\n", __FILE__, __LINE__, size, r); |
JMF | 0:2563b0415d1f | 38 | return 0; |
JMF | 0:2563b0415d1f | 39 | } |
JMF | 0:2563b0415d1f | 40 | if ( r > 0 ) { |
JMF | 0:2563b0415d1f | 41 | BufferedSerialThunk(stream, buffer, r); |
JMF | 0:2563b0415d1f | 42 | } |
JMF | 0:2563b0415d1f | 43 | return r; |
JMF | 0:2563b0415d1f | 44 | } |