Blame src/win32/path_w32.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_git_path_w32_h__
Packit Service 20376f
#define INCLUDE_git_path_w32_h__
Packit Service 20376f
Packit Service 20376f
#include "common.h"
Packit Service 20376f
#include "vector.h"
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * Provides a large enough buffer to support Windows paths:  MAX_PATH is
Packit Service 20376f
 * 260, corresponding to a maximum path length of 259 characters plus a
Packit Service 20376f
 * NULL terminator.  Prefixing with "\\?\" adds 4 characters, but if the
Packit Service 20376f
 * original was a UNC path, then we turn "\\server\share" into
Packit Service 20376f
 * "\\?\UNC\server\share".  So we replace the first two characters with
Packit Service 20376f
 * 8 characters, a net gain of 6, so the maximum length is MAX_PATH+6.
Packit Service 20376f
 */
Packit Service 20376f
#define GIT_WIN_PATH_UTF16		MAX_PATH+6
Packit Service 20376f
Packit Service 20376f
/* Maximum size of a UTF-8 Win32 path.  We remove the "\\?\" or "\\?\UNC\"
Packit Service 20376f
 * prefixes for presentation, bringing us back to 259 (non-NULL)
Packit Service 20376f
 * characters.  UTF-8 does have 4-byte sequences, but they are encoded in
Packit Service 20376f
 * UTF-16 using surrogate pairs, which takes up the space of two characters.
Packit Service 20376f
 * Two characters in the range U+0800 -> U+FFFF take up more space in UTF-8
Packit Service 20376f
 * (6 bytes) than one surrogate pair (4 bytes).
Packit Service 20376f
 */
Packit Service 20376f
#define GIT_WIN_PATH_UTF8		(259 * 3 + 1)
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * The length of a Windows "shortname", for 8.3 compatibility.
Packit Service 20376f
 */
Packit Service 20376f
#define GIT_WIN_PATH_SHORTNAME  13
Packit Service 20376f
Packit Service 20376f
/* Win32 path types */
Packit Service 20376f
typedef wchar_t git_win32_path[GIT_WIN_PATH_UTF16];
Packit Service 20376f
typedef char git_win32_utf8_path[GIT_WIN_PATH_UTF8];
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create a Win32 path (in UCS-2 format) from a UTF-8 string.
Packit Service 20376f
 *
Packit Service 20376f
 * @param dest The buffer to receive the wide string.
Packit Service 20376f
 * @param src The UTF-8 string to convert.
Packit Service 20376f
 * @return The length of the wide string, in characters (not counting the NULL terminator), or < 0 for failure
Packit Service 20376f
 */
Packit Service 20376f
extern int git_win32_path_from_utf8(git_win32_path dest, const char *src);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Canonicalize a Win32 UCS-2 path so that it is suitable for delivery to the
Packit Service 20376f
 * Win32 APIs: remove multiple directory separators, squashing to a single one,
Packit Service 20376f
 * strip trailing directory separators, ensure directory separators are all
Packit Service 20376f
 * canonical (always backslashes, never forward slashes) and process any
Packit Service 20376f
 * directory entries of '.' or '..'.
Packit Service 20376f
 *
Packit Service 20376f
 * This processes the buffer in place.
Packit Service 20376f
 *
Packit Service 20376f
 * @param path The buffer to process
Packit Service 20376f
 * @return The new length of the buffer, in wchar_t's (not counting the NULL terminator)
Packit Service 20376f
 */
Packit Service 20376f
extern int git_win32_path_canonicalize(git_win32_path path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create an internal format (posix-style) UTF-8 path from a Win32 UCS-2 path.
Packit Service 20376f
 *
Packit Service 20376f
 * @param dest The buffer to receive the UTF-8 string.
Packit Service 20376f
 * @param src The wide string to convert.
Packit Service 20376f
 * @return The length of the UTF-8 string, in bytes (not counting the NULL terminator), or < 0 for failure
Packit Service 20376f
 */
Packit Service 20376f
extern int git_win32_path_to_utf8(git_win32_utf8_path dest, const wchar_t *src);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the short name for the terminal path component in the given path.
Packit Service 20376f
 * For example, given "C:\Foo\Bar\Asdf.txt", this will return the short name
Packit Service 20376f
 * for the file "Asdf.txt".
Packit Service 20376f
 *
Packit Service 20376f
 * @param path The given path in UTF-8
Packit Service 20376f
 * @return The name of the shortname for the given path
Packit Service 20376f
 */
Packit Service 20376f
extern char *git_win32_path_8dot3_name(const char *path);
Packit Service 20376f
Packit Service 20376f
extern int git_win32_path_readlink_w(git_win32_path dest, const git_win32_path path);
Packit Service 20376f
Packit Service 20376f
#endif