1 /*
2  * Copyright (c) 2017 Johannes Lorenz
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25  /**
26  * @file util.h
27  * Utilities shared by rtosc functions
28  *
29  * @test util.c
30  */
31 
32 #ifndef UTIL_H
33 #define UTIL_H
34 
35 #include <stdlib.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /**
42  * Copy string to another memory location, including the terminating zero byte
43  * @param dest Destination memory location
44  * @param src Source string
45  * @param buffersize Maximal number of bytes that you can write to @p dest
46  * @return A pointer to @p dest
47  * @warning @p dest and @p src shall not overlap
48  * @warning if buffersize is larger than strlen(src)+1, unused bytes in @p dest
49  *   are not overwritten. Secure information may be released. Don't use this if
50  *   you want to send the string somewhere else, e.g. via IPC.
51  */
52 char *fast_strcpy(char *dest, const char *src, size_t buffersize);
53 
54 /*TODO: Add documentation?*/
55 #ifdef _MSC_VER
56 #define STACKALLOC(type, name, size) type *name = (type*)(_alloca((size)*sizeof(type)))
57 #else
58 #define STACKALLOC(type, name, size) type name[size]
59 #endif
60 #ifdef __cplusplus
61 }
62 #endif
63 
64 #endif // UTIL_H
65