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