Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/stdlib/set_constraint_handler_s.c
- This file was added.
/*- | |||||
* Copyright (c) 2017 Juniper Networks. All rights reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in the | |||||
* documentation and/or other materials provided with the distribution. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
*/ | |||||
#include <sys/cdefs.h> | |||||
__FBSDID("$FreeBSD$"); | |||||
#include <errno.h> | |||||
#include <stddef.h> | |||||
#include <stdlib.h> | |||||
/* rationale recommends allocating new memory each time */ | |||||
static constraint_handler_t *_ch = NULL; | |||||
constraint_handler_t | |||||
set_constraint_handler_s(constraint_handler_t handler) | |||||
{ | |||||
constraint_handler_t ret = NULL; | |||||
kib: Style prohibits local declarations with initialization. Also, a blank line is needed between… | |||||
Not Done Inline ActionsNot fixed. kib: Not fixed. | |||||
if (_ch != NULL) | |||||
Not Done Inline ActionsUse _ch == NULL comparision for pointers. Note that next if() uses style-compliant check for the same condition. kib: Use _ch == NULL comparision for pointers. Note that next if() uses style-compliant check for… | |||||
ret = *_ch; | |||||
if (_ch == NULL) | |||||
_ch = (constraint_handler_t *) | |||||
malloc(sizeof(constraint_handler_t)); | |||||
Not Done Inline ActionsContinuation line should have 4-spaces indent. kib: Continuation line should have 4-spaces indent. | |||||
if (_ch != NULL) | |||||
Not Done Inline ActionsSame. kib: Same. | |||||
*_ch = handler; | |||||
return ret; | |||||
Not Done Inline Actionsreturn (ret); kib: return (ret); | |||||
Not Done Inline ActionsNot fixed. kib: Not fixed. | |||||
} | |||||
Not Done Inline Actionsreturn (ret); (still) kib: return (ret); (still) | |||||
void | |||||
__throw_constraint_handler_s(const char * restrict msg, errno_t error) | |||||
Not Done Inline ActionsIf your intent in selecting the function name was to put it into the implementation-private namespace to minimize issues with statically-linked programs, then __throw_contraint_handler_s is a better name for the function. kib: If your intent in selecting the function name was to put it into the implementation-private… | |||||
{ | |||||
Not Done Inline ActionsThere must be an empty line after '{' and the first statement in a function without locals. if (_ch != NULL && *_ch != NULL) kib: There must be an empty line after '{' and the first statement in a function without locals.
```… | |||||
if (_ch && *_ch) | |||||
kibUnsubmitted Not Done Inline Actions!= NULL still not applied. kib: != NULL still not applied. | |||||
(*_ch)(msg, NULL, error); | |||||
} | |||||
void | |||||
abort_handler_s(const char * restrict msg __unused, | |||||
Not Done Inline ActionsContinuation line should have 4-spaces ident. kib: Continuation line should have 4-spaces ident. | |||||
void * restrict ptr __unused, errno_t error __unused) | |||||
{ | |||||
Not Done Inline ActionsBlank line. kib: Blank line. | |||||
Not Done Inline Actionsstill. kib: still. | |||||
abort(); | |||||
} | |||||
void | |||||
Not Done Inline Actions4-spaces indent. kib: 4-spaces indent. | |||||
ignore_handler_s(const char * restrict msg __unused, | |||||
void * restrict ptr __unused, errno_t error __unused) | |||||
{ | |||||
} |
Style prohibits local declarations with initialization. Also, a blank line is needed between decl section and the first statement.