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