aboutsummaryrefslogtreecommitdiff
path: root/src/lib/FL/common.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/FL/common.cxx')
-rw-r--r--src/lib/FL/common.cxx60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/lib/FL/common.cxx b/src/lib/FL/common.cxx
new file mode 100644
index 0000000..852b0e7
--- /dev/null
+++ b/src/lib/FL/common.cxx
@@ -0,0 +1,60 @@
1// COPY A STRING WITH 'new'
2// Value can be NULL
3//
4static char *strnew(const char *val)
5{
6 if ( val == NULL )
7 return(NULL);
8
9 char *s = new char[strlen(val)+1];
10 strcpy(s, val);
11
12 return(s);
13}
14
15// FREE STRING CREATED WITH strnew(), NULLS OUT STRING
16// Value can be NULL
17//
18static char *strfree(char *val)
19{
20 if ( val )
21 delete [] val;
22
23 return(NULL);
24}
25
26// 'DYNAMICALLY' APPEND ONE STRING TO ANOTHER
27// Returns newly allocated string, or NULL
28// if s && val == NULL.
29// 's' can be NULL; returns a strnew(val).
30// 'val' can be NULL; s is returned unmodified.
31//
32// Usage:
33// char *s = strnew("foo"); // s = "foo"
34// s = strapp(s, "bar"); // s = "foobar"
35//
36#ifndef WINDOWS
37static char *strapp(char *s, const char *val)
38{
39 if ( ! val )
40 return(s); // Nothing to append? return s
41
42 if ( ! s )
43 return(strnew(val)); // New string? return copy of val
44
45 char *news = new char[strlen(s)+strlen(val)+1];
46 strcpy(news, s);
47 strcat(news, val);
48
49 delete [] s; // delete old string
50 return(news); // return new copy
51}
52#endif
53// APPEND A CHARACTER TO A STRING
54static void chrcat(char *s, char c)
55{
56 char tmp[2] = { c, '\0' };;
57 strcat(s, tmp);
58}
59
60