summaryrefslogtreecommitdiff
path: root/apps/plugins/text_viewer/tv_bookmark.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/text_viewer/tv_bookmark.c')
-rw-r--r--apps/plugins/text_viewer/tv_bookmark.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/apps/plugins/text_viewer/tv_bookmark.c b/apps/plugins/text_viewer/tv_bookmark.c
index 815e7a1f91..5f77d2a92c 100644
--- a/apps/plugins/text_viewer/tv_bookmark.c
+++ b/apps/plugins/text_viewer/tv_bookmark.c
@@ -32,7 +32,6 @@ enum {
32 TV_BOOKMARK_USER = 2, 32 TV_BOOKMARK_USER = 2,
33}; 33};
34 34
35#define SERIALIZE_BOOKMARK_SIZE 8
36 35
37struct tv_bookmark_info { 36struct tv_bookmark_info {
38 struct tv_screen_pos pos; 37 struct tv_screen_pos pos;
@@ -287,11 +286,8 @@ bool tv_deserialize_bookmarks(int fd)
287 return res; 286 return res;
288} 287}
289 288
290static bool tv_write_bookmark_info(int fd, const struct tv_bookmark_info *b) 289static void tv_write_bookmark_info(unsigned char *p, const struct tv_bookmark_info *b)
291{ 290{
292 unsigned char buf[SERIALIZE_BOOKMARK_SIZE];
293 unsigned char *p = buf;
294
295 *p++ = b->pos.file_pos >> 24; 291 *p++ = b->pos.file_pos >> 24;
296 *p++ = b->pos.file_pos >> 16; 292 *p++ = b->pos.file_pos >> 16;
297 *p++ = b->pos.file_pos >> 8; 293 *p++ = b->pos.file_pos >> 8;
@@ -302,21 +298,17 @@ static bool tv_write_bookmark_info(int fd, const struct tv_bookmark_info *b)
302 298
303 *p++ = b->pos.line; 299 *p++ = b->pos.line;
304 *p = b->flag; 300 *p = b->flag;
305
306 return (rb->write(fd, buf, SERIALIZE_BOOKMARK_SIZE) >= 0);
307} 301}
308 302
309int tv_serialize_bookmarks(int fd) 303int tv_serialize_bookmarks(unsigned char *buf)
310{ 304{
311 int i; 305 int i;
312 306
313 if (rb->write(fd, &bookmark_count, 1) < 0) 307 buf[0] = bookmark_count;
314 return 0;
315 308
316 for (i = 0; i < bookmark_count; i++) 309 for (i = 0; i < bookmark_count; i++)
317 { 310 {
318 if (!tv_write_bookmark_info(fd, &bookmarks[i])) 311 tv_write_bookmark_info(buf + i * SERIALIZE_BOOKMARK_SIZE + 1, &bookmarks[i]);
319 break;
320 } 312 }
321 return i * SERIALIZE_BOOKMARK_SIZE + 1; 313 return i * SERIALIZE_BOOKMARK_SIZE + 1;
322} 314}