Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/string/memset.3
| Show All 23 Lines | |||||
| .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||||
| .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||||
| .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
| .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
| .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | .\" 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 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
| .\" SUCH DAMAGE. | .\" SUCH DAMAGE. | ||||
| .\" | .\" | ||||
| .Dd August 19, 2018 | .Dd October 24, 2024 | ||||
| .Dt MEMSET 3 | .Dt MEMSET 3 | ||||
| .Os | .Os | ||||
| .Sh NAME | .Sh NAME | ||||
| .Nm memset | .Nm memset | ||||
| .Nd write a byte to byte string | .Nd write a byte to byte string | ||||
| .Sh LIBRARY | .Sh LIBRARY | ||||
| .Lb libc | .Lb libc | ||||
| .Sh SYNOPSIS | .Sh SYNOPSIS | ||||
| .In string.h | .In string.h | ||||
| .Ft void * | .Ft void * | ||||
| .Fn memset "void *dest" "int c" "size_t len" | .Fn memset "void *dest" "int c" "size_t len" | ||||
| .Ft void * | |||||
| .Fn memset_explicit "void *dest" "int c" "size_t len" | |||||
| .Fd #define __STDC_WANT_LIB_EXT1__ 1 | .Fd #define __STDC_WANT_LIB_EXT1__ 1 | ||||
| .Ft errno_t | .Ft errno_t | ||||
| .Fn memset_s "void *dest" "rsize_t destsz" "int c" "rsize_t len" | .Fn memset_s "void *dest" "rsize_t destsz" "int c" "rsize_t len" | ||||
| .Sh DESCRIPTION | .Sh DESCRIPTION | ||||
| The | The | ||||
| .Fn memset | .Fn memset | ||||
| function | function | ||||
| writes | writes | ||||
| Show All 11 Lines | |||||
| is greater than the length of the | is greater than the length of the | ||||
| .Fa dest | .Fa dest | ||||
| buffer. | buffer. | ||||
| The behaviour is also undefined if | The behaviour is also undefined if | ||||
| .Fa dest | .Fa dest | ||||
| is an invalid pointer. | is an invalid pointer. | ||||
| .Pp | .Pp | ||||
| The | The | ||||
| .Fn memset_explicit | |||||
| function behaves the same as | |||||
| .Fn memset, but will not be removed by a compiler's dead store | |||||
| optimization pass, making it useful for clearing sensitive memory | |||||
| such as a password. | |||||
| .Pp | |||||
| The | |||||
| .Fn memset_s | .Fn memset_s | ||||
| function behaves the same as | function behaves the same as | ||||
| .Fn memset | .Fn memset | ||||
| except that an error is returned and the currently registered | except that an error is returned and the currently registered | ||||
| runtime-constraint handler is called if | runtime-constraint handler is called if | ||||
| .Fa dest | .Fa dest | ||||
| is a null pointer, | is a null pointer, | ||||
| .Fa destsz | .Fa destsz | ||||
| Show All 24 Lines | |||||
| .Fn memset . | .Fn memset . | ||||
| For instance, a buffer containing a password should be cleared with | For instance, a buffer containing a password should be cleared with | ||||
| .Fn memset_s | .Fn memset_s | ||||
| before | before | ||||
| .Xr free 3 . | .Xr free 3 . | ||||
| .Sh RETURN VALUES | .Sh RETURN VALUES | ||||
| The | The | ||||
| .Fn memset | .Fn memset | ||||
| function returns its first argument. | and | ||||
| .Fn memset_explicit | |||||
| functions return their first argument. | |||||
| The | The | ||||
| .Fn memset_s | .Fn memset_s | ||||
| function returns zero on success, non-zero on error. | function returns zero on success, non-zero on error. | ||||
| .Sh SEE ALSO | .Sh SEE ALSO | ||||
| .Xr bzero 3 , | .Xr bzero 3 , | ||||
| .Xr explicit_bzero 3 , | .Xr explicit_bzero 3 , | ||||
| .Xr set_constraint_handler_s 3 , | .Xr set_constraint_handler_s 3 , | ||||
| .Xr swab 3 , | .Xr swab 3 , | ||||
| .Xr wmemset 3 | .Xr wmemset 3 | ||||
| .Sh STANDARDS | .Sh STANDARDS | ||||
| The | The | ||||
| .Fn memset | .Fn memset | ||||
| function | function | ||||
| conforms to | conforms to | ||||
| .St -isoC . | .St -isoC . | ||||
| .Fn memset_s | .Fn memset_s | ||||
| conforms to | conforms to | ||||
| .St -isoC-2011 | .St -isoC-2011 | ||||
| K.3.7.4.1. | K.3.7.4.1. | ||||
| .Fn memset_explicit | |||||
| conforms to | |||||
| .St -isoC-2024 . | |||||