For buffer, no memory has to be allocated when using the GNU version of termcap. This is what we can assume under Linux! Otherwise, you'll have to allocate 2048 Bytes. (Formerly, buffer only needed to be 1024 Bytes, but the size has doubled).
tgetent(...) returns 1 on success and 0 when the database is found but has no entry for TERM. Other errors will return different values.
The following example should explain how to use tgetent(...):
#define buffer 0
/* all right, we have the entry */
/* uups, something wrong with TERM
* check termtype first, then termcap database
/* huuu, fatal error */
By, default termcap uses /etc/termcap/ as the database. If the environment variable TERMCAP is set, with $HOME/mytermcap for instance, all functions will use instead of /etc/termcap. With no leading slash in TERMCAP, the defined value is used as a name for a terminal.