Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MilkcocoaOsSample_ESP8266
Fork of esp8266-driver by
ESP8266/ATParser/BufferedSerial/BufferedPrint.c@1:a45ebbd86564, 2017-02-10 (annotated)
- Committer:
- jksoft
- Date:
- Fri Feb 10 01:29:24 2017 +0000
- Revision:
- 1:a45ebbd86564
- Parent:
- 0:6946b0b9e323
no change
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| group-ESP8266 | 0:6946b0b9e323 | 1 | /* |
| group-ESP8266 | 0:6946b0b9e323 | 2 | * Copyright (c) 2014-2015 ARM Limited. All rights reserved. |
| group-ESP8266 | 0:6946b0b9e323 | 3 | * SPDX-License-Identifier: Apache-2.0 |
| group-ESP8266 | 0:6946b0b9e323 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
| group-ESP8266 | 0:6946b0b9e323 | 5 | * not use this file except in compliance with the License. |
| group-ESP8266 | 0:6946b0b9e323 | 6 | * You may obtain a copy of the License at |
| group-ESP8266 | 0:6946b0b9e323 | 7 | * |
| group-ESP8266 | 0:6946b0b9e323 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| group-ESP8266 | 0:6946b0b9e323 | 9 | * |
| group-ESP8266 | 0:6946b0b9e323 | 10 | * Unless required by applicable law or agreed to in writing, software |
| group-ESP8266 | 0:6946b0b9e323 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| group-ESP8266 | 0:6946b0b9e323 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| group-ESP8266 | 0:6946b0b9e323 | 13 | * See the License for the specific language governing permissions and |
| group-ESP8266 | 0:6946b0b9e323 | 14 | * limitations under the License. |
| group-ESP8266 | 0:6946b0b9e323 | 15 | */ |
| group-ESP8266 | 0:6946b0b9e323 | 16 | |
| group-ESP8266 | 0:6946b0b9e323 | 17 | #include <stdarg.h> |
| group-ESP8266 | 0:6946b0b9e323 | 18 | #include <stdint.h> |
| group-ESP8266 | 0:6946b0b9e323 | 19 | #include <stdio.h> |
| group-ESP8266 | 0:6946b0b9e323 | 20 | #include <string.h> |
| group-ESP8266 | 0:6946b0b9e323 | 21 | |
| group-ESP8266 | 0:6946b0b9e323 | 22 | #include "mbed_error.h" |
| group-ESP8266 | 0:6946b0b9e323 | 23 | |
| group-ESP8266 | 0:6946b0b9e323 | 24 | size_t BufferedSerialThunk(void *buf_serial, const void *s, size_t length); |
| group-ESP8266 | 0:6946b0b9e323 | 25 | |
| group-ESP8266 | 0:6946b0b9e323 | 26 | int BufferedPrintfC(void *stream, int size, const char* format, va_list arg) |
| group-ESP8266 | 0:6946b0b9e323 | 27 | { |
| group-ESP8266 | 0:6946b0b9e323 | 28 | int r; |
| group-ESP8266 | 0:6946b0b9e323 | 29 | char buffer[512]; |
| group-ESP8266 | 0:6946b0b9e323 | 30 | if (size >= 512) { |
| group-ESP8266 | 0:6946b0b9e323 | 31 | return -1; |
| group-ESP8266 | 0:6946b0b9e323 | 32 | } |
| group-ESP8266 | 0:6946b0b9e323 | 33 | memset(buffer, 0, size); |
| group-ESP8266 | 0:6946b0b9e323 | 34 | r = vsprintf(buffer, format, arg); |
| group-ESP8266 | 0:6946b0b9e323 | 35 | // this may not hit the heap but should alert the user anyways |
| group-ESP8266 | 0:6946b0b9e323 | 36 | if(r > (int32_t) size) { |
| group-ESP8266 | 0:6946b0b9e323 | 37 | error("%s %d buffer overwrite (max_buf_size: %d exceeded: %d)!\r\n", __FILE__, __LINE__, size, r); |
| group-ESP8266 | 0:6946b0b9e323 | 38 | return 0; |
| group-ESP8266 | 0:6946b0b9e323 | 39 | } |
| group-ESP8266 | 0:6946b0b9e323 | 40 | if ( r > 0 ) { |
| group-ESP8266 | 0:6946b0b9e323 | 41 | BufferedSerialThunk(stream, buffer, r); |
| group-ESP8266 | 0:6946b0b9e323 | 42 | } |
| group-ESP8266 | 0:6946b0b9e323 | 43 | return r; |
| group-ESP8266 | 0:6946b0b9e323 | 44 | } |
