3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2004-2010 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 if (ftruncate(fd, 0) < 0)
56 memset(value, 0, sizeof(value));
57 for (i = 0; i < (size / sizeof(value)); i++) {
58 if (write(fd, value, sizeof(value)) < 0)
64 sprintf(key, "11:11:11:11:11:11");
65 str = textfile_get(filename, key);
67 if (truncate(filename, 0) < 0)
70 sprintf(key, "00:00:00:00:00:00");
71 if (textfile_del(filename, key) < 0)
72 fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
74 memset(value, 0, sizeof(value));
75 if (textfile_put(filename, key, value) < 0)
76 fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
78 str = textfile_get(filename, key);
80 fprintf(stderr, "No value for %s\n", key);
84 snprintf(value, sizeof(value), "Test");
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_put(filename, key, value) < 0)
92 fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
94 if (textfile_del(filename, key) < 0)
95 fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
97 str = textfile_get(filename, key);
99 fprintf(stderr, "Found value for %s\n", key);
103 for (i = 1; i < max + 1; i++) {
104 sprintf(key, "00:00:00:00:00:%02X", i);
106 memset(value, 0, sizeof(value));
107 for (j = 0; j < i; j++)
110 printf("%s %s\n", key, value);
112 if (textfile_put(filename, key, value) < 0) {
113 fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
117 str = textfile_get(filename, key);
119 fprintf(stderr, "No value for %s\n", key);
125 sprintf(key, "00:00:00:00:00:%02X", max);
127 memset(value, 0, sizeof(value));
128 for (j = 0; j < max; j++)
131 if (textfile_put(filename, key, value) < 0)
132 fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
134 sprintf(key, "00:00:00:00:00:%02X", 1);
136 memset(value, 0, sizeof(value));
137 for (j = 0; j < max; j++)
140 if (textfile_put(filename, key, value) < 0)
141 fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
145 for (i = 1; i < max + 1; i++) {
146 sprintf(key, "00:00:00:00:00:%02X", i);
148 str = textfile_get(filename, key);
150 printf("%s %s\n", key, str);
156 sprintf(key, "00:00:00:00:00:%02X", 2);
158 if (textfile_del(filename, key) < 0)
159 fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
161 sprintf(key, "00:00:00:00:00:%02X", max - 3);
163 if (textfile_del(filename, key) < 0)
164 fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
168 textfile_foreach(filename, print_entry, NULL);
171 sprintf(key, "00:00:00:00:00:%02X", 1);
173 if (textfile_del(filename, key) < 0)
174 fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
176 sprintf(key, "00:00:00:00:00:%02X", max);
178 if (textfile_del(filename, key) < 0)
179 fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
181 sprintf(key, "00:00:00:00:00:%02X", max + 1);
183 if (textfile_del(filename, key) < 0)
184 fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
188 textfile_foreach(filename, print_entry, NULL);