diff options
author | law <law@138bc75d-0d04-0410-961f-82ee72b054a4> | 1999-09-07 05:49:18 +0000 |
---|---|---|
committer | law <law@138bc75d-0d04-0410-961f-82ee72b054a4> | 1999-09-07 05:49:18 +0000 |
commit | 7014838cdd847f5d22f8b4bff0285ad622b707b5 (patch) | |
tree | f1a67b6ea75a7f0da3f06e0a1c60b213f4403168 /gcc/dyn-string.c | |
parent | 713829e97b2cabe9369424002f6efb23a7c86aba (diff) | |
download | gcc-7014838cdd847f5d22f8b4bff0285ad622b707b5.tar.gz |
Merge in gcc2-ss-010999
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@29150 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/dyn-string.c')
-rw-r--r-- | gcc/dyn-string.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/gcc/dyn-string.c b/gcc/dyn-string.c index c9edfcb076e..704629d253b 100644 --- a/gcc/dyn-string.c +++ b/gcc/dyn-string.c @@ -4,28 +4,29 @@ This file is part of GNU CC. -GNU CC is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. -GNU CC is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + #include "config.h" #include "system.h" #include "dyn-string.h" -/* Create a new dynamic string capable of holding at least SPACE - characters, including the terminating NUL. If SPACE is 0, it - will be silently increased to 1. */ +/* Create a new dynamic string capable of holding at least SPACE characters, + including the terminating NUL. If SPACE is 0, it will be silently + increased to 1. */ dyn_string_t dyn_string_new (space) @@ -33,13 +34,12 @@ dyn_string_new (space) { dyn_string_t result = (dyn_string_t) xmalloc (sizeof (struct dyn_string)); + /* We need at least one byte in which to store the terminating NUL. */ if (space == 0) - /* We need at least one byte in which to store the terminating - NUL. */ space = 1; result->allocated = space; - result->s = (char*) xmalloc (space); + result->s = (char *) xmalloc (space); result->length = 0; result->s[0] = '\0'; @@ -56,8 +56,7 @@ dyn_string_delete (ds) free (ds); } -/* Append the NUL-terminated string S to DS, resizing DS if - necessary. */ +/* Append the NUL-terminated string S to DS, resizing DS if necessary. */ dyn_string_t dyn_string_append (ds, s) @@ -65,16 +64,19 @@ dyn_string_append (ds, s) const char *s; { int len = strlen (s); - dyn_string_resize (ds, ds->length + len + 1 /* '\0' */); + + /* The new length is the old length plus the size of our string, plus + one for the null at the end. */ + dyn_string_resize (ds, ds->length + len + 1); strcpy (ds->s + ds->length, s); ds->length += len; return ds; } -/* Increase the capacity of DS so that it can hold at least SPACE - characters, including the terminating NUL. This function will not - (at present) reduce the capacity of DS. */ +/* Increase the capacity of DS so it can hold at least SPACE characters, + including the terminating NUL. This function will not (at present) + reduce the capacity of DS. */ dyn_string_t dyn_string_resize (ds, space) @@ -90,7 +92,7 @@ dyn_string_resize (ds, space) { /* We actually need more space. */ ds->allocated = new_allocated; - ds->s = (char*) xrealloc (ds->s, ds->allocated); + ds->s = (char *) xrealloc (ds->s, ds->allocated); } return ds; |