Bash Tee function in C code

Thanks for the info. :slight_smile:

I need to explain this better.

In my experience, programs rarely have one exit point. Meaning:

malloc needed varibles
code
free variables.
exit to command line.

Functions can be this simple. Main-line code rarely is this simple.

If you add checking for errors of various kinds:
filename missing, file won’t read or write, won’t open or close.

maloc variables
check open file successful, if error exit
check read file, if error exit.
check write file, if error exit
close file, if error exit.
free variables.

That’s four exit points before the memory is freed. I’ve had to write the code so it flows into the exit at the end. That’s is NOT simple. Else, create a function to free all the variables at each exit point.

Add up all the exits points in something as complex as scanvirus as c code. This makes for a very complex structure. :stuck_out_tongue:

PS, I can do linked lists of various types. I choose not to use them for simplicity.

I’ve used the function ‘sizeof(variable)’ for memory allocation.

Sorry, but I do not understand you here at all. What e.g. is a “shortcut bash command”. And what is a “system command”.

I get the idea that we are going off post. My first answer here had to purposes:

  • to point to the fact that we all use “lingo” in ICT, specially here in discussing shell features. Most of these lingo words have a meaning that is defined in e.g. the man page of the shell. One should use those terms in the meaning that is defined in this context, else you will have confusion at all sites;
  • speclaly in this case, the difference if it is a shell-builtin or a separate tool/program/binary is for you the difference of where to find the coding that you may want to use again in your own program. But that went completely wrong. Instead of saying: “aha, better look in the source-code of tee then in the source code of bash”, you stated that it is all one same bunch of words and that those that lay value in making a difference between a program, an alias, or a builtin are just pedantic for the case of being pedantic.

Oh dear, the “spaghetti code” versus “structured code” discussion:

  • Yes, C doesn’t have the concept of “constructors” and “destructors” – as C++ does …
  • Yes, C is rather similar to assembler in that, one has to ensure that one cleans up before one exits …

There’s no clear answer to this issue – it’s purely a matter of taste and, personal preferences and, personal abilities and, the capabilities of the tools being used …