-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.c
More file actions
53 lines (37 loc) · 791 Bytes
/
Copy pathbuffer.c
File metadata and controls
53 lines (37 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "buffer.h"
#include <stdlib.h>
#include <string.h>
void InitBuffer (struct buffer *);
void ExtendBuffer (struct buffer *);
void FreeBuffer (struct buffer *);
/* Initialization buffer.
* Create string for write
* and init cnts of parts(1) and symbols(0)
*/
void InitBuffer (struct buffer * buf)
{
buf->str = (char *) malloc (BUF_SIZE);
buf->part = 1;
buf->cnt = 0;
}
/* Extend buffer (linear).
* Inc part of buf,
* create new string greater than was,
* copy old to new
* delete old
*/
void ExtendBuffer (struct buffer *buf)
{
char * tmp_str;
tmp_str = malloc ((++buf->part) * BUF_SIZE);
strcpy (tmp_str, buf->str);
free (buf->str);
buf->str = tmp_str;
}
/* Free buffer
*/
void FreeBuffer (struct buffer * buf)
{
free (buf->str);
free (buf);
}