summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt5
-rw-r--r--CMakeLists.txt2
-rw-r--r--bowshock/CMakeLists.txt1
-rw-r--r--bowshock/include/bow/bs.hxx16
-rw-r--r--bowshock/source/init/bow/compShd.cxx24
-rw-r--r--bowshock/source/init/bow/cred.cxx45
-rw-r--r--bowshock/source/init/bow/getSavPth.cxx8
-rw-r--r--bowshock/source/sav/cont.cxx23
-rw-r--r--bowshock/source/sav/sav.cxx24
9 files changed, 82 insertions, 66 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 6d51283..be82f4f 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,8 @@
+# 0.B.1
+
+* Fortify sources;
+* Use Flux more;
+
# 0.B.0
* Use generator expressions in CMake;
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3a2b650..15df5ca 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.21)
project(
bowshock
- VERSION 0.11.0
+ VERSION 0.11.1
HOMEPAGE_URL "https://mandelbrot.dk/bowshock"
LANGUAGES C CXX
)
diff --git a/bowshock/CMakeLists.txt b/bowshock/CMakeLists.txt
index 13b62e2..b35355a 100644
--- a/bowshock/CMakeLists.txt
+++ b/bowshock/CMakeLists.txt
@@ -75,6 +75,7 @@ target_link_libraries(
target_compile_definitions(
bowshock PRIVATE
+ _FORTIFY_SOURCE=$<IF:$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">,0x0,0x2>
_POSIX_C_SOURCE=200112l
GLFW_INCLUDE_NONE
bow_datDir="/home/delta/Repositories/bowshock/datdir"
diff --git a/bowshock/include/bow/bs.hxx b/bowshock/include/bow/bs.hxx
index bb867fb..e74a584 100644
--- a/bowshock/include/bow/bs.hxx
+++ b/bowshock/include/bow/bs.hxx
@@ -2,14 +2,6 @@
#pragma once
-// flux is retarded and uses compound literals - even for C++. We override this nonsense with some value initialisations.
-#include <flux/io.h>
-#undef flux_disc
-#undef flux_keep
-#define flux_disc (::flux_priv_disc {._disc = true,})
-#define flux_keep (::flux_priv_disc {._disc = false,})
-// Note: flux will recieve better (C++) support in the future.
-
#ifndef bow_datDir
#error Data directory not specified!
#endif
@@ -36,6 +28,10 @@ static_assert(::zap::bytelen == 0x8u,"Bytes must contain exactly eight bits.");
#define bow_setStrLen(ptr,len,str) ((void)(ptr = str,len = sizeof (str) - 0x1u))
namespace bow {
+ constexpr ::zap::i04 verMaj = 0x0u;
+ constexpr ::zap::i04 verMin = 0xBu;
+ constexpr ::zap::i04 verPat = 0x1u;
+
constexpr bool dbg = bow_dbg;
constexpr ::zap::sz cmdrNmLen = 0xEu;
@@ -136,10 +132,6 @@ namespace bow {
float zoom;
};
- constexpr ::zap::i04 verMaj = 0x0u;
- constexpr ::zap::i04 verMin = 0xBu;
- constexpr ::zap::i04 verPat = 0x0u;
-
char const * objTypStr(::bow::objTyp typ) noexcept;
::zap::i04 rnd() noexcept;
diff --git a/bowshock/source/init/bow/compShd.cxx b/bowshock/source/init/bow/compShd.cxx
index eeba260..7615a0d 100644
--- a/bowshock/source/init/bow/compShd.cxx
+++ b/bowshock/source/init/bow/compShd.cxx
@@ -2,8 +2,9 @@
#include <bow/init.hxx>
-#include <cstdio>
#include <cstdlib>
+#include <flux/io.hh>
+#include <flux/stats.hh>
#include <glad/glad.h>
#include <stdexcept>
#include <zap/mem.hh>
@@ -49,21 +50,26 @@ void ::bow::bow::compShd(GLuint & shd,char const * const nm,GLenum const typ) {
bow_logDbg("compiling %s shader at \"%s\"",typStr,pth);
- FILE * fp = ::std::fopen(pth,"r");
+ ::flux::fil fil;
+ ::flux::err err = fil.op(pth,::flux::md::rd,::flux::keep);
- delete[] pth;
+ if (err != ::flux::err::ok) [[unlikely]] {throw ::std::runtime_error {"unable to open shader source"};}
+
+ ::zap::sz const filsz = [&pth]() {
+ ::flux::stats stats;
+ ::flux::stat(stats,pth);
- if (fp == nullptr) {throw ::std::runtime_error {"unable to open shader source"};}
+ return stats.sz;
+ }();
- ::std::fseek(fp,0x0,SEEK_END);
- ::zap::sz const filsz = static_cast<::zap::sz>(ftell(fp));
- ::std::rewind(fp);
+ delete[] pth;
static_assert(sizeof (GLchar) == sizeof (char));
GLchar * const src = new GLchar[filsz + 0x1u];
- ::std::fread(src,sizeof (GLchar),filsz,fp);
- ::std::fclose(fp);
+ err = fil.rd(src,filsz);
+ if (err != ::flux::err::ok) {throw ::std::runtime_error {"unable to read shader source"};}
+ fil.cl();
src[filsz] = '\x00';
diff --git a/bowshock/source/init/bow/cred.cxx b/bowshock/source/init/bow/cred.cxx
index 905ddd1..f3a9f09 100644
--- a/bowshock/source/init/bow/cred.cxx
+++ b/bowshock/source/init/bow/cred.cxx
@@ -2,39 +2,58 @@
#include <bow/init.hxx>
-#include <flux/io.h>
-#include <cstdio>
+#include <flux/io.hh>
+#include <flux/stats.hh>
#include <cstdlib>
+#include <stdexcept>
void ::bow::bow::cred() noexcept {
- FILE * fp = ::std::fopen(bow_datDir "/CREDITS.txt","r");
+ char const * const pth = bow_datDir "/CREDITS.txt";
- ::std::fseek(fp,0x0,SEEK_END);
- ::zap::sz const filsz = (::zap::sz)ftell(fp);
- ::std::rewind(fp);
+ ::zap::sz const filsz = [&pth]() {
+ ::flux::stats stats;
+ ::flux::stat(stats,pth);
- char * cred = new char[filsz + 0x3u];
- char * const credstart = cred;
+ return stats.sz;
+ }();
+
+ ::flux::fil fil;
+ ::flux::err err = fil.op(pth,::flux::md::rd,::flux::keep);
+
+ if (err != ::flux::err::ok) [[unlikely]] {
+ bow_logErr("unable to open credits file");
+
+ ::std::exit(EXIT_FAILURE);
+ }
- if (cred == nullptr) {
+ char * cred;
+
+ try {cred = new char[filsz + 0x3u];}
+ catch (::std::bad_alloc const & e) {
bow_logErr("unable to allocate memory");
+
::std::exit(EXIT_FAILURE);
}
+ char * const credstart = cred;
+
*cred++ = '\n';
- cred += ::std::fread(cred,sizeof (char),filsz,fp);
- ::std::fclose(fp);
+ fil.rd(cred,filsz);
+ fil.cl();
+ cred += filsz;
*cred++ = '\n';
*cred++ = '\x00';
cred = credstart;
- ::flux_err err = ::flux_wrstr(::flux_defout,cred);
+ ::flux::dflout.wr(cred,filsz + 0x3u);
- if (err) {
+ if (err != ::flux::err::ok) {
bow_logErr("unable to write to defout");
+
+ ::std::exit(EXIT_FAILURE);
}
delete[] cred;
diff --git a/bowshock/source/init/bow/getSavPth.cxx b/bowshock/source/init/bow/getSavPth.cxx
index ad0e6e1..030dfa1 100644
--- a/bowshock/source/init/bow/getSavPth.cxx
+++ b/bowshock/source/init/bow/getSavPth.cxx
@@ -3,15 +3,15 @@
#include <bow/init.hxx>
#include <cstdlib>
-#include <flux/stats.h>
+#include <flux/stats.hh>
#include <zap/mem.hh>
#include <zap/str.hh>
char const * ::bow::bow::getSavPth() noexcept {
- char const * hmDir = ::flux_hmdir();
+ char const * hmDir = ::flux::hmdir();
char const * filNm;
- ::zap::sz hmDirLen;
- ::zap::sz filNmLen;
+ ::zap::sz hmDirLen;
+ ::zap::sz filNmLen;
if (hmDir == nullptr) [[unlikely]] {
bow_log("unable to get home directory, using current directory");
diff --git a/bowshock/source/sav/cont.cxx b/bowshock/source/sav/cont.cxx
index 9132586..d50ded7 100644
--- a/bowshock/source/sav/cont.cxx
+++ b/bowshock/source/sav/cont.cxx
@@ -3,41 +3,42 @@
#include <bow/sav.hxx>
#include <cinttypes>
-#include <flux/io.h>
+#include <flux/io.hh>
#include <zap/mem.hh>
void ::bow::cont(::bow::plDat & plDat,char const * const pth) noexcept {
bow_log("loading save file at \"%s\"",pth);
- ::flux_fil * fil;
- ::flux_err err = ::flux_op(&fil,pth,::flux_md_rd,flux_keep);
+ ::flux::fil fil;
+
+ ::flux::err err = fil.op(pth,::flux::md::rd,::flux::keep);
- if (err) [[unlikely]] {
+ if (err != ::flux::err::ok) [[unlikely]] {
bow_logErr("unable to open save file \"%s\"",pth);
return ::bow::newSav(plDat);
}
::zap::i8 rawDat[::bow::savLen];
- err = ::flux_rd(rawDat,fil,::bow::savLen,nullptr);
+ err = fil.rd(rawDat,::bow::savLen);
- if (err) [[unlikely]] {
- ::flux_cl(fil);
+ if (err != ::flux::err::ok) [[unlikely]] {
+ fil.cl();
- if (err == ::flux_err_eof) bow_logErr("corrupt save file at \"%s\"",pth);
- else bow_logErr("unable to read file at \"%s\"",pth);
+ if (err == ::flux::err::eof) bow_logErr("corrupt save file at \"%s\"",pth);
+ else bow_logErr("unable to read file at \"%s\"",pth);
return ::bow::newSav(plDat);
}
- ::flux_cl(fil);
+ fil.cl();
::bow::savDat dat;
::bow::decSav(dat,rawDat);
if (dat.fmtVer != ::bow::savVer) [[unlikely]] {
- bow_logErr("invalid format (%" PRIX64 " of save file at \"%s\"",dat.fmtVer,pth);
+ bow_logErr("invalid format (%" PRIX64 ") of save file at \"%s\"",dat.fmtVer,pth);
return ::bow::newSav(plDat);
}
diff --git a/bowshock/source/sav/sav.cxx b/bowshock/source/sav/sav.cxx
index 38de722..48e2ef6 100644
--- a/bowshock/source/sav/sav.cxx
+++ b/bowshock/source/sav/sav.cxx
@@ -3,26 +3,18 @@
#include <bow/run.hxx>
#include <bow/sav.hxx>
-#include <flux/io.h>
+#include <flux/io.hh>
#include <zap/mem.hh>
void ::bow::sav(char const * const pth,::bow::plDat const & plDat) noexcept {
bow_log("saving commander %s at \"%s\"",plDat.nm,pth);
- ::flux_fil * fil;
- ::flux_err err = ::flux_mkfil(&fil,pth,0644);
+ ::flux::fil fil;
+ ::flux::err err = fil.mk(pth,0644u);
- if (err) [[unlikely]] {
- if (err != ::flux_err_exist) [[unlikely]] {
- bow_logErr("unable to open save file \"%s\"",pth);
- ::bow::abrt();
- }
-
- err = ::flux_op(&fil,pth,::flux_md_wr,flux_disc);
- if (err) [[unlikely]] {
- bow_logErr("unable to create save file \"%s\"",pth);
- ::bow::abrt();
- }
+ if (err != ::flux::err::ok) [[unlikely]] {
+ bow_logErr("unable to open save file \"%s\"",pth);
+ ::bow::abrt();
}
::zap::i8 dat[::bow::savLen];
@@ -49,6 +41,6 @@ void ::bow::sav(char const * const pth,::bow::plDat const & plDat) noexcept {
::bow::encSav(dat,savDat);
- ::flux_wr(fil,dat,::bow::savLen);
- ::flux_cl(fil);
+ fil.wr(dat,::bow::savLen);
+ fil.cl();
}