dev builds
themes manual
device status forums
mailing lists
IRC bugs
dev guide

Rockbox mail archive

Subject: Multiple Read Failure
From: Benjamin (
Date: 2003-01-13

One thing that I have noticed developing the bookmarking capability
is that opening and closing a file and then opening it again quickly
can result in a read failure for the second open. Below is a snippet
of the code I use to auto-load a bookmark. If I leave the line blow
marked with *** out and compile, calling bookmark_autoload() will
prompt the user and the call bookmark_load(). Bookmark_load will
then fail at the first read after successfully opening the file.
If I leave the line in and compile, then bookmark_autoload() will
call bookmark_load() and bookmark_load() will successfully read the
line. I'm not sure if I'm over-running some memory, but I don't
see anything blatantly wrong.

Full source can be found at (~1.4MB).


bool bookmark_autoload(char* file)
    char bookmark_file_name[MAX_PATH+5];
    bool done = false;
    int key;
    int fd;
    //Checking to see if a bookmark file exists.
    snprintf(bookmark_file_name, MAX_PATH+5, "%s.%s", file, "bmf");
    fd = open(bookmark_file_name, O_RDONLY);
       return false;

    //Prompt the user if they want to load the bookmark
    //if yes:
          bookmark_load(bookmark_file_name, false);

void bookmark_load(char* file, bool ask_resume_bookmark)
    int fd;
    int nread = 0;
    char read_buf[MAX_PATH];
    char read_char[1];
    char error_buf[MAX_PATH];
    bool success = true;
    int read_count = 0;
    memset(read_buf, 0, MAX_PATH);
    memset(error_buf, 0, MAX_PATH);
    fd = open(file, O_RDONLY);

    snprintf(error_buf, "%s: %2d", file, fd); // ***
    if(fd >= 0)
         //reading the global_settings.resume_index
         read_count = 0;
         memset(read_buf, 0, MAX_PATH);
            nread = read(fd, read_char, 1);
            if(nread <= 0)
                //Error condition

                success = false;
               //Parse the resume index
          //Read the rest of the bookmark file

Page was last modified "Jan 10 2012" The Rockbox Crew