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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
extern int foo (void);
int
avi_parse_comments (int fd, char *buf, int space_left)
{
int len = 0, readlen = 0, k;
char *data, *c, *d;
if (fd <= 0 || !buf || space_left <= 0)
return -1;
memset (buf, 0, space_left);
readlen = foo ();
if (!(data = malloc (readlen * sizeof (char) + 1)))
return -1;
c = data;
space_left--;
while (len < space_left)
{
if (!c || *c == '\0')
break;
else if (*c == 'I')
{
d = c + 4;
k = 0;
while (d[k] != '\r' && d[k] != '\n' && d[k] != '\0')
++k;
if (k >= space_left)
return len;
memcpy (buf + len, c, 4);
len += 4;
long2str (buf + len, k + 1);
len += 4;
memcpy (buf + len, d, k);
*(buf + len + k + 1) = '\0';
if ((k + 1) & 1)
{
k++;
*(buf + len + k + 1) = '\0';
}
len += k + 1;
while (*c != '\n' && *c != '\0')
++c;
if (*c != '\0')
++c;
else
break;
}
}
free (data);
return len;
}
|