I do not have a lot of time to write the shorter and most efficient on first time.
Also, whole program is not mine. I add functions that must rely on existing ones
With that in mind, what is so "stupid" in code post 1?
Those constants are used everywhere and should be replaced by a constant symbol. Too easy to mess it up by accident.
Use of strcat() is somewhat dangerous if you can't prove that you won't overflow. And even if you can, during maintenance, this can still be a problem and bite you in the ass later.
The way you use suffix increment would be better as prefix increment (though the compiler would probably optimize it as a prefix).
There are probably other things, but I only skimmed the code.
Thanks,
Yes, then there are habits about the prefix in increment...
strcat, in this case, it is really controlled as source is constant and target enough big. But using strncat is obviously a better option
The constants: I always grep the source to avoid any issue, but you are right
Now about those LLU
Total_Size, Used_Size and Free_Size are unsigned long long integers
They contain partition size in bytes calculated through statfs or by reading and parsing /proc/partitions
For some reasons, I keep them in bytes. Inside this specific function, they are converted into Mb (1024 * 1024 = 1048576)
Since Total_Size... are LLU, right element should be specified to the same type
Now, as alternative to converting ull to integer, I could either define a new ull to hold the Total_Size/(1024*1024) or keep repeating same cumbersome calculation through the code
I did not see the need to define 3 new ull on the stack for this, so I went with integer as it is far than enough for what the function needs to display