]> git.proxmox.com Git - libgit2.git/blob - src/win32/path_w32.h
New upstream version 1.3.0+dfsg.1
[libgit2.git] / src / win32 / path_w32.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7 #ifndef INCLUDE_win32_path_w32_h__
8 #define INCLUDE_win32_path_w32_h__
9
10 #include "common.h"
11
12 /**
13 * Create a Win32 path (in UCS-2 format) from a UTF-8 string. If the given
14 * path is relative, then it will be turned into an absolute path by having
15 * the current working directory prepended.
16 *
17 * @param dest The buffer to receive the wide string.
18 * @param src The UTF-8 string to convert.
19 * @return The length of the wide string, in characters (not counting the NULL terminator), or < 0 for failure
20 */
21 extern int git_win32_path_from_utf8(git_win32_path dest, const char *src);
22
23 /**
24 * Create a Win32 path (in UCS-2 format) from a UTF-8 string. If the given
25 * path is relative, then it will not be turned into an absolute path.
26 *
27 * @param dest The buffer to receive the wide string.
28 * @param src The UTF-8 string to convert.
29 * @return The length of the wide string, in characters (not counting the NULL terminator), or < 0 for failure
30 */
31 extern int git_win32_path_relative_from_utf8(git_win32_path dest, const char *src);
32
33 /**
34 * Canonicalize a Win32 UCS-2 path so that it is suitable for delivery to the
35 * Win32 APIs: remove multiple directory separators, squashing to a single one,
36 * strip trailing directory separators, ensure directory separators are all
37 * canonical (always backslashes, never forward slashes) and process any
38 * directory entries of '.' or '..'.
39 *
40 * Note that this is intended to be used on absolute Windows paths, those
41 * that start with `C:\`, `\\server\share`, `\\?\`, etc.
42 *
43 * This processes the buffer in place.
44 *
45 * @param path The buffer to process
46 * @return The new length of the buffer, in wchar_t's (not counting the NULL terminator)
47 */
48 extern int git_win32_path_canonicalize(git_win32_path path);
49
50 /**
51 * Create an internal format (posix-style) UTF-8 path from a Win32 UCS-2 path.
52 *
53 * @param dest The buffer to receive the UTF-8 string.
54 * @param src The wide string to convert.
55 * @return The length of the UTF-8 string, in bytes (not counting the NULL terminator), or < 0 for failure
56 */
57 extern int git_win32_path_to_utf8(git_win32_utf8_path dest, const wchar_t *src);
58
59 /**
60 * Get the short name for the terminal path component in the given path.
61 * For example, given "C:\Foo\Bar\Asdf.txt", this will return the short name
62 * for the file "Asdf.txt".
63 *
64 * @param path The given path in UTF-8
65 * @return The name of the shortname for the given path
66 */
67 extern char *git_win32_path_8dot3_name(const char *path);
68
69 extern int git_win32_path_readlink_w(git_win32_path dest, const git_win32_path path);
70
71 /**
72 * Removes any trailing backslashes from a path, except in the case of a drive
73 * letter path (C:\, D:\, etc.). This function cannot fail.
74 *
75 * @param path The path which should be trimmed.
76 * @return The length of the modified string (<= the input length)
77 */
78 size_t git_win32_path_trim_end(wchar_t *str, size_t len);
79
80 /**
81 * Removes any of the following namespace prefixes from a path,
82 * if found: "\??\", "\\?\", "\\?\UNC\". This function cannot fail.
83 *
84 * @param path The path which should be converted.
85 * @return The length of the modified string (<= the input length)
86 */
87 size_t git_win32_path_remove_namespace(wchar_t *str, size_t len);
88
89 #endif