Blame src/sysdir.h

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