memcpy (iov[2 + elem + offset].iov_base, ctype->codeset_name, total);
memset (mempcpy (iov[2 + elem + offset].iov_base, ctype->codeset_name, total), '\0', 4 - (total & 3));
ctype_output (struct localedef_t *locale, struct charset_t *charset,	      const char *output_path){  struct locale_ctype_t *ctype = locale->categories[LC_CTYPE].ctype;  const size_t nelems = (_NL_ITEM_INDEX (_NL_NUM_LC_CTYPE)			 + 2 * (ctype->map_collection_nr - 2));  struct iovec iov[2 + nelems + ctype->nr_charclass		  + ctype->map_collection_nr];  struct locale_file data;  u_int32_t idx[nelems];  size_t elem, cnt, offset, total;  if ((locale->binary & (1 << LC_CTYPE)) != 0)    {      iov[0].iov_base = ctype;      iov[0].iov_len = locale->len[LC_CTYPE];      write_locale_data (output_path, "LC_CTYPE", 1, iov);      return;    }  /* Now prepare the output: Find the sizes of the table we can use.  */  allocate_arrays (ctype, charset);  data.magic = LIMAGIC (LC_CTYPE);  data.n = nelems;  iov[0].iov_base = (void *) &data;  iov[0].iov_len = sizeof (data);  iov[1].iov_base = (void *) idx;  iov[1].iov_len = sizeof (idx);  idx[0] = iov[0].iov_len + iov[1].iov_len;  offset = 0;  for (elem = 0; elem < nelems; ++elem)    {      if (elem < _NL_ITEM_INDEX (_NL_NUM_LC_CTYPE))	switch (elem)	  {#define CTYPE_DATA(name, base, len)					      \	  case _NL_ITEM_INDEX (name):					      \	    iov[2 + elem + offset].iov_base = (base);			      \	    iov[2 + elem + offset].iov_len = (len);			      \	    if (elem + 1 < nelems)					      \	      idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len;     \	    break	  CTYPE_DATA (_NL_CTYPE_CLASS,		      ctype->ctype_b,		      (256 + 128) * sizeof (char_class_t));	  CTYPE_DATA (_NL_CTYPE_TOUPPER_EB,		      ctype->map_eb[0],		      (ctype->plane_size * ctype->plane_cnt + 128)		      * sizeof (u_int32_t));	  CTYPE_DATA (_NL_CTYPE_TOLOWER_EB,		      ctype->map_eb[1],		      (ctype->plane_size * ctype->plane_cnt + 128)		      * sizeof (u_int32_t));	  CTYPE_DATA (_NL_CTYPE_TOUPPER_EL,		      ctype->map_el[0],		      (ctype->plane_size * ctype->plane_cnt + 128)		      * sizeof (u_int32_t));	  CTYPE_DATA (_NL_CTYPE_TOLOWER_EL,		      ctype->map_el[1],		      (ctype->plane_size * ctype->plane_cnt + 128)		      * sizeof (u_int32_t));	  CTYPE_DATA (_NL_CTYPE_CLASS32,		      ctype->ctype32_b,		      (ctype->plane_size * ctype->plane_cnt		       * sizeof (char_class32_t)));	  CTYPE_DATA (_NL_CTYPE_NAMES_EB,		      ctype->names_eb, (ctype->plane_size * ctype->plane_cnt					* sizeof (u_int32_t)));	  CTYPE_DATA (_NL_CTYPE_NAMES_EL,		      ctype->names_el, (ctype->plane_size * ctype->plane_cnt					* sizeof (u_int32_t)));	  CTYPE_DATA (_NL_CTYPE_HASH_SIZE,		      &ctype->plane_size, sizeof (u_int32_t));	  CTYPE_DATA (_NL_CTYPE_HASH_LAYERS,		      &ctype->plane_cnt, sizeof (u_int32_t));	  case _NL_ITEM_INDEX (_NL_CTYPE_CLASS_NAMES):	    /* The class name array.  */	    total = 0;	    for (cnt = 0; cnt < ctype->nr_charclass; ++cnt, ++offset)	      {		iov[2 + elem + offset].iov_base		  = (void *) ctype->classnames[cnt];		iov[2 + elem + offset].iov_len		  = strlen (ctype->classnames[cnt]) + 1;		total += iov[2 + elem + offset].iov_len;	      }	    iov[2 + elem + offset].iov_base = (void *) "\0\0\0";	    iov[2 + elem + offset].iov_len = 1 + (4 - ((total + 1) % 4));	    total += 1 + (4 - ((total + 1) % 4));	    if (elem + 1 < nelems)	      idx[elem + 1] = idx[elem] + total;	    break;	  case _NL_ITEM_INDEX (_NL_CTYPE_MAP_NAMES):	    /* The class name array.  */	    total = 0;	    for (cnt = 0; cnt < ctype->map_collection_nr; ++cnt, ++offset)	      {		iov[2 + elem + offset].iov_base		  = (void *) ctype->mapnames[cnt];		iov[2 + elem + offset].iov_len		  = strlen (ctype->mapnames[cnt]) + 1;		total += iov[2 + elem + offset].iov_len;	      }	    iov[2 + elem + offset].iov_base = (void *) "\0\0\0";	    iov[2 + elem + offset].iov_len = 1 + (4 - ((total + 1) % 4));	    total += 1 + (4 - ((total + 1) % 4));	    if (elem + 1 < nelems)	      idx[elem + 1] = idx[elem] + total;	    break;	  CTYPE_DATA (_NL_CTYPE_WIDTH,		      ctype->width, ctype->plane_size * ctype->plane_cnt);	  CTYPE_DATA (_NL_CTYPE_MB_CUR_MAX,		      &ctype->mb_cur_max, sizeof (u_int32_t));	  case _NL_ITEM_INDEX (_NL_CTYPE_CODESET_NAME):	    total = strlen (ctype->codeset_name) + 1;	    if (total % 4 == 0)	      iov[2 + elem + offset].iov_base = (char *) ctype->codeset_name;	    else	      {		iov[2 + elem + offset].iov_base = alloca ((total + 3) & ~3);		memcpy (iov[2 + elem + offset].iov_base, ctype->codeset_name,			total);		total = (total + 3) & ~3;	      }	    iov[2 + elem + offset].iov_len = total;	    if (elem + 1 < nelems)	      idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len;	    break;	  default:	    assert (! "unknown CTYPE element");	  }      else	{	  /* Handle extra maps.  */	  size_t nr = (elem - _NL_ITEM_INDEX (_NL_NUM_LC_CTYPE)) >> 1;	  if (((elem - _NL_ITEM_INDEX (_NL_NUM_LC_CTYPE)) & 1) == 0)	    iov[2 + elem + offset].iov_base = ctype->map_eb[nr];	  else	    iov[2 + elem + offset].iov_base = ctype->map_el[nr];	  iov[2 + elem + offset].iov_len = ((ctype->plane_size					     * ctype->plane_cnt + 128)					    * sizeof (u_int32_t));	  if (elem + 1 < nelems)	    idx[elem + 1] = idx[elem] + iov[2 + elem + offset].iov_len;	}    }  assert (2 + elem + offset == (nelems + ctype->nr_charclass				+ ctype->map_collection_nr + 2));  write_locale_data (output_path, "LC_CTYPE", 2 + elem + offset, iov);}