Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: Multiple Read Failure

Multiple Read Failure

From: Benjamin <mailinglists_at_samuraipanda.com>
Date: Mon, 13 Jan 2003 13:28:21 -0800

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 www.samuraipanda.com/fullsrc.zip (~1.4MB).

Ben


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);
    
    if(fd<0)
       return false;
       
    close(fd);

    //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);
         while(success)
         {
            nread = read(fd, read_char, 1);
            if(nread <= 0)
            {
                //Error condition
                bookmark_display_message("global_settings.resume_index");

                success = false;
                break;
            }
            else
               //Parse the resume index
          }
          //Read the rest of the bookmark file
    }
}
Received on 2003-01-14

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy