retrieve the specified terminal entry and return it in `entbuf' */
| 60 | |
| 61 | /* retrieve the specified terminal entry and return it in `entbuf' */ |
| 62 | int |
| 63 | tgetent(char *entbuf, /* size must be at least [TCBUFSIZ] */ |
| 64 | const char *term) |
| 65 | { |
| 66 | int result; |
| 67 | FILE *fp; |
| 68 | char *tc = getenv("TERMCAP"); |
| 69 | |
| 70 | tc_entry = entbuf; |
| 71 | if (!entbuf || !term) |
| 72 | return -1; |
| 73 | /* if ${TERMCAP} is found as a file, it's not an inline termcap entry */ |
| 74 | if ((fp = fopen(tc ? tc : TERMCAP, "r")) != 0) |
| 75 | tc = 0; |
| 76 | /* if ${TERMCAP} isn't a file and `term' matches ${TERM}, use ${TERMCAP} |
| 77 | */ |
| 78 | if (tc) { |
| 79 | char *tm = getenv("TERM"); |
| 80 | if (tm && strcmp(tm, term) == 0) |
| 81 | return tc_store(term, tc); |
| 82 | fp = fopen(TERMCAP, "r"); |
| 83 | } |
| 84 | /* otherwise, look `term' up in the file */ |
| 85 | if (fp) { |
| 86 | char wrkbuf[TCBUFSIZ]; |
| 87 | tc = tc_find(fp, term, wrkbuf, (int) (sizeof wrkbuf - strlen(term))); |
| 88 | result = tc_store(term, tc); |
| 89 | (void) fclose(fp); |
| 90 | } else { |
| 91 | result = -1; |
| 92 | } |
| 93 | return result; |
| 94 | } |
| 95 | |
| 96 | /* copy the entry into the output buffer */ |
| 97 | static int |
no test coverage detected