I actually have a two part question. I'm trying to develop a script that will recurse through a directory tree and collect the regular file sizes to give me the total size of the tree. I've already gotten st_size from sys/stat.h to work via intmax_t from stdint.h to work in another script, but for whatever reason the only way it will produce a correct, non-zero result in the current app is to include it in a printf statement -- ie, printf ("%d", (intmax_t)statstruct.st_size) works where "bytes = (intmax_t)statstruct.st_size" does not (bizarrely), meaning I cannot manipulate or collect an integer.
I thought of using the final return value of a seperate program (that already works) but of course system() returns a pid, not the actual return value. So my first question is: Can I do that somehow anyway (without using a pipe)?
My other question: is there a better way than st_size/intmax_t to get a file size? And why does it work so strangely?