Blame src/sysdir.h

Packit ae9e2a
/*
Packit ae9e2a
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit ae9e2a
 *
Packit ae9e2a
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit ae9e2a
 * a Linking Exception. For full terms see the included COPYING file.
Packit ae9e2a
 */
Packit ae9e2a
#ifndef INCLUDE_sysdir_h__
Packit ae9e2a
#define INCLUDE_sysdir_h__
Packit ae9e2a
Packit ae9e2a
#include "common.h"
Packit ae9e2a
#include "posix.h"
Packit ae9e2a
#include "buffer.h"
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Find a "global" file (i.e. one in a user's home directory).
Packit ae9e2a
 *
Packit ae9e2a
 * @param path buffer to write the full path into
Packit ae9e2a
 * @param filename name of file to find in the home directory
Packit ae9e2a
 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
Packit ae9e2a
 */
Packit ae9e2a
extern int git_sysdir_find_global_file(git_buf *path, const char *filename);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Find an "XDG" file (i.e. one in user's XDG config path).
Packit ae9e2a
 *
Packit ae9e2a
 * @param path buffer to write the full path into
Packit ae9e2a
 * @param filename name of file to find in the home directory
Packit ae9e2a
 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
Packit ae9e2a
 */
Packit ae9e2a
extern int git_sysdir_find_xdg_file(git_buf *path, const char *filename);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Find a "system" file (i.e. one shared for all users of the system).
Packit ae9e2a
 *
Packit ae9e2a
 * @param path buffer to write the full path into
Packit ae9e2a
 * @param filename name of file to find in the home directory
Packit ae9e2a
 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
Packit ae9e2a
 */
Packit ae9e2a
extern int git_sysdir_find_system_file(git_buf *path, const char *filename);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Find a "ProgramData" file (i.e. one in %PROGRAMDATA%)
Packit ae9e2a
 *
Packit ae9e2a
 * @param path buffer to write the full path into
Packit ae9e2a
 * @param filename name of file to find in the ProgramData directory
Packit ae9e2a
 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
Packit ae9e2a
 */
Packit ae9e2a
extern int git_sysdir_find_programdata_file(git_buf *path, const char *filename);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Find template directory.
Packit ae9e2a
 *
Packit ae9e2a
 * @param path buffer to write the full path into
Packit ae9e2a
 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
Packit ae9e2a
 */
Packit ae9e2a
extern int git_sysdir_find_template_dir(git_buf *path);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Expand the name of a "global" file (i.e. one in a user's home
Packit ae9e2a
 * directory).  Unlike `find_global_file` (above), this makes no
Packit ae9e2a
 * attempt to check for the existence of the file, and is useful if
Packit ae9e2a
 * you want the full path regardless of existence.
Packit ae9e2a
 *
Packit ae9e2a
 * @param path buffer to write the full path into
Packit ae9e2a
 * @param filename name of file in the home directory
Packit ae9e2a
 * @return 0 on success or -1 on error
Packit ae9e2a
 */
Packit ae9e2a
extern int git_sysdir_expand_global_file(git_buf *path, const char *filename);
Packit ae9e2a
Packit ae9e2a
typedef enum {
Packit ae9e2a
	GIT_SYSDIR_SYSTEM = 0,
Packit ae9e2a
	GIT_SYSDIR_GLOBAL = 1,
Packit ae9e2a
	GIT_SYSDIR_XDG    = 2,
Packit ae9e2a
	GIT_SYSDIR_PROGRAMDATA = 3,
Packit ae9e2a
	GIT_SYSDIR_TEMPLATE = 4,
Packit ae9e2a
	GIT_SYSDIR__MAX   = 5,
Packit ae9e2a
} git_sysdir_t;
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Configures global data for configuration file search paths.
Packit ae9e2a
 *
Packit ae9e2a
 * @return 0 on success, <0 on failure
Packit ae9e2a
 */
Packit ae9e2a
extern int git_sysdir_global_init(void);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the search path for global/system/xdg files
Packit ae9e2a
 *
Packit ae9e2a
 * @param out pointer to git_buf containing search path
Packit ae9e2a
 * @param which which list of paths to return
Packit ae9e2a
 * @return 0 on success, <0 on failure
Packit ae9e2a
 */
Packit ae9e2a
extern int git_sysdir_get(const git_buf **out, git_sysdir_t which);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get search path into a preallocated buffer
Packit ae9e2a
 *
Packit ae9e2a
 * @param out String buffer to write into
Packit ae9e2a
 * @param outlen Size of string buffer
Packit ae9e2a
 * @param which Which search path to return
Packit ae9e2a
 * @return 0 on success, GIT_EBUFS if out is too small, <0 on other failure
Packit ae9e2a
 */
Packit ae9e2a
Packit ae9e2a
extern int git_sysdir_get_str(char *out, size_t outlen, git_sysdir_t which);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Set search paths for global/system/xdg files
Packit ae9e2a
 *
Packit ae9e2a
 * The first occurrence of the magic string "$PATH" in the new value will
Packit ae9e2a
 * be replaced with the old value of the search path.
Packit ae9e2a
 *
Packit ae9e2a
 * @param which Which search path to modify
Packit ae9e2a
 * @param paths New search path (separated by GIT_PATH_LIST_SEPARATOR)
Packit ae9e2a
 * @return 0 on success, <0 on failure (allocation error)
Packit ae9e2a
 */
Packit ae9e2a
extern int git_sysdir_set(git_sysdir_t which, const char *paths);
Packit ae9e2a
Packit ae9e2a
#endif /* INCLUDE_sysdir_h__ */