3
* BlueZ - Bluetooth protocol stack for Linux
5
* Copyright (C) 2004-2008 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
int i, j, fd, err, size, max = 10;
49
printf("System uses a page size of %d bytes\n\n", size);
51
fd = creat(filename, 0644);
52
err = ftruncate(fd, 0);
54
memset(value, 0, sizeof(value));
55
for (i = 0; i < (size / sizeof(value)); i++)
56
err = write(fd, value, sizeof(value));
60
sprintf(key, "11:11:11:11:11:11");
61
str = textfile_get(filename, key);
63
err = truncate(filename, 0);
66
sprintf(key, "00:00:00:00:00:00");
67
if (textfile_del(filename, key) < 0)
68
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
70
memset(value, 0, sizeof(value));
71
if (textfile_put(filename, key, value) < 0)
72
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
74
str = textfile_get(filename, key);
76
fprintf(stderr, "No value for %s\n", key);
80
snprintf(value, sizeof(value), "Test");
81
if (textfile_put(filename, key, value) < 0)
82
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
84
if (textfile_put(filename, key, value) < 0)
85
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
87
if (textfile_put(filename, key, value) < 0)
88
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
90
if (textfile_del(filename, key) < 0)
91
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
93
str = textfile_get(filename, key);
95
fprintf(stderr, "Found value for %s\n", key);
99
for (i = 1; i < max + 1; i++) {
100
sprintf(key, "00:00:00:00:00:%02X", i);
102
memset(value, 0, sizeof(value));
103
for (j = 0; j < i; j++)
106
printf("%s %s\n", key, value);
108
if (textfile_put(filename, key, value) < 0) {
109
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
113
str = textfile_get(filename, key);
115
fprintf(stderr, "No value for %s\n", key);
121
sprintf(key, "00:00:00:00:00:%02X", max);
123
memset(value, 0, sizeof(value));
124
for (j = 0; j < max; j++)
127
if (textfile_put(filename, key, value) < 0)
128
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
130
sprintf(key, "00:00:00:00:00:%02X", 1);
132
memset(value, 0, sizeof(value));
133
for (j = 0; j < max; j++)
136
if (textfile_put(filename, key, value) < 0)
137
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
141
for (i = 1; i < max + 1; i++) {
142
sprintf(key, "00:00:00:00:00:%02X", i);
144
str = textfile_get(filename, key);
146
printf("%s %s\n", key, str);
152
sprintf(key, "00:00:00:00:00:%02X", 2);
154
if (textfile_del(filename, key) < 0)
155
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
157
sprintf(key, "00:00:00:00:00:%02X", max - 3);
159
if (textfile_del(filename, key) < 0)
160
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
164
textfile_foreach(filename, print_entry, NULL);
167
sprintf(key, "00:00:00:00:00:%02X", 1);
169
if (textfile_del(filename, key) < 0)
170
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
172
sprintf(key, "00:00:00:00:00:%02X", max);
174
if (textfile_del(filename, key) < 0)
175
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
177
sprintf(key, "00:00:00:00:00:%02X", max + 1);
179
if (textfile_del(filename, key) < 0)
180
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
184
textfile_foreach(filename, print_entry, NULL);