Print this page
Rich's feedback
   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 /*
  13  * Copyright 2017 Jason King
  14  */
  15 #include <sys/debug.h>
  16 #include <sys/sysmacros.h>
  17 #include <string.h>
  18 #include "str.h"
  19 #include "sysdemangle_int.h"
  20 
  21 #define STR_CHUNK_SZ    (64U)
  22 
  23 /* are we storing a reference vs. a dynamically allocated copy? */
  24 #define IS_REF(s) ((s)->str_s != NULL && (s)->str_size == 0)
  25 
  26 /*
  27  * Dynamically resizeable strings, with lazy allocation when initialized
  28  * with a constant string value
  29  *
  30  * NOTE: these are not necessairly 0-terminated
  31  *
  32  * Additionally, these can store references instead of copies of strings
  33  * (as indicated by the IS_REF() macro.  However mutation may cause a
  34  * string to convert from a refence to a dynamically allocated copy.
  35  */
  36 
  37 void
  38 str_init(str_t *restrict s, sysdem_ops_t *restrict ops)
  39 {


   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 /*
  13  * Copyright 2017 Jason King
  14  */
  15 #include <sys/debug.h>
  16 #include <sys/sysmacros.h>
  17 #include <string.h>
  18 #include "str.h"
  19 #include "demangle_int.h"
  20 
  21 #define STR_CHUNK_SZ    (64U)
  22 
  23 /* are we storing a reference vs. a dynamically allocated copy? */
  24 #define IS_REF(s) ((s)->str_s != NULL && (s)->str_size == 0)
  25 
  26 /*
  27  * Dynamically resizeable strings, with lazy allocation when initialized
  28  * with a constant string value
  29  *
  30  * NOTE: these are not necessairly 0-terminated
  31  *
  32  * Additionally, these can store references instead of copies of strings
  33  * (as indicated by the IS_REF() macro.  However mutation may cause a
  34  * string to convert from a refence to a dynamically allocated copy.
  35  */
  36 
  37 void
  38 str_init(str_t *restrict s, sysdem_ops_t *restrict ops)
  39 {