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