static int make_db_path(char *dst, const char *src, unsigned limit) { int rc = -1; const char *top = _nc_tic_dir(0); if (src == top || _nc_is_abs_path(src)) { if (strlen(src) + 1 <= limit) { (void) strlcpy(dst, src, limit); rc = 0; } } else { if (strlen(top) + strlen(src) + 2 <= limit) { (void) snprintf(dst, limit, "%s/%s", top, src); rc = 0; } } #if USE_HASHED_DB if (rc == 0) { if (_nc_is_dir_path(dst)) { rc = -1; } else { unsigned have = strlen(dst); if (have > 3 && strcmp(dst + have - 3, DBM_SUFFIX)) { if (have + 3 <= limit) strlcat(dst, DBM_SUFFIX, limit); else rc = -1; } } } #endif return rc; }
static int make_db_path(char *dst, const char *src, size_t limit) { int rc = -1; const char *top = _nc_tic_dir(0); if (src == top || _nc_is_abs_path(src)) { if (strlen(src) + 1 <= limit) { _nc_STRCPY(dst, src, limit); rc = 0; } } else { if (strlen(top) + strlen(src) + 2 <= limit) { _nc_SPRINTF(dst, _nc_SLIMIT(limit) "%s/%s", top, src); rc = 0; } } #if USE_HASHED_DB if (rc == 0) { static const char suffix[] = DBM_SUFFIX; size_t have = strlen(dst); size_t need = strlen(suffix); if (have > need && strcmp(dst + (int) (have - need), suffix)) { if (have + need <= limit) { _nc_STRCAT(dst, suffix, limit); } else { rc = -1; } } else if (_nc_is_dir_path(dst)) { rc = -1; } } #endif return rc; }
static int make_db_path(char *dst, const char *src, unsigned limit) { int rc = -1; const char *top = _nc_tic_dir(0); if (src == top || _nc_is_abs_path(src)) { if (strlen(src) + 1 <= limit) { (void) strcpy(dst, src); rc = 0; } } else { if (strlen(top) + strlen(src) + 2 <= limit) { (void) sprintf(dst, "%s/%s", top, src); rc = 0; } } #if USE_HASHED_DB if (rc == 0) { if (_nc_is_dir_path(dst)) { rc = -1; } else { static const char suffix[] = DBM_SUFFIX; unsigned have = strlen(dst); unsigned need = strlen(suffix); if (have > need && strcmp(dst + have - need, suffix)) { if (have + need <= limit) strcat(dst, suffix); else rc = -1; } } } #endif return rc; }
/* * Figure out what kind of terminal we're dealing with, and then read in * its termcap entry. */ static const char * get_termcap_entry(char *userarg) { int errret; char *p; const char *ttype; #if HAVE_GETTTYNAM struct ttyent *t; #else FILE *fp; #endif char *ttypath; if (userarg) { ttype = userarg; goto found; } /* Try the environment. */ if ((ttype = getenv("TERM")) != 0) goto map; if ((ttypath = ttyname(STDERR_FILENO)) != 0) { p = _nc_basename(ttypath); #if HAVE_GETTTYNAM /* * We have the 4.3BSD library call getttynam(3); that means * there's an /etc/ttys to look up device-to-type mappings in. * Try ttyname(3); check for dialup or other mapping. */ if ((t = getttynam(p))) { ttype = t->ty_type; goto map; } #else if ((fp = fopen("/etc/ttytype", "r")) != 0 || (fp = fopen("/etc/ttys", "r")) != 0) { char buffer[BUFSIZ]; char *s, *t, *d; while (fgets(buffer, sizeof(buffer), fp) != NULL) { for (s = buffer, t = d = 0; *s; s++) { if (isspace(UChar(*s))) *s = '\0'; else if (t == 0) t = s; else if (d == 0 && s != buffer && s[-1] == '\0') d = s; } if (t != 0 && d != 0 && !strcmp(d, p)) { ttype = strdup(t); fclose(fp); goto map; } } fclose(fp); } #endif /* HAVE_GETTTYNAM */ } /* If still undefined, use "unknown". */ ttype = "unknown"; map:ttype = mapped(ttype); /* * If not a path, remove TERMCAP from the environment so we get a * real entry from /etc/termcap. This prevents us from being fooled * by out of date stuff in the environment. */ found:if ((p = getenv("TERMCAP")) != 0 && !_nc_is_abs_path(p)) { /* 'unsetenv("TERMCAP")' is not portable. * The 'environ' array is better. */ int n; for (n = 0; environ[n] != 0; n++) { if (!strncmp("TERMCAP=", environ[n], 8)) { while ((environ[n] = environ[n + 1]) != 0) { n++; } break; } } } /* * ttype now contains a pointer to the type of the terminal. * If the first character is '?', ask the user. */ if (ttype[0] == '?') { if (ttype[1] != '\0') ttype = askuser(ttype + 1); else ttype = askuser(0); } /* Find the terminfo entry. If it doesn't exist, ask the user. */ while (setupterm((NCURSES_CONST char *) ttype, STDOUT_FILENO, &errret) != OK) { if (errret == 0) { (void) fprintf(stderr, "%s: unknown terminal type %s\n", _nc_progname, ttype); ttype = 0; } else { (void) fprintf(stderr, "%s: can't initialize terminal type %s (error %d)\n", _nc_progname, ttype, errret); ttype = 0; } ttype = askuser(ttype); } #if BROKEN_LINKER tgetflag("am"); /* force lib_termcap.o to be linked for 'ospeed' */ #endif return (ttype); }