safec  2.1
Safe C Library - ISO TR24731 Bounds Checking Interface
safe_str_constraint.c
Go to the documentation of this file.
1 /*------------------------------------------------------------------
2  * safe_str_constraint.c
3  *
4  * October 2008, Bo Berry
5  * 2012, Jonathan Toppins <jtoppins@users.sourceforge.net>
6  *
7  * Copyright (c) 2008, 2009, 2012 Cisco Systems
8  * All rights reserved.
9  *
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
17  * conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
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  *------------------------------------------------------------------
31  */
32 
33 #include "safeclib_private.h"
34 #include "safe_str_constraint.h"
35 #include "safe_str_lib.h"
36 
37 
38 static constraint_handler_t str_handler = NULL;
39 
40 
75 constraint_handler_t
76 set_str_constraint_handler_s (constraint_handler_t handler)
77 {
78  constraint_handler_t prev_handler = str_handler;
79  if (NULL == handler) {
80  str_handler = sl_default_handler;
81  } else {
82  str_handler = handler;
83  }
84  return prev_handler;
85 }
86 EXPORT_SYMBOL(set_str_constraint_handler_s)
87 
88 
89 
98 void
100  void *ptr,
101  errno_t error)
102 {
103  if (NULL != str_handler) {
104  str_handler(msg, ptr, error);
105  } else {
106  sl_default_handler(msg, ptr, error);
107  }
108 }
static constraint_handler_t str_handler
void invoke_safe_str_constraint_handler(const char *msg, void *ptr, errno_t error)
Invokes the currently set constraint handler or the default.
constraint_handler_t set_str_constraint_handler_s(constraint_handler_t handler)
The set_str_constraint_handler_s function sets the runtime-constraint handler to be handler...