Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. /* dynstr_nls.c */
  2. /*****************************************************************************/
  3. /* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
  4. /*                                                                           */
  5. /* AS-Port                                                                   */
  6. /*                                                                           */
  7. /* Handling of strings with dynamic allocation - NLS extensions              */
  8. /*                                                                           */
  9. /*****************************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. #include "dynstr.h"
  15. #include "nls.h"
  16. #include "dynstr_nls.h"
  17.  
  18. /*!------------------------------------------------------------------------
  19.  * \fn     as_dynstr_append_upr(as_dynstr_t *p_dest, const char *p_src, size_t src_len)
  20.  * \brief  extend string and convert to upper case
  21.  * \param  p_dest string to extend
  22.  * \param  p_src what to append
  23.  * \param  src_len how much to append
  24.  * \return actual # of bytes transferred
  25.  * ------------------------------------------------------------------------ */
  26.  
  27. size_t as_dynstr_append_upr(as_dynstr_t *p_dest, const char *p_src, size_t src_len)
  28. {
  29.   size_t dest_len = strlen(p_dest->p_str), dest_cap;
  30.  
  31.   if ((dest_len + src_len + 1 > p_dest->capacity) && p_dest->dynamic)
  32.     as_dynstr_realloc(p_dest, as_dynstr_roundup_len(dest_len + src_len));
  33.   dest_cap = p_dest->capacity - dest_len;
  34.   if (src_len >= dest_cap)
  35.     src_len = dest_cap - 1;
  36.   NLS_UpString2(p_dest->p_str + dest_len, dest_cap, p_src, src_len);
  37.   return src_len;
  38. }
  39.  
  40. /*!------------------------------------------------------------------------
  41.  * \fn     as_dynstr_append_c_str_upr(as_dynstr_t *p_dest, const char *p_src)
  42.  * \brief  extend string and convert to upper case
  43.  * \param  p_dest string to extend
  44.  * \param  p_src what to append
  45.  * \return actual # of bytes transferred
  46.  * ------------------------------------------------------------------------ */
  47.  
  48. size_t as_dynstr_append_c_str_upr(as_dynstr_t *p_dest, const char *p_src)
  49. {
  50.   return as_dynstr_append_upr(p_dest, p_src, strlen(p_src));
  51. }
  52.