:: [DNG] Icerbergs aren't small just b…
Top Pagina
Delete this message
Reply to this message
Auteur: Rainer Weikusat
Datum:  
Aan: dng
Onderwerp: [DNG] Icerbergs aren't small just because they're mostly underwater (was: "Common knowledge?"-question)
KatolaZ <katolaz@???> writes:

[...]

> I still don't see the need for an internal buffer to print out a
> formatted string, to be honest :)


Everything in code can always be implemented in a number of different
ways, hence, whatever the code ends up doing is "not really needed" ---
it could have achieved the same in a different way.

In this case, the function is part of a 79 lines program whose main
looks like this:

int main(int argc, char **argv)
{
    char const *name;
    int status;


    name = get_name(*argv);
    openlog(name, LOG_PID | LOG_PERROR, LOG_DAEMON);
    if (argc < 3) usage();


    print_start(name, argv[1]);


    switch (fork()) {
    case -1:
    die(__func__, "fork");


    case 0:
    execvp(argv[2], argv + 2);


    syslog(LOG_ERR, "main: execvp: %m(%d)", errno);
    _exit(1);
    }


    wait(&status);
    print_stop(status);


    return 0;
}


and whose purpose is to enable me to write

starting "unleashed VPN" \
    daemon -n chdir / monitor -n qvpn ssh-vpn mes-pgsql 5000 unleashed unleashed4


in an init script to get a 'start: ok (or failed)' message printed to
file descriptor 2 with having to put two printf invocation around the
start command. And in the context of that, using stdio for the sole
purpose of performing a trivial string formatting operation seemed very
inappropriate --- that's new-fangled, ill-thought out stuff supposed to
make UNIX(*) easier to use by moron^WUCB students and who really needs
that?

The program also contains a very nice example of why the post-increment
operators is useful (and I means 'useful', not 'common because of
mindless copying of example code'):

static char const *get_name(char const *arg0)
{
    char const *n, *r;


    n = r = arg0;
    while (*r) if (*r++ == '/') n = r;
    return n;
}