RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-datawalls-data-hanging-as-warning
Last change
on this file since 53496ab3 was
30d80d2,
checked in by Olly Betts <olly@…>, 11 years ago
|
src/str.c,src/str.h: Inline s_zero() and s_free() since they should
optimise down to similar or less code than a function call would.
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[9286525] | 1 | /* append a string */ |
---|
[846746e] | 2 | /* Copyright (c) Olly Betts 1999 |
---|
| 3 | * |
---|
[89231c4] | 4 | * This program is free software; you can redistribute it and/or modify |
---|
| 5 | * it under the terms of the GNU General Public License as published by |
---|
| 6 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | * (at your option) any later version. |
---|
[846746e] | 8 | * |
---|
| 9 | * This program is distributed in the hope that it will be useful, |
---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
[89231c4] | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | * GNU General Public License for more details. |
---|
[846746e] | 13 | * |
---|
[89231c4] | 14 | * You should have received a copy of the GNU General Public License |
---|
| 15 | * along with this program; if not, write to the Free Software |
---|
[ecbc6c18] | 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
[846746e] | 17 | */ |
---|
| 18 | |
---|
[99d5754] | 19 | #include <string.h> |
---|
| 20 | |
---|
| 21 | #include "osalloc.h" |
---|
[b6ea3c2] | 22 | #include "str.h" |
---|
[99d5754] | 23 | |
---|
| 24 | /* append a string */ |
---|
| 25 | void |
---|
| 26 | s_cat(char **pstr, int *plen, char *s) |
---|
| 27 | { |
---|
| 28 | int new_len = strlen(s) + 1; /* extra 1 for nul */ |
---|
| 29 | int len = 0; |
---|
| 30 | |
---|
| 31 | if (*pstr) { |
---|
| 32 | len = strlen(*pstr); |
---|
| 33 | new_len += len; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | if (!*pstr || new_len > *plen) { |
---|
| 37 | *plen = (new_len + 32) & ~3; |
---|
| 38 | *pstr = osrealloc(*pstr, *plen); |
---|
| 39 | } |
---|
[cb3d1e2] | 40 | |
---|
[99d5754] | 41 | strcpy(*pstr + len, s); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | /* append a character */ |
---|
| 45 | void |
---|
| 46 | s_catchar(char **pstr, int *plen, char ch) |
---|
| 47 | { |
---|
| 48 | int new_len = 2; /* extra 1 for nul */ |
---|
| 49 | int len = 0; |
---|
| 50 | |
---|
| 51 | if (*pstr) { |
---|
| 52 | len = strlen(*pstr); |
---|
| 53 | new_len += len; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | if (!*pstr || new_len > *plen) { |
---|
| 57 | *plen = (new_len + 32) & ~3; |
---|
| 58 | *pstr = osrealloc(*pstr, *plen); |
---|
| 59 | } |
---|
[cb3d1e2] | 60 | |
---|
[99d5754] | 61 | (*pstr)[len] = ch; |
---|
| 62 | (*pstr)[len + 1] = '\0'; |
---|
| 63 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.