mayuresh bharmoria / Mbed OS mbed-os-example-wifi
Committer:
mayur098
Date:
Thu Jun 21 17:50:21 2018 +0000
Revision:
0:8f8e8f3cbd1c
first commit;

Who changed what in which revision?

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