Back to index

tetex-bin  3.0
Functions
lib_print.c File Reference
#include <curses.priv.h>
#include <term.h>

Go to the source code of this file.

Functions

 mcprint (char *data, int len)

Function Documentation

mcprint ( char *  data,
int  len 
)

Definition at line 41 of file lib_print.c.

{
    char *mybuf, *switchon;
    size_t onsize, offsize, res;

    errno = 0;
    if (!cur_term || (!prtr_non && (!prtr_on || !prtr_off))) {
       errno = ENODEV;
       return (ERR);
    }

    if (prtr_non) {
       switchon = tparm(prtr_non, len);
       onsize = strlen(switchon);
       offsize = 0;
    } else {
       switchon = prtr_on;
       onsize = strlen(prtr_on);
       offsize = strlen(prtr_off);
    }

    if (switchon == 0
       || (mybuf = typeMalloc(char, onsize + len + offsize + 1)) == 0) {
       errno = ENOMEM;
       return (ERR);
    }

    (void) strcpy(mybuf, switchon);
    memcpy(mybuf + onsize, data, (unsigned) len);
    if (offsize)
       (void) strcpy(mybuf + onsize + len, prtr_off);

    /*
     * We're relying on the atomicity of UNIX writes here.  The
     * danger is that output from a refresh() might get interspersed
     * with the printer data after the write call returns but before the
     * data has actually been shipped to the terminal.  If the write(2)
     * operation is truly atomic we're protected from this.
     */
    res = write(cur_term->Filedes, mybuf, onsize + len + offsize);

    /*
     * By giving up our scheduler slot here we increase the odds that the
     * kernel will ship the contiguous clist items from the last write
     * immediately.
     */
    (void) sleep(0);

    free(mybuf);
    return (res);
}

Here is the call graph for this function: