#catch - A simple fetch in C

158 messages Β· Page 1 of 1 (latest)

twilit perch
#

I made a simple fetch in C for GNU+Linux systems.
It was designed to be easy to understand, fast, and memory safe.
I would love feedback on it

twilit perch
#

@tardy wyvern Its this

#

according to valgrind, it is memory safe

#

super fast execution

#

its pretty much instant

tardy wyvern
twilit perch
#

I designed it to be divided in functions, each function does 1 thing and is independent from everything else

#

the only exception would be free_character_arr() Which provides a way to free character arrays made by split() in a easy way

tardy wyvern
tardy wyvern
twilit perch
#

Just imagine main() if all that code was merged into it without the functions

tardy wyvern
tardy wyvern
twilit perch
#

speaking of maintainability, catch should be easy to maintain, and add additional code to. A function is responsible for printing out a specific information, so all a dev that wants to contribute to catch just make a function, verify the said function works on their machine and just copy-paste it in

#

at least in theory

tardy wyvern
twilit perch
twilit perch
#

You should try running it on your own machine (If you're on GNU+Linux)

tardy wyvern
# twilit perch no

https://youtu.be/kZ2Nco4-39s

https://github.com/Snaipe/Criterion

Give these a shot and put into your program and see if they catch any bugs πŸ™‚

GitHub

A cross-platform C and C++ unit testing framework for the 21st century - Snaipe/Criterion

tardy wyvern
twilit perch
tardy wyvern
twilit perch
#

I love the heap though

#

the entire split() function returns a heap allocated array which each element is a pointer to a heap allocated character array

tardy wyvern
twilit perch
tardy wyvern
twilit perch
tardy wyvern
twilit perch
#

I understood "Dont use Heap with arduino cuz you will run out of memory due to fragmentation" from that

tardy wyvern
twilit perch
#

or should i continue with my own natural one?

tardy wyvern
twilit perch
twilit perch
#

I just got another idea to jailbreak ChatGPT

twilit perch
#

since the printing function are independent, they eventually become magic for the user, and even the person that wrote it (me)

#

Like seriously, I can just forget about how it works and just print_os() without a care in the world

#

is that good or bad

tardy wyvern
tardy wyvern
twilit perch
twilit perch
#

Its really easy to forget how the functions that print information works

tardy wyvern
tardy wyvern
# twilit perch thats because the program dosen't have to care what `fread()` returns

then you might just want to suppress compiler warning by https://stackoverflow.com/questions/3378560/how-to-disable-gcc-warnings-for-a-few-lines-of-code but i won't recommend it as you're technically outsmarting the compiler at this point πŸ€·β€β™‚οΈ and I would actually do something with what fread() returns e.g. like check any potential errors

twilit perch
#

@tardy wyvern Also, ive been thinking of making a very simple archive tool similar to tar

twilit perch
twilit perch
tardy wyvern
twilit perch
#
    Archive
{------------------------------}
|____________| |_| |______| |_|
   Data         |     |      Terminator (Signals EOF)
                |   Metadata
                Metadata terminator (signals beginning of metadata)```
#

I was thinking of this way to make it work

#

(yes i spent a bunch of time drawing that)

tardy wyvern
twilit perch
#

since a file can have any kind of data, i need terminators that wont get mixed

tardy wyvern
twilit perch
tardy wyvern
twilit perch
#

What about unsigned chars as terminators?

twilit perch
tardy wyvern
twilit perch
tardy wyvern
twilit perch
#

ive got an idea, i should be able to write hexidecimal binary

#

with unsigned chars

twilit perch
tardy wyvern
# twilit perch πŸ’€

Bruh don't πŸ’€ me when your stuff encounters buffer overflow or gets randomly truncated lol

tardy wyvern
twilit perch
tardy wyvern
twilit perch
tardy wyvern
tardy wyvern
twilit perch
tardy wyvern
twilit perch
tardy wyvern
twilit perch
#

for tampering detection, the users are better off using cryptographic methods such as signing

#

first im gonna try to write hexidecimal binary for terminators

tardy wyvern
# twilit perch Im pretty sure any attacker would also change the checksum too

You're basically saying "because an attacker will go to any lengths to do x" that you'll just do the least ideal thing possible and just be done with it; I don't really agree with that mentality but if you want to create a new archive standard where I can just truncate your archive or cause a buffer overflow trivially then ig that's on you πŸ€·β€β™‚οΈ

twilit perch
#

yeah boii

#

I can write hex binary

twilit perch
#

its not a compression standard or anything, Im just putting file data in a big file along with their metadata such as name

#

it isnt rocket science

twilit perch
#

instead of using terminators

twilit perch
#

@tardy wyvern Also, does sizeof(long) change accross machines or is it only a compiler portability thing?

tardy wyvern
twilit perch
#

After that ill make the archive maker

twilit perch
#

@tardy wyvern btw, i made a github repo for Sar

#

im planning on Sar becoming a real thing rather than one for learning

tardy wyvern
twilit perch
#

the data portion is reserved for the file data inside of the archive, it dosent even have a name. Why would i need to do that?

#
  • the size of the data block is defined in the reserved space of the uint64_ts
tardy wyvern
twilit perch
#

it is stored outside of metadata in a reserved portion called archive metadata

tardy wyvern
twilit perch
#

its because its stupidly simple

tardy wyvern
tardy wyvern
twilit perch
#

i sent that emoji to metametadata

tardy wyvern
# twilit perch i sent that emoji to metametadata

So you store different data about each data block, and there can be multiple data blocks, and then the archive metadata includes data about the whole archive including data about the data about each data block? Is this your design and does that make sense?

twilit perch
#

the same structure can be copied over and over again for a archive with many files

#

heck, you can even merge 2 diffirent archive files into a singular one

#

the design very well allows that and shouldn't require extra effort inside the source code

#

merging the archives shouldn't even have to do any processing, you just get arc1 and arc2 and just combine em' without doing anything special

#

you should be able to use DD to combine them too

tardy wyvern
tardy wyvern
twilit perch
twilit perch
twilit perch
#

Its just reserved for explicity defining where stuff is at

#
  • This also means an archive can be any size, up to the 64 bit limit.
#

while also allowing metadata block to be easily resizeable for any purpose, which makes adding new information to the metadata extremely easy

tardy wyvern
twilit perch
twilit perch
#

aand i just completely avoided it

#

guess how i avoided it

#

seriously though, take a guess

tardy wyvern
twilit perch
twilit perch
#

hence the name of the archive project trollcrab

#

i called it "Stupid's Archive" for a reason

#

it implies the author (me) is stupid
it implies it is stupidly easy to use
it implies it is stupidly simple
it implies the code can be understood by someone stupid

#

just like me

twilit perch
#

@tardy wyvern Aye

#

I found a really nice vscode extension