1 /*------------------------------------------------------------------
2 * safe_str_constraint.c
4 * October 2008, Bo Berry
5 * 2012, Jonathan Toppins <jtoppins@users.sourceforge.net>
7 * Copyright (c) 2008, 2009, 2012 Cisco Systems
10 * Permission is hereby granted, free of charge, to any person
11 * obtaining a copy of this software and associated documentation
12 * files (the "Software"), to deal in the Software without
13 * restriction, including without limitation the rights to use,
14 * copy, modify, merge, publish, distribute, sublicense, and/or
15 * sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following
19 * The above copyright notice and this permission notice shall be
20 * included in all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 * OTHER DEALINGS IN THE SOFTWARE.
30 *------------------------------------------------------------------
33 #include "safeclib_private.h"
34 #include "safe_str_constraint.h"
35 #include "safe_str_lib.h"
38 static constraint_handler_t str_handler
= NULL
;
43 * set_str_constraint_handler_s
46 * #include "safe_str_lib.h"
47 * constraint_handler_t
48 * set_str_constraint_handler_s(constraint_handler_t handler)
51 * The set_str_constraint_handler_s function sets the runtime-constraint
52 * handler to be handler. The runtime-constraint handler is the function to
53 * be called when a library function detects a runtime-constraint
54 * violation. Only the most recent handler registered with
55 * set_str_constraint_handler_s is called when a runtime-constraint
57 * When the handler is called, it is passed the following arguments in
58 * the following order:
59 * 1. A pointer to a character string describing the
60 * runtime-constraint violation.
61 * 2. A null pointer or a pointer to an implementation defined
63 * 3. If the function calling the handler has a return type declared
64 * as errno_t, the return value of the function is passed.
65 * Otherwise, a positive value of type errno_t is passed.
66 * The implementation has a default constraint handler that is used if no
67 * calls to the set_constraint_handler_s function have been made. The
68 * behavior of the default handler is implementation-defined, and it may
69 * cause the program to exit or abort. If the handler argument to
70 * set_constraint_handler_s is a null pointer, the implementation default
71 * handler becomes the current constraint handler.
74 * ISO/IEC JTC1 SC22 WG14 N1172, Programming languages, environments
75 * and system software interfaces, Extensions to the C Library,
76 * Part I: Bounds-checking interfaces
79 * *msg Pointer to the message describing the error
81 * *ptr Pointer to aassociated data. Can be NULL.
83 * error The error code encountered.
92 * set_str_constraint_handler_s()
95 set_str_constraint_handler_s (constraint_handler_t handler
)
97 constraint_handler_t prev_handler
= str_handler
;
98 if (NULL
== handler
) {
99 str_handler
= sl_default_handler
;
101 str_handler
= handler
;
105 EXPORT_SYMBOL(set_str_constraint_handler_s
);
110 * invoke_safe_str_constraint_handler
113 * #include "safe_str_constraint.h"
115 * invoke_safe_str_constraint_handler (const char *msg,
120 * Invokes the currently set constraint handler or the default.
123 * *msg Pointer to the message describing the error
125 * *ptr Pointer to aassociated data. Can be NULL.
127 * error The error code encountered.
137 invoke_safe_str_constraint_handler (const char *msg
,
141 if (NULL
!= str_handler
) {
142 str_handler(msg
, ptr
, error
);
144 sl_default_handler(msg
, ptr
, error
);