Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
strcatalloc.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file strcatalloc.c
5 
6  \version V1.3
7  \date 26.06.15
8 
9  \copyright (c) Dr. Andrew C. R. Martin, University of Reading, 2002-14
10  \author Dr. Andrew C. R. Martin
11  \par
12  Institute of Structural & Molecular Biology,
13  University College London,
14  Gower Street,
15  London.
16  WC1E 6BT.
17  \par
18  andrew@bioinf.org.uk
19  andrew.martin@ucl.ac.uk
20 
21 **************************************************************************
22 
23  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
24  according to the conditions laid out in the accompanying file
25  COPYING.DOC.
26 
27  The code may be modified as required, but any modifications must be
28  documented so that the person responsible can be identified.
29 
30  The code may not be sold commercially or included as part of a
31  commercial product except as described in the file COPYING.DOC.
32 
33 **************************************************************************
34 
35  Description:
36  ============
37 
38 
39 **************************************************************************
40 
41  Usage:
42  ======
43 
44 **************************************************************************
45 
46  Revision History:
47  =================
48 - V1.0 22.05.99 Original By: ACRM
49 - V1.1 11.07.00 Check that realloc succeeded
50 - V1.2 07.07.14 Use bl prefix for functions By: CTP
51 - V1.3 26.06.15 Corrected checks on input strings being NULL By: ACRM
52 
53 *************************************************************************/
54 /* Doxygen
55  -------
56  #GROUP General Programming
57  #SUBGROUP String handling
58 
59  #FUNCTION blStrcatalloc()
60  Like strcat() but uses a realloc() on instr to make space available.
61 */
62 /************************************************************************/
63 /* Includes
64 */
65 #include <stdlib.h>
66 #include <string.h>
67 
68 /************************************************************************/
69 /* Defines and macros
70 */
71 
72 /************************************************************************/
73 /* Globals
74 */
75 
76 /************************************************************************/
77 /* Prototypes
78 */
79 
80 
81 /************************************************************************/
82 /*>char *blStrcatalloc(char *instr, char *catstr)
83  ----------------------------------------------
84 *//**
85 
86  \param[in] *instr String to append to
87  \param[in] *catstr String to append
88  \return realloc'd version of instr with catstr
89  appended
90 
91  Like strcat() but uses a realloc() on instr to make space available.
92 
93 - 22.05.99 Original By: ACRM
94 - 16.06.99 Initialise outstr to NULL
95 - 25.08.99 Fixed bug where testing for NULL outstr instead of catstr
96 - 11.07.00 Check that realloc succeeded
97 - 07.07.14 Use bl prefix for functions By: CTP
98 - 26.06.15 Corrected checks on instr and catstr being null By: ACRM
99 */
100 char *blStrcatalloc(char *instr, char *catstr)
101 {
102  int totLen;
103  char *outstr = NULL;
104 
105  totLen = ((instr==NULL) ? 0 : strlen(instr)) +
106  ((catstr==NULL) ? 0 : strlen(catstr));
107  if((outstr = realloc(instr, totLen+1))!=NULL)
108  {
109  /* If the input string was NULL, outstr will have been allocated
110  using the equivalent of malloc() so must be initialized before
111  concatenating
112  */
113  if(instr==NULL)
114  outstr[0] = '\0';
115  /* If the additional string was non-NULL then add it on */
116  if(catstr!=NULL)
117  strcat(outstr, catstr);
118  }
119 
120  return(outstr);
121 }
#define NULL
Definition: array2.c:99
char * blStrcatalloc(char *instr, char *catstr)
Definition: strcatalloc.c:100