コード例 #1
0
ファイル: write_entry.c プロジェクト: ajinkya93/OpenBSD
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;
}
コード例 #2
0
ファイル: write_entry.c プロジェクト: 2asoft/freebsd
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;
}
コード例 #3
0
ファイル: toe.c プロジェクト: AaronDP/ncurses-5.9_adbshell
static bool
is_database(const char *path)
{
    bool result = FALSE;
#if USE_DATABASE
    if (_nc_is_dir_path(path) && access(path, R_OK | X_OK) == 0) {
	result = TRUE;
    }
#endif
#if USE_TERMCAP
    if (_nc_is_file_path(path) && access(path, R_OK) == 0) {
	result = TRUE;
    }
#endif
#if USE_HASHED_DB
    if (!result) {
	char filename[PATH_MAX];
	if (_nc_is_file_path(path) && access(path, R_OK) == 0) {
	    result = TRUE;
	} else if (make_db_name(filename, path, sizeof(filename))) {
	    if (_nc_is_file_path(filename) && access(filename, R_OK) == 0) {
		result = TRUE;
	    }
	}
    }
#endif
    return result;
}
コード例 #4
0
ファイル: lib_trace.c プロジェクト: StarchLinux/ncurses
trace(const unsigned int tracelevel)
{
    if ((TraceFP == 0) && tracelevel) {
	const char *mode = _nc_globals.init_trace ? "ab" : "wb";

	if (TracePath[0] == '\0') {
	    int size = sizeof(TracePath) - 12;
	    if (getcwd(TracePath, size) == 0) {
		perror("curses: Can't get working directory");
		exit(EXIT_FAILURE);
	    }
	    TracePath[size] = '\0';
	    assert(strlen(TracePath) <= size);
	    strlcat(TracePath, "/trace", sizeof(TracePath));
	    if (_nc_is_dir_path(TracePath)) {
		strlcat(TracePath, ".log", sizeof(TracePath));
	    }
	}

	_nc_globals.init_trace = TRUE;
	_nc_tracing = tracelevel;
	if (_nc_access(TracePath, W_OK) < 0
	    || (TraceFP = fopen(TracePath, mode)) == 0) {
	    perror("curses: Can't open 'trace' file");
	    exit(EXIT_FAILURE);
	}
	/* Try to set line-buffered mode, or (failing that) unbuffered,
	 * so that the trace-output gets flushed automatically at the
	 * end of each line.  This is useful in case the program dies. 
	 */
#if HAVE_SETVBUF		/* ANSI */
	(void) setvbuf(TraceFP, (char *) 0, _IOLBF, 0);
#elif HAVE_SETBUF		/* POSIX */
	(void) setbuffer(TraceFP, (char *) 0);
#endif
	_tracef("TRACING NCURSES version %s.%d (tracelevel=%#x)",
		NCURSES_VERSION,
		NCURSES_VERSION_PATCH,
		tracelevel);
    } else if (tracelevel == 0) {
	if (TraceFP != 0) {
	    fclose(TraceFP);
	    TraceFP = 0;
	}
	_nc_tracing = tracelevel;
    } else if (_nc_tracing != tracelevel) {
	_nc_tracing = tracelevel;
	_tracef("tracelevel=%#x", tracelevel);
    }
}
コード例 #5
0
ファイル: write_entry.c プロジェクト: jsjohnst/node-ncurses
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;
}