| 1 | /*------------------------------------------------------------------ |
| 2 | * wmemset_s |
| 3 | * |
| 4 | * August 2014, D Wheeler |
| 5 | * |
| 6 | * Copyright (c) 2014 Intel Corp |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person |
| 10 | * obtaining a copy of this software and associated documentation |
| 11 | * files (the "Software"), to deal in the Software without |
| 12 | * restriction, including without limitation the rights to use, |
| 13 | * copy, modify, merge, publish, distribute, sublicense, and/or |
| 14 | * sell copies of the Software, and to permit persons to whom the |
| 15 | * Software is furnished to do so, subject to the following |
| 16 | * conditions: |
| 17 | * |
| 18 | * The above copyright notice and this permission notice shall be |
| 19 | * included in all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 23 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 26 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 27 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 28 | * OTHER DEALINGS IN THE SOFTWARE. |
| 29 | *------------------------------------------------------------------ |
| 30 | */ |
| 31 | |
| 32 | #include "safeclib_private.h" |
| 33 | #include "safe_mem_constraint.h" |
| 34 | #include "mem_primitives_lib.h" |
| 35 | #include "safe_mem_lib.h" |
| 36 | |
| 37 | |
| 38 | /** |
| 39 | * NAME |
| 40 | * wmemset_s |
| 41 | * |
| 42 | * SYNOPSIS |
| 43 | * #include "safe_mem_lib.h" |
| 44 | * errno_t |
| 45 | * wmemset_s(wchar_t *dest, wchar_t value, rsize_t len) |
| 46 | * |
| 47 | * DESCRIPTION |
| 48 | * Sets len number of wide characters starting at dest to the specified value. |
| 49 | * |
| 50 | * SPECIFIED IN |
| 51 | * ISO/IEC JTC1 SC22 WG14 N1172, Programming languages, environments |
| 52 | * and system software interfaces, Extensions to the C Library, |
| 53 | * Part I: Bounds-checking interfaces |
| 54 | * |
| 55 | * INPUT PARAMETERS |
| 56 | * dest pointer to memory that will be set to the value |
| 57 | * |
| 58 | * value byte value |
| 59 | * |
| 60 | * len number of wide characters to be set |
| 61 | * |
| 62 | * OUTPUT PARAMETERS |
| 63 | * dest is updated |
| 64 | * |
| 65 | * RUNTIME CONSTRAINTS |
| 66 | * dest shall not be a null pointer. |
| 67 | * len shall not be 0 nor greater than RSIZE_MAX_MEM/sizeof(wchar_t). |
| 68 | * If there is a runtime constraint, the operation is not performed. |
| 69 | * |
| 70 | * RETURN VALUE |
| 71 | * EOK successful operation |
| 72 | * ESNULLP NULL pointer |
| 73 | * ESZEROL zero length |
| 74 | * ESLEMAX length exceeds max limit |
| 75 | * |
| 76 | * ALSO SEE |
| 77 | * memset_s, memset16_s(), memset32_s() |
| 78 | * |
| 79 | */ |
| 80 | errno_t |
| 81 | wmemset_s (wchar_t *dest, wchar_t value, rsize_t len) |
| 82 | { |
| 83 | if (dest == NULL) { |
| 84 | invoke_safe_mem_constraint_handler("wmemset_s: dest is null", |
| 85 | NULL, ESNULLP); |
| 86 | return (RCNEGATE(ESNULLP)); |
| 87 | } |
| 88 | |
| 89 | if (len == 0) { |
| 90 | invoke_safe_mem_constraint_handler("wmemset_s: len is 0", |
| 91 | NULL, ESZEROL); |
| 92 | return (RCNEGATE(ESZEROL)); |
| 93 | } |
| 94 | |
| 95 | if (len*sizeof(wchar_t) > RSIZE_MAX_MEM) { |
| 96 | invoke_safe_mem_constraint_handler("wmemset_s: len exceeds max", |
| 97 | NULL, ESLEMAX); |
| 98 | return (RCNEGATE(ESLEMAX)); |
| 99 | } |
| 100 | |
| 101 | mem_prim_set32((uint32_t *)dest, len, value); |
| 102 | |
| 103 | return (RCNEGATE(EOK)); |
| 104 | } |
| 105 | EXPORT_SYMBOL(wmemset_s) |