3
* BlueZ - Bluetooth protocol stack for Linux
5
* Copyright (C) 2004-2009 Marcel Holtmann <marcel@holtmann.org>
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
37
static void print_entry(char *key, char *value, void *data)
39
printf("%s %s\n", key, value);
42
int main(int argc, char *argv[])
44
char filename[] = "/tmp/textfile";
45
char key[18], value[512], *str;
46
unsigned int i, j, size, max = 10;
50
printf("System uses a page size of %d bytes\n\n", size);
52
fd = creat(filename, 0644);
53
err = ftruncate(fd, 0);
55
memset(value, 0, sizeof(value));
56
for (i = 0; i < (size / sizeof(value)); i++)
57
err = write(fd, value, sizeof(value));
61
sprintf(key, "11:11:11:11:11:11");
62
str = textfile_get(filename, key);
64
err = truncate(filename, 0);
67
sprintf(key, "00:00:00:00:00:00");
68
if (textfile_del(filename, key) < 0)
69
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
71
memset(value, 0, sizeof(value));
72
if (textfile_put(filename, key, value) < 0)
73
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
75
str = textfile_get(filename, key);
77
fprintf(stderr, "No value for %s\n", key);
81
snprintf(value, sizeof(value), "Test");
82
if (textfile_put(filename, key, value) < 0)
83
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
85
if (textfile_put(filename, key, value) < 0)
86
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
88
if (textfile_put(filename, key, value) < 0)
89
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
91
if (textfile_del(filename, key) < 0)
92
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
94
str = textfile_get(filename, key);
96
fprintf(stderr, "Found value for %s\n", key);
100
for (i = 1; i < max + 1; i++) {
101
sprintf(key, "00:00:00:00:00:%02X", i);
103
memset(value, 0, sizeof(value));
104
for (j = 0; j < i; j++)
107
printf("%s %s\n", key, value);
109
if (textfile_put(filename, key, value) < 0) {
110
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
114
str = textfile_get(filename, key);
116
fprintf(stderr, "No value for %s\n", key);
122
sprintf(key, "00:00:00:00:00:%02X", max);
124
memset(value, 0, sizeof(value));
125
for (j = 0; j < max; j++)
128
if (textfile_put(filename, key, value) < 0)
129
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
131
sprintf(key, "00:00:00:00:00:%02X", 1);
133
memset(value, 0, sizeof(value));
134
for (j = 0; j < max; j++)
137
if (textfile_put(filename, key, value) < 0)
138
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
142
for (i = 1; i < max + 1; i++) {
143
sprintf(key, "00:00:00:00:00:%02X", i);
145
str = textfile_get(filename, key);
147
printf("%s %s\n", key, str);
153
sprintf(key, "00:00:00:00:00:%02X", 2);
155
if (textfile_del(filename, key) < 0)
156
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
158
sprintf(key, "00:00:00:00:00:%02X", max - 3);
160
if (textfile_del(filename, key) < 0)
161
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
165
textfile_foreach(filename, print_entry, NULL);
168
sprintf(key, "00:00:00:00:00:%02X", 1);
170
if (textfile_del(filename, key) < 0)
171
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
173
sprintf(key, "00:00:00:00:00:%02X", max);
175
if (textfile_del(filename, key) < 0)
176
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
178
sprintf(key, "00:00:00:00:00:%02X", max + 1);
180
if (textfile_del(filename, key) < 0)
181
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
185
textfile_foreach(filename, print_entry, NULL);