Jackalope / jlib (public) (License: GPLv3 or later) (since 2019-11-18) (hash sha1)
jlib C++ template library
Used to replace std functionality without exception handling.
- data structures
- filesystem routines
- crossplatform threads interface (currently only pthreads implementation)
- thread pool
- crossplatform dynamic memory functions interface (allocate, reallocate, deallocate) with alignment support
- high percision timer routines based on timespec
List of commits:
Subject Hash Author Date (UTC)
added read whole TEXT file func also (only binary was before) d70894b97e0760c85fa03bf802d36a840d331bc9 Jackalope 2020-05-20 19:05:49
Changed cmake library interface 0b4c87b296597ae929dc1038e9eefbf155250fa7 Jackalope 2020-05-12 06:57:42
added byte_array and byte_array_ro typedefs 902916f777983eba78d325e9f9c9c01bd2502ca3 Jackalope 2020-05-11 07:47:33
remove _BIT postfix from file opening flags 1cf92db6ccb85c2ac0ed7f86fbdfeac97745bd45 Jackalope 2020-05-11 07:46:51
added license 16a67712bb2ffd15263a6a146a06d4860f435645 Jackalope 2020-05-09 23:31:00
code refactoring 7cfcdc6b9382cea7227d44746c166747fced61a0 Jackalope 2020-05-09 23:05:21
add check for threads count to prevent bloating ce23263c2c053dd1374d54c618b6850215077880 Jackalope 2020-04-21 22:11:24
pthreads detach function fix 8ac43fe43beca9b55d2ea605e0c3fd821b8b5579 Jackalope 2020-04-15 09:53:11
make asserts constexpr compatible 4c2dfc64c3d9587ee9b749db9355f4e0d6003547 Jackalope 2020-03-29 07:03:08
changed default grow policy size addition to 8 619dc29be4ed4ac049cbee81a92e37f29ffd8b7c Jackalope 2020-03-06 07:05:53
comment fixes 73b30cdb75c18752d55c38d862c2c8e54c7b5b5d TheArtOfGriefing 2020-02-15 19:55:30
comment fixes a10726439280c28a5317db2baf3f2de907ba5595 TheArtOfGriefing 2020-02-15 19:53:25
comments fix c07ffee6225640072ec2b064c73097f73824868e TheArtOfGriefing 2020-02-15 18:44:58
comments 610cb9723e9451e21ee23bfd2748febb1d8d5889 TheArtOfGriefing 2020-02-13 18:26:23
threads code style refactoring 3e11b789a11d4d36ba7e1515118d916d05a52a12 Jackalope 2020-02-11 03:09:19
remove several function be4d8627a56e807dd5b0675f1ae3ba9135720db1 Jackalope 2020-02-09 14:55:26
darray function insert dummy item without size checking b3bf411a1545760ee5a7dc8f5afc455335a1927e Jackalope 2020-02-04 05:35:07
make array count functions static and constexpr 272f99f2929b282513aaa529089a8f093db1c8c0 Jackalope 2020-02-01 05:42:45
grammar correction for allocate.h bf1c90dfe7335bb6e57e9bdec7833ef842c616fd TheArtOfGriefing 2020-01-27 20:09:18
changed array2D and array3D template arguments order 37f03f7de5ccc7fbc0c3c77db0b9f0c10e0dc027 jp.larry 2020-01-14 00:28:33
Commit d70894b97e0760c85fa03bf802d36a840d331bc9 - added read whole TEXT file func also (only binary was before)
Author: Jackalope
Author date (UTC): 2020-05-20 19:05
Committer name: Jackalope
Committer date (UTC): 2020-05-20 19:05
Parent(s): 0b4c87b296597ae929dc1038e9eefbf155250fa7
Signer:
Signing key:
Signing status: N
Tree: d47ae9f68b1cbe59c07716d6fa4c69326b277fe5
File Lines added Lines deleted
include/jlib/fs/file.h 9 2
include/jlib/fs/file.hpp 37 26
File include/jlib/fs/file.h changed (mode: 100644) (index cb2d99f..a034ddd)
27 27
28 28 namespace jl::fs { namespace jl::fs {
29 29 /** /**
30 * @brief Get whole file content.
30 * @brief Get whole file binary content.
31 31 * *
32 32 * After this function call is successfull, * After this function call is successfull,
33 33 * memory must be deallocated by jl::deallocate, when no longer needed. * memory must be deallocated by jl::deallocate, when no longer needed.
 
... ... namespace jl::fs {
44 44 */ */
45 45 [[nodiscard]] bool [[nodiscard]] bool
46 46 read_file(const char *filename, uint8_t **pp_dst, uint64_t *p_size); read_file(const char *filename, uint8_t **pp_dst, uint64_t *p_size);
47 /**
48 * @brief Get whole file textual content
49 * @see read_file
50 */
51 [[nodiscard]] bool
52 read_file(const char *filename, char **pp_dst, uint64_t *p_size);
47 53
48 54 [[nodiscard]] bool [[nodiscard]] bool
49 55 write_file(const char *filename, const uint8_t *p_src, uint64_t size); write_file(const char *filename, const uint8_t *p_src, uint64_t size);
 
... ... struct jl::fs::stream
65 71 WRITE_TO_END = 0b00001000, ///< writing to the end of stream WRITE_TO_END = 0b00001000, ///< writing to the end of stream
66 72 TEXT = 0b00010000, ///< operate as text stream TEXT = 0b00010000, ///< operate as text stream
67 73 }; };
74 using mask = uint8_t;
68 75 /** /**
69 76 * @brief Open file * @brief Open file
70 77 * After successful file opening, * After successful file opening,
 
... ... struct jl::fs::stream
76 83 * @see fs::error_no * @see fs::error_no
77 84 * @see stream::close * @see stream::close
78 85 */ */
79 [[nodiscard]] bool open_file(const char *path, flag flags);
86 [[nodiscard]] bool open_file(const char *path, mask flags);
80 87 /** /**
81 88 * @brief Close stream * @brief Close stream
82 89 * Must be used only if stream is opened. * Must be used only if stream is opened.
File include/jlib/fs/file.hpp changed (mode: 100644) (index 8635483..3d68bdc)
... ... namespace jl::fs::details
58 58 } }
59 59 /// Struct with c-string type mode for file opening. /// Struct with c-string type mode for file opening.
60 60 struct mode { struct mode {
61 constexpr mode(stream::flag flags) : str() {
61 constexpr mode(stream::mask flags) : str() {
62 62 int str_size = 0; int str_size = 0;
63 63 if (flags & stream::flag::READ) { if (flags & stream::flag::READ) {
64 64 if (flags & stream::flag::CLEAN) { if (flags & stream::flag::CLEAN) {
 
... ... namespace jl::fs::details
100 100 } }
101 101 } }
102 102 [[nodiscard]] inline bool jl::fs::stream:: [[nodiscard]] inline bool jl::fs::stream::
103 open_file(const char *path, flag flags) {
103 open_file(const char *path, mask flags) {
104 104 details::mode mode(flags); details::mode mode(flags);
105 105 p_file = fopen(path, mode.str); p_file = fopen(path, mode.str);
106 106 return p_file != nullptr; return p_file != nullptr;
 
... ... write_string(const char *p_src) {
209 209 write_string_locked(const char *p_src) { write_string_locked(const char *p_src) {
210 210 return details::write_str<true>(p_file, p_src); return details::write_str<true>(p_file, p_src);
211 211 } }
212 [[nodiscard]] inline jl::fs::stream::flag
213 operator | (jl::fs::stream::flag _1, jl::fs::stream::flag _2) {
214 return jl::fs::stream::flag(uint8_t(_1) | _2);
215 }
216 [[nodiscard]] inline bool jl::fs::
217 read_file(const char *filename, uint8_t **pp_dst, uint64_t *p_size) {
218 jl::fs::stream file;
219 if (not file.open_file(filename, jl::fs::stream::flag::READ))
220 return false;
221 if (file.pos_set_to_end()) {
222 size_t size = (*p_size) = size_t(file.pos());
223 if (not file.pos_set(0))
224 goto CANCEL;
225 if (not jl::allocate_bytes(pp_dst, size))
226 goto CANCEL;
227 if (not file.read_bytes(*pp_dst, size)) {
228 jl::deallocate(pp_dst);
229 goto CANCEL;
212 namespace jl::fs::detail {
213 template<int MASK, typename T>
214 [[nodiscard]] inline bool
215 read_file(const char *filename, T **pp_dst, uint64_t *p_size) {
216 jl::fs::stream file;
217 if (not file.open_file(filename, MASK))
218 return false;
219 if (file.pos_set_to_end()) {
220 size_t size = (*p_size) = size_t(file.pos());
221 if (not file.pos_set(0))
222 goto CANCEL;
223 if (not jl::allocate_bytes(pp_dst, size))
224 goto CANCEL;
225 if (not file.read_bytes(*pp_dst, size)) {
226 jl::deallocate(pp_dst);
227 goto CANCEL;
228 }
229 file.close();
230 return true;
230 231 } }
232 CANCEL:
231 233 file.close(); file.close();
232 return true;
234 return false;
233 235 } }
234 CANCEL:
235 file.close();
236 return false;
236 }
237 [[nodiscard]] inline bool jl::fs::
238 read_file(const char *filename, uint8_t **pp_dst, uint64_t *p_size) {
239 constexpr static const
240 stream::mask m = jl::fs::stream::flag::READ;
241 return detail::read_file<m>(filename, pp_dst, p_size);
242 }
243 [[nodiscard]] inline bool jl::fs::
244 read_file(const char *filename, char **pp_dst, uint64_t *p_size) {
245 constexpr static const
246 stream::mask m = jl::fs::stream::flag::READ | jl::fs::stream::flag::TEXT;
247 return detail::read_file<m>(filename, pp_dst, p_size);
237 248 } }
238 249 [[nodiscard]] inline bool jl::fs:: [[nodiscard]] inline bool jl::fs::
239 250 write_file(const char *filename, const uint8_t *p_src, uint64_t size) { write_file(const char *filename, const uint8_t *p_src, uint64_t size) {
240 jl::fs::stream file;
241 auto f = jl::fs::stream::flag::WRITE | jl::fs::stream::flag::CLEAN;
251 stream file;
252 stream::mask f = jl::fs::stream::flag::WRITE | jl::fs::stream::flag::CLEAN;
242 253 if (not file.open_file(filename, f)) if (not file.open_file(filename, f))
243 254 return false; return false;
244 255 bool res = file.write_bytes(p_src, size) == size; bool res = file.write_bytes(p_src, size) == size;
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/Jackalope/jlib

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/Jackalope/jlib

Clone this repository using git:
git clone git://git.rocketgit.com/user/Jackalope/jlib

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main