File Handling in Linux 9 Supplying the envelope explicitly

The recipients of a message can simply be specified on the command line. This has the drawback that mail addresses can contain characters that give system() and popen() considerable grief, such as single quotes, quoted strings etc. Passing these constructs successfully through shell interpretation presents pitfalls. (One can do it by replacing any single quotes by the sequence single-quote backslash single-quote single-quote, then surrounding the entire address with single quotes. Ugly, huh?)
Some of this unpleasantness can be avoided by eschewing the use of system() or popen(), and resorting to fork() and exec() directly. This is sometimes necessary in any event; for example, user-installed handlers for SIGCHLD will usually break pclose() to a greater or lesser extent.
Here's an example:
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sysexits.h>
/* #include <paths.h> if you have it */
#define _PATH_SENDMAIL "/usr/lib/sendmail"
 To Look for similar posts on File handling in Linux explore the following links from the same blog as well.


Post a Comment