Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
translations translations
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Welcome to the Rockbox Technical Forums!

+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  fopen file in .rockbox dir
« previous next »
  • Print
Pages: [1]

Author Topic: fopen file in .rockbox dir  (Read 550 times)

Offline rockbox_dev123

  • Member
  • *
  • Posts: 164
fopen file in .rockbox dir
« on: May 28, 2025, 03:26:44 PM »
Hi,

I'm playing around and compiling my first Rockbox plugin with the simulator but I'm having trouble opening files.

I'm doing this:
Code: [Select]
    if (rb->file_exists(ROCKBOX_DIR"/foo/bar.txt"))
    {
        rb->splashf(2*HZ, "exists");
        dp = fopen(ROCKBOX_DIR"/foo/bar.txt", "rt");
        if (dp == NULL)
        {
            rb->splashf(2*HZ, "%d", errno);
            return PLUGIN_OK;
        }
        else
        {
            /* I never get here */
            do_something_with_bar();
        }
    }

Which gives me a splash confirming that my file exists in the location I am trying to access it.

However, when I make the fopen call to the same path I get an errno value of 2 which I believe indicates ENOENT No such file or directory. Do I need to transform the path somehow?

EDIT:

I've managed to get it to work by placing my files in the same directory as the rockboxui binary.

e.g. if you are trying to access a file like this:
Code: [Select]
open("/foo/bar.txt", "rt");It will work if you place this in the build directory where the simulator is:
Code: [Select]
├── simdisk
├── foo
│   └── bar.txt
└── rockboxui

I'll work out if I need to change the path once the plugin is finished and I'm ready to test on hardware.
« Last Edit: May 28, 2025, 03:38:28 PM by rockbox_dev123 »
Logged

Offline rockbox_dev123

  • Member
  • *
  • Posts: 164
Re: fopen file in .rockbox dir
« Reply #1 on: May 28, 2025, 06:53:21 PM »
I've finished writing my plugin and I'm ready to test it on my iPod. Unfortunately, I've found that when doing
Code: [Select]
rb->srand(*rb->current_tick);to get a random value that if I call my plugin on startup, as the current tick is always the same the value is not random.

I've pored through the codebase and had a look at /firmware/libc/gmtime.c but I couldn't find a UNIX epoch time struct anywhere that I could use with srand like a traditional time() call.

Can anyone advise on how I can get a good seed for srand on the players boot?

Thanks in advance
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 1194
Re: fopen file in .rockbox dir
« Reply #2 on: May 29, 2025, 01:01:32 PM »
yeah our random is deterministic same srand same 'random' numbers
I assume this is in the sim? On an actual device I'd expect enough variability by the time you got into the plugin
to make this not occur maybe you can add in something that makes the wait a bit more variable prior to the srand call?

maybe something like waiting a bit:
Code: [Select]
static void wait(void)
{
#ifdef SIMULATOR
    rb->splashf(0, "Press any button.");
    while (rb->get_action(CONTEXT_STD, 1) == ACTION_NONE)
    {
        rb->yield();
    }
#endif
}
Logged

Offline rockbox_dev123

  • Member
  • *
  • Posts: 164
Re: fopen file in .rockbox dir
« Reply #3 on: June 02, 2025, 09:35:05 PM »
I managed to finish my plugin. It's a port of display-dhammapada with an updated translation courtesy of the BPS. It's not in a state to be upstreamed so I'm uploading it here instead for anyone interested.

The plugin selects a random set of verses and displays them verse by verse using simple_viewer.c. On an iPod Classic I can press skip backwards, menu or select to advance the verses until the end of the range.

I have the plugin set to run on startup now and it works well.

Quote
display-dhammapada was originally written by Richard Cepas <rch@online.lt> and later updated by bodhi.zazen <bodhizazen at fedoraproject dot org> and paultag <paultag at ubuntu.com>

Place dhammapada-english-bps.txt into .rockbox/dhammapada/dhammapada-english-bps.txt then you can compile dhammapada.c like you would any other C plugin. Docs here.
* dhammapada.c (7.92 kB - downloaded 75 times.)

* dump 250603-022456.png (1.05 kB, 320x240 - viewed 145 times.)

* dump 250603-022628.png (1.6 kB, 320x240 - viewed 141 times.)
* dhammapada-english-bps.txt (61.91 kB - downloaded 73 times.)
Logged

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  fopen file in .rockbox dir
 

  • SMF 2.0.19 | SMF © 2021, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.057 seconds with 16 queries.