1 .\"
   2 .\" This file and its contents are supplied under the terms of the
   3 .\" Common Development and Distribution License ("CDDL"), version 1.0.
   4 .\" You may only use this file in accordance with the terms of version
   5 .\" 1.0 of the CDDL.
   6 .\"
   7 .\" A full copy of the text of the CDDL should have accompanied this
   8 .\" source.  A copy of the CDDL is also available via the Internet at
   9 .\" http://www.illumos.org/license/CDDL.
  10 .\"
  11 .\"
  12 .\" Copyright 2018 Nexenta Systems, Inc.
  13 .\"
  14 .Dd August 12, 2017
  15 .Dt MEMSET_S 3C
  16 .Os
  17 .Sh NAME
  18 .Nm memset_s
  19 .Nd copy a value to all bytes of a memory buffer
  20 .Sh LIBRARY
  21 .Lb libc
  22 .Sh SYNOPSIS
  23 .Fd #define __STDC_WANT_LIB_EXT1__ 1
  24 .In string.h
  25 .Ft errno_t
  26 .Fo memset_s
  27 .Fa "void *s"
  28 .Fa "rsize_t smax"
  29 .Fa "int c"
  30 .Fa "rsize_t n"
  31 .Fc
  32 .Sh DESCRIPTION
  33 The
  34 .Fn memset_s
  35 function copies the value of
  36 .Fa c
  37 .Po converted to an
  38 .Vt unsigned char
  39 .Pc
  40 into each of the first
  41 .Fa n
  42 bytes of the memory buffer pointed to by
  43 .Fa s .
  44 .Pp
  45 Unlike the
  46 .Xr memset 3C ,
  47 .Fn memset_s
  48 is guaranteed to never be optimized away by the compiler.
  49 .Pp
  50 The
  51 .Fn memset_s
  52 function detects the following runtime-constraint violations:
  53 .Bl -enum
  54 .It
  55 .Fa s
  56 is a
  57 .Dv NULL
  58 pointer.
  59 .It
  60 .Fa smax
  61 or
  62 .Fa n
  63 is greater than
  64 .Dv RSIZE_MAX .
  65 .It
  66 .Fa n
  67 is greater than
  68 .Fa smax
  69 .Pq buffer overflow .
  70 .El
  71 .Pp
  72 If runtime-constraint violation is detected, and if
  73 .Fa s
  74 and
  75 .Fa smax
  76 are valid, the
  77 .Fn memset_s
  78 function copies the value of
  79 .Fa c
  80 .Po converted to an
  81 .Vt unsigned char
  82 .Pc
  83 into each of the first
  84 .Fa smax
  85 bytes of the memory buffer pointed to by
  86 .Fa s
  87 before calling the runtime-constraint handler.
  88 .Sh RETURN VALUES
  89 The
  90 .Fn memset_s
  91 function returns 0 if there was no runtime-constraint violation.
  92 Otherwise, a non-zero value is returned.
  93 .Sh INTERFACE STABILITY
  94 .Sy Standard
  95 .Sh MT-LEVEL
  96 .Sy Safe
  97 .Sh SEE ALSO
  98 .Xr memset 3C ,
  99 .Xr set_constraint_handler_s 3C
 100 .Sh STANDARDS
 101 The
 102 .Fn memset_s
 103 function conforms to
 104 .St -isoC-2011 .