Browse code

First draft

git-svn: trunk@772

Nigel Horne authored on 2004/08/20 20:58:20
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,76 @@
0
+/*
1
+ *  Copyright (C) 2004 Nigel Horne <njh@bandsman.co.uk>
2
+ *
3
+ *  This program is free software; you can redistribute it and/or modify
4
+ *  it under the terms of the GNU General Public License as published by
5
+ *  the Free Software Foundation; either version 2 of the License, or
6
+ *  (at your option) any later version.
7
+ *
8
+ *  This program is distributed in the hope that it will be useful,
9
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
+ *  GNU General Public License for more details.
12
+ *
13
+ *  You should have received a copy of the GNU General Public License
14
+ *  along with this program; if not, write to the Free Software
15
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ *
17
+ * $Log: line.c,v $
18
+ * Revision 1.1  2004/08/20 11:58:20  nigelhorne
19
+ * First draft
20
+ *
21
+ */
22
+
23
+static	char	const	rcsid[] = "$Id: line.c,v 1.1 2004/08/20 11:58:20 nigelhorne Exp $";
24
+
25
+#if HAVE_CONFIG_H
26
+#include "clamav-config.h"
27
+#endif
28
+
29
+#include <stdio.h>
30
+#include <string.h>
31
+
32
+#include "line.h"
33
+#include "others.h"
34
+
35
+line_t *
36
+lineCreate(const char *data)
37
+{
38
+	line_t *ret = cli_malloc(sizeof(struct line));
39
+
40
+	if(ret == NULL)
41
+		return NULL;
42
+
43
+	ret->l_data = strdup(data);
44
+	if(ret->l_data == NULL) {
45
+		free(ret);
46
+		return NULL;
47
+	}
48
+	ret->l_refs = 1;
49
+
50
+	return ret;
51
+}
52
+
53
+line_t *
54
+lineLink(line_t *line)
55
+{
56
+	line->l_refs++;
57
+	return line;
58
+}
59
+
60
+line_t *
61
+lineUnlink(line_t *line)
62
+{
63
+	if(--line->l_refs == 0) {
64
+		free(line->l_data);
65
+		free(line);
66
+		return NULL;
67
+	}
68
+	return line;
69
+}
70
+
71
+const char *
72
+lineGetData(const line_t *line)
73
+{
74
+	return line ? line->l_data : NULL;
75
+}
0 76
new file mode 100644
... ...
@@ -0,0 +1,32 @@
0
+/*
1
+ *  Copyright (C) 2004 Nigel Horne <njh@bandsman.co.uk>
2
+ *
3
+ *  This program is free software; you can redistribute it and/or modify
4
+ *  it under the terms of the GNU General Public License as published by
5
+ *  the Free Software Foundation; either version 2 of the License, or
6
+ *  (at your option) any later version.
7
+ *
8
+ *  This program is distributed in the hope that it will be useful,
9
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
+ *  GNU General Public License for more details.
12
+ *
13
+ *  You should have received a copy of the GNU General Public License
14
+ *  along with this program; if not, write to the Free Software
15
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ *
17
+ * $Log: line.h,v $
18
+ * Revision 1.1  2004/08/20 11:58:20  nigelhorne
19
+ * First draft
20
+ *
21
+ */
22
+
23
+typedef struct line {
24
+	char	*l_data;	/* the line's contents */
25
+	unsigned int	l_refs;	/* the number of references to the data */
26
+} line_t;
27
+
28
+line_t	*lineCreate(const char *data);
29
+line_t	*lineLink(line_t *line);
30
+line_t	*lineUnlink(line_t *line);
31
+const	char	*lineGetData(const line_t *line);