summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorHello TMW <hello@themanaworld.org>2024-09-17 14:04:03 +0000
committerHello TMW <hello@themanaworld.org>2024-09-17 14:04:03 +0000
commit3a0bfe045e24a8d769c60b513ade85505926be70 (patch)
tree9c8b265ac18c45bf6e51745af32b471646422b26 /src/shared
parent90754fd121ffaec886c415689031f9ef01ae4972 (diff)
parent48ee77e4fdfc3741996df0ddaca49c090292fc10 (diff)
downloadtmwa-3a0bfe045e24a8d769c60b513ade85505926be70.tar.gz
tmwa-3a0bfe045e24a8d769c60b513ade85505926be70.tar.bz2
tmwa-3a0bfe045e24a8d769c60b513ade85505926be70.tar.xz
tmwa-3a0bfe045e24a8d769c60b513ade85505926be70.zip
Merge branch tmwa:master into master
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/lib.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/shared/lib.cpp b/src/shared/lib.cpp
index 0eebf17..c0a4371 100644
--- a/src/shared/lib.cpp
+++ b/src/shared/lib.cpp
@@ -35,25 +35,37 @@
namespace tmwa
{
static
- void try_read(const io::DirFd& dirfd, ZString filename)
+ void try_read(const io::DirFd& dirfd, LString dir_path, ZString filename)
{
io::ReadFile rf(dirfd, filename);
if (!rf.is_open())
+ {
+ FPRINTF(stderr, "Could not open %s/%s\n"_fmt, dir_path, filename);
abort();
+ }
AString line;
if (!rf.getline(line))
+ {
+ FPRINTF(stderr, "Could not read from %s/%s\n"_fmt, dir_path, filename);
abort();
+ }
}
static
- void try_write(const io::DirFd& dirfd, ZString filename)
+ void try_write(const io::DirFd& dirfd, LString dir_path, ZString filename)
{
io::WriteFile wf(dirfd, filename);
if (!wf.is_open())
+ {
+ FPRINTF(stderr, "Could not open %s/%s\n"_fmt, dir_path, filename);
abort();
+ }
wf.put_line("Hello, World!"_s);
if (!wf.close())
+ {
+ FPRINTF(stderr, "Could not write to %s/%s\n"_fmt, dir_path, filename);
abort();
+ }
}
void check_paths()
@@ -65,13 +77,17 @@ namespace tmwa
io::DirFd root(portable_root);
- io::DirFd etc(root, PACKAGESYSCONFDIR.xslice_t(portable));
- io::DirFd var(root, PACKAGELOCALSTATEDIR.xslice_t(portable));
- io::DirFd share(root, PACKAGEDATADIR.xslice_t(portable));
+ LString etc_path = PACKAGESYSCONFDIR.xslice_t(portable);
+ LString var_path = PACKAGELOCALSTATEDIR.xslice_t(portable);
+ LString share_path = PACKAGEDATADIR.xslice_t(portable);
- try_read(etc, "shared.conf"_s);
- try_read(share, "shared.data"_s);
- try_write(var, "shared.test"_s);
+ io::DirFd etc(root, etc_path);
+ io::DirFd var(root, var_path);
+ io::DirFd share(root, share_path);
+
+ try_read(etc, etc_path, "shared.conf"_s);
+ try_read(share, share_path, "shared.data"_s);
+ try_write(var, var_path, "shared.test"_s);
// io::FD::open();
}