-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_stream.c
63 lines (49 loc) · 1.16 KB
/
test_stream.c
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
/*
$Id$
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "nstream.h"
#include "nstore.h"
#include "nassert.h"
#include "nmalloc.h"
void test_write(const char *name, const char *mode)
{
tn_stream *st;
if (mode == NULL) mode = "w";
st = n_stream_open(name, mode, TN_STREAM_UNKNOWN);
n_stream_printf(st, "dupa blada\n i co z tego\n");
n_stream_seek(st, 0, SEEK_SET);
n_stream_printf(st, "ALA");
n_stream_close(st);
}
void test_read(const char *name)
{
tn_stream *st;
char buf[1024] = { '\0' };
st = n_stream_open(name, "r", TN_STREAM_UNKNOWN);
n_stream_read(st, buf, sizeof(buf));
printf("read %s\n", buf);
n_stream_close(st);
}
void test_getline(const char *name)
{
tn_stream *st;
char *buf = n_malloc(16);
int n;
st = n_stream_open(name, "r", TN_STREAM_UNKNOWN);
n = n_stream_getline(st, &buf, 16);
printf("getline = %d (%s)\n", n, buf);
n_assert(strlen(buf) == n);
n_stream_close(st);
}
int main(int argc, char *argv[])
{
if (argc > 1) {
//test_write(argv[1], "a+");
test_getline(argv[1]);
}
return 0;
}