Skip to content

Commit

Permalink
* lftp_tinfo.cc: fixed termcap coredump.
Browse files Browse the repository at this point in the history
  • Loading branch information
lavv17 committed Aug 30, 2012
1 parent cf34703 commit 3c895bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/ChangeLog
@@ -1,3 +1,7 @@
2012-08-30 Alexander V. Lukyanov <lav@yars.free.net>

* lftp_tinfo.cc: fixed termcap coredump.

2012-08-27 Alexander V. Lukyanov <lav@yars.free.net>

* DHT.cc, DHT.h: add rate limit; improve FindNodes by checking
Expand Down
23 changes: 14 additions & 9 deletions src/lftp_tinfo.cc
Expand Up @@ -40,32 +40,37 @@ extern "C" {
# include <termcap.h>
#endif
}

#include <stdlib.h>
#include "lftp_tinfo.h"

#if defined(HAVE_TIGETSTR)
static bool terminfo_ok = true;
static void init_terminfo()
{
static bool initted = false;
if(initted) return;
initted = true;

#if defined(HAVE_TIGETSTR)
int errret=0;
if(setupterm(NULL, 1, &errret) == ERR)
terminfo_ok = false;
}
#elif defined(HAVE_TGETSTR)
static char buf[2048];
if(tgetent(buf,getenv("TERM")) == -1)
terminfo_ok = false;
#endif
}

const char *get_string_term_cap(const char *terminfo_cap, const char *tcap_cap)
{
#if defined(HAVE_TIGETSTR)
init_terminfo();
if(terminfo_ok) {
/* Cast to work around missing const def in some ncurses installations: */
const char *ret = tigetstr(const_cast<char *>(terminfo_cap));
if(ret && ret != (char *)-1) return ret;
}
if(!terminfo_ok)
return 0;

#if defined(HAVE_TIGETSTR)
/* Cast to work around missing const def in some ncurses installations: */
const char *ret = tigetstr(const_cast<char *>(terminfo_cap));
if(ret && ret != (char *)-1) return ret;
#elif defined(HAVE_TGETSTR)
const char *ret = tgetstr(const_cast<char *>(tcap_cap), 0);
if(ret && ret != (const char *)-1)
Expand Down

0 comments on commit 3c895bb

Please sign in to comment.