git

Форк
0
/
path-utils.c 
89 строк · 1.8 Кб
1
#include "../../git-compat-util.h"
2
#include "../../environment.h"
3

4
int win32_has_dos_drive_prefix(const char *path)
5
{
6
	int i;
7

8
	/*
9
	 * Does it start with an ASCII letter (i.e. highest bit not set),
10
	 * followed by a colon?
11
	 */
12
	if (!(0x80 & (unsigned char)*path))
13
		return *path && path[1] == ':' ? 2 : 0;
14

15
	/*
16
	 * While drive letters must be letters of the English alphabet, it is
17
	 * possible to assign virtually _any_ Unicode character via `subst` as
18
	 * a drive letter to "virtual drives". Even `1`, or `ä`. Or fun stuff
19
	 * like this:
20
	 *
21
	 *      subst ֍: %USERPROFILE%\Desktop
22
	 */
23
	for (i = 1; i < 4 && (0x80 & (unsigned char)path[i]); i++)
24
		; /* skip first UTF-8 character */
25
	return path[i] == ':' ? i + 1 : 0;
26
}
27

28
int win32_skip_dos_drive_prefix(char **path)
29
{
30
	int ret = has_dos_drive_prefix(*path);
31
	*path += ret;
32
	return ret;
33
}
34

35
int win32_offset_1st_component(const char *path)
36
{
37
	char *pos = (char *)path;
38

39
	/* unc paths */
40
	if (!skip_dos_drive_prefix(&pos) &&
41
			is_dir_sep(pos[0]) && is_dir_sep(pos[1])) {
42
		/* skip server name */
43
		pos = strpbrk(pos + 2, "\\/");
44
		if (!pos)
45
			return 0; /* Error: malformed unc path */
46

47
		do {
48
			pos++;
49
		} while (*pos && !is_dir_sep(*pos));
50
	}
51

52
	return pos + is_dir_sep(*pos) - path;
53
}
54

55
int win32_fspathncmp(const char *a, const char *b, size_t count)
56
{
57
	int diff;
58

59
	for (;;) {
60
		if (!count--)
61
			return 0;
62
		if (!*a)
63
			return *b ? -1 : 0;
64
		if (!*b)
65
			return +1;
66

67
		if (is_dir_sep(*a)) {
68
			if (!is_dir_sep(*b))
69
				return -1;
70
			a++;
71
			b++;
72
			continue;
73
		} else if (is_dir_sep(*b))
74
			return +1;
75

76
		diff = ignore_case ?
77
			(unsigned char)tolower(*a) - (int)(unsigned char)tolower(*b) :
78
			(unsigned char)*a - (int)(unsigned char)*b;
79
		if (diff)
80
			return diff;
81
		a++;
82
		b++;
83
	}
84
}
85

86
int win32_fspathcmp(const char *a, const char *b)
87
{
88
	return win32_fspathncmp(a, b, (size_t)-1);
89
}
90

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.