utf-conv.h 1.15 KB
Newer Older
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
3 4 5 6
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
7 8
#ifndef INCLUDE_git_utfconv_h__
#define INCLUDE_git_utfconv_h__
9 10

#include <wchar.h>
11
#include "common.h"
12

13
/* Maximum characters in a Windows path plus one for NUL byte */
14
#define GIT_WIN_PATH_UTF16 (260 + 1)
15 16

/* Maximum bytes necessary to convert a full-length UTF16 path to UTF8 */
17
#define GIT_WIN_PATH_UTF8  (260 * 4 + 1)
18

19
typedef wchar_t git_win32_path[GIT_WIN_PATH_UTF16];
20

21 22
typedef char git_win32_path_as_utf8[GIT_WIN_PATH_UTF8];

23
/* dest_size is the size of dest in wchar_t's */
24
int git__utf8_to_16(wchar_t * dest, size_t dest_size, const char *src);
25
/* dest_size is the size of dest in char's */
26
int git__utf16_to_8(char *dest, size_t dest_size, const wchar_t *src);
27

28
GIT_INLINE(int) git_win32_path_from_c(git_win32_path dest, const char *src)
29 30 31 32
{
	return git__utf8_to_16(dest, GIT_WIN_PATH_UTF16, src);
}

33
GIT_INLINE(int) git_win32_path_to_c(git_win32_path_as_utf8 dest, const wchar_t *src)
34 35 36
{
	return git__utf16_to_8(dest, GIT_WIN_PATH_UTF8, src);
}
37

38
#endif