예제 #1
0
/**
 * @internal
 * @brief Create a new string buffer.
 *
 * @param csize the character size
 * @return Newly allocated string buffer instance.
 *
 * This function creates a new string buffer. On error, @c NULL is
 * returned. To free the resources, use eina_strbuf_common_free().
 *
 * @see eina_strbuf_common_free()
 * @see eina_strbuf_common_append()
 * @see eina_strbuf_common_string_get()
 */
Eina_Strbuf *
eina_strbuf_common_new(size_t csize)
{
   Eina_Strbuf *buf;

   buf = calloc(1, sizeof(Eina_Strbuf));
   if (EINA_UNLIKELY(!buf)) return NULL;
   if (EINA_UNLIKELY(!_eina_strbuf_common_init(csize, buf)))
     {
        eina_strbuf_common_free(buf);
        return NULL;
     }
   return buf;
}
예제 #2
0
/**
 * @internal
 * @brief Create a new string buffer managing str.
 *
 * @param csize the character size
 * @param str the string to manage
 * @param len the length of the string to manage
 * @return Newly allocated string buffer instance.
 *
 * This function creates a new string buffer. On error, @c NULL is
 * returned. To free the resources, use eina_strbuf_common_free().
 *
 * @see eina_strbuf_common_free()
 * @see eina_strbuf_common_append()
 * @see eina_strbuf_common_string_get()
 * @since 1.1.0
 */
Eina_Strbuf *
eina_strbuf_common_manage_new(size_t csize,
                               void *str,
                               size_t len)
{
   Eina_Strbuf *buf;

   buf = calloc(1, sizeof(Eina_Strbuf));
   if (EINA_UNLIKELY(!buf)) return NULL;
   if (EINA_UNLIKELY(!_eina_strbuf_common_manage_init(csize, buf, str, len)))
     {
        eina_strbuf_common_free(buf);
        return NULL;
     }
   return buf;
}
예제 #3
0
/**
 * @brief Create a new string buffer.
 *
 * @return Newly allocated string buffer instance.
 *
 * This function creates a new string buffer. On error, @c NULL is
 * returned and Eina error is set to #EINA_ERROR_OUT_OF_MEMORY. To
 * free the resources, use eina_strbuf_common_free().
 *
 * @see eina_strbuf_common_free()
 * @see eina_strbuf_common_append()
 * @see eina_strbuf_common_string_get()
 */
Eina_Strbuf *eina_strbuf_common_new(size_t csize)
{
	Eina_Strbuf *buf;

	eina_error_set(0);
	buf = malloc(sizeof(Eina_Strbuf));
	if (EINA_UNLIKELY(!buf)) {
		eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
		return NULL;
	}

	if (EINA_UNLIKELY(!_eina_strbuf_common_init(csize, buf))) {
		eina_strbuf_common_free(buf);
		return NULL;
	}

	return buf;
}
예제 #4
0
/**
 * @internal
 * @brief Create a new string buffer managing read only str.
 *
 * @param csize the character size
 * @param str the read only string to manage
 * @param len the length of the string to manage
 * @return Newly allocated string buffer instance.
 *
 * This function creates a new string buffer. On error, @c NULL is
 * returned. To free the resources, use eina_strbuf_common_free().
 *
 * @see eina_strbuf_common_free()
 * @see eina_strbuf_common_append()
 * @see eina_strbuf_common_string_get()
 * @since 1.1.0
 */
Eina_Strbuf *
eina_strbuf_common_manage_ro_new(size_t csize,
                                 const void *str,
                                 size_t len)
{
   Eina_Strbuf *buf;

   buf = calloc(1, sizeof(Eina_Strbuf));
   if (EINA_UNLIKELY(!buf)) return NULL;
   if (EINA_UNLIKELY(!_eina_strbuf_common_manage_init(csize, buf,
                                                      (void*) str, len)))
     {
        eina_strbuf_common_free(buf);
        return NULL;
     }
   buf->ro = EINA_TRUE;
   return buf;
}