diff options
Diffstat (limited to 'src/buf.c')
-rw-r--r-- | src/buf.c | 52 |
1 files changed, 21 insertions, 31 deletions
@@ -73,12 +73,13 @@ struct Buf *buf_prints (struct Buf *buf, const char *fmt, const char *s) char *t; size_t tsz; - t = flex_alloc (tsz = strlen (fmt) + strlen (s) + 1); + tsz = strlen(fmt) + strlen(s) + 1; + t = malloc(tsz); if (!t) flexfatal (_("Allocation of buffer to print string failed")); snprintf (t, tsz, fmt, s); buf = buf_strappend (buf, t); - flex_free (t); + free(t); return buf; } @@ -104,14 +105,14 @@ struct Buf *buf_linedir (struct Buf *buf, const char* filename, int lineno) t = malloc(tsz); if (!t) flexfatal (_("Allocation of buffer for line directive failed")); - for (dst = t + sprintf (t, "#line %d \"", lineno), src = filename; *src; *dst++ = *src++) + for (dst = t + snprintf (t, tsz, "#line %d \"", lineno), src = filename; *src; *dst++ = *src++) if (*src == '\\') /* escape backslashes */ *dst++ = '\\'; *dst++ = '"'; *dst++ = '\n'; *dst = '\0'; buf = buf_strappend (buf, t); - flex_free (t); + free(t); return buf; } @@ -129,10 +130,7 @@ struct Buf *buf_concat(struct Buf* dest, const struct Buf* src) /* Appends n characters in str to buf. */ -struct Buf *buf_strnappend (buf, str, n) - struct Buf *buf; - const char *str; - int n; +struct Buf *buf_strnappend (struct Buf *buf, const char *str, int n) { buf_append (buf, str, n + 1); @@ -143,18 +141,13 @@ struct Buf *buf_strnappend (buf, str, n) } /* Appends characters in str to buf. */ -struct Buf *buf_strappend (buf, str) - struct Buf *buf; - const char *str; +struct Buf *buf_strappend (struct Buf *buf, const char *str) { - return buf_strnappend (buf, str, strlen (str)); + return buf_strnappend (buf, str, (int) strlen (str)); } /* appends "#define str def\n" */ -struct Buf *buf_strdefine (buf, str, def) - struct Buf *buf; - const char *str; - const char *def; +struct Buf *buf_strdefine (struct Buf *buf, const char *str, const char *def) { buf_strappend (buf, "#define "); buf_strappend (buf, " "); @@ -178,7 +171,8 @@ struct Buf *buf_m4_define (struct Buf *buf, const char* def, const char* val) size_t strsz; val = val?val:""; - str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + strlen(val) + 2); + strsz = strlen(fmt) + strlen(def) + strlen(val) + 2; + str = malloc(strsz); if (!str) flexfatal (_("Allocation of buffer for m4 def failed")); @@ -198,7 +192,8 @@ struct Buf *buf_m4_undefine (struct Buf *buf, const char* def) char * str; size_t strsz; - str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + 2); + strsz = strlen(fmt) + strlen(def) + 2; + str = malloc(strsz); if (!str) flexfatal (_("Allocation of buffer for m4 undef failed")); @@ -208,23 +203,21 @@ struct Buf *buf_m4_undefine (struct Buf *buf, const char* def) } /* create buf with 0 elements, each of size elem_size. */ -void buf_init (buf, elem_size) - struct Buf *buf; - size_t elem_size; +void buf_init (struct Buf *buf, size_t elem_size) { - buf->elts = (void *) 0; + buf->elts = NULL; buf->nelts = 0; buf->elt_size = elem_size; buf->nmax = 0; } /* frees memory */ -void buf_destroy (buf) - struct Buf *buf; +void buf_destroy (struct Buf *buf) { - if (buf && buf->elts) - flex_free (buf->elts); - buf->elts = (void *) 0; + if (buf) { + free(buf->elts); + buf->elts = NULL; + } } @@ -234,10 +227,7 @@ void buf_destroy (buf) * We grow by mod(512) boundaries. */ -struct Buf *buf_append (buf, ptr, n_elem) - struct Buf *buf; - const void *ptr; - int n_elem; +struct Buf *buf_append (struct Buf *buf, const void *ptr, int n_elem) { int n_alloc = 0; |