1
1
/*
2
2
* Converts filenames from decomposed unicode into precomposed unicode.
3
3
* Used on MacOS X.
4
- */
5
-
4
+ */
6
5
7
6
#define PRECOMPOSE_UNICODE_C
8
7
11
10
#include "precompose_utf8.h"
12
11
13
12
typedef char * iconv_ibp ;
14
- const static char * repo_encoding = "UTF-8" ;
15
- const static char * path_encoding = "UTF-8-MAC" ;
16
-
13
+ static const char * repo_encoding = "UTF-8" ;
14
+ static const char * path_encoding = "UTF-8-MAC" ;
17
15
18
- static size_t has_utf8 (const char * s , size_t maxlen , size_t * strlen_c )
16
+ static size_t has_non_ascii (const char * s , size_t maxlen , size_t * strlen_c )
19
17
{
20
- const uint8_t * utf8p = (const uint8_t * ) s ;
18
+ const uint8_t * ptr = (const uint8_t * ) s ;
21
19
size_t strlen_chars = 0 ;
22
20
size_t ret = 0 ;
23
21
24
- if ((! utf8p ) || (! * utf8p )) {
22
+ if (! ptr || ! * ptr )
25
23
return 0 ;
26
- }
27
24
28
- while (( * utf8p ) && maxlen ) {
29
- if (* utf8p & 0x80 )
25
+ while ( * ptr && maxlen ) {
26
+ if (* ptr & 0x80 )
30
27
ret ++ ;
31
28
strlen_chars ++ ;
32
- utf8p ++ ;
29
+ ptr ++ ;
33
30
maxlen -- ;
34
31
}
35
32
if (strlen_c )
@@ -41,26 +38,24 @@ static size_t has_utf8(const char *s, size_t maxlen, size_t *strlen_c)
41
38
42
39
void probe_utf8_pathname_composition (char * path , int len )
43
40
{
44
- const static char * auml_nfc = "\xc3\xa4" ;
45
- const static char * auml_nfd = "\x61\xcc\x88" ;
41
+ static const char * auml_nfc = "\xc3\xa4" ;
42
+ static const char * auml_nfd = "\x61\xcc\x88" ;
46
43
int output_fd ;
47
44
if (precomposed_unicode != -1 )
48
45
return ; /* We found it defined in the global config, respect it */
49
- path [len ] = 0 ;
50
46
strcpy (path + len , auml_nfc );
51
47
output_fd = open (path , O_CREAT |O_EXCL |O_RDWR , 0600 );
52
- if (output_fd >=0 ) {
48
+ if (output_fd >= 0 ) {
53
49
close (output_fd );
54
- path [len ] = 0 ;
55
50
strcpy (path + len , auml_nfd );
56
51
/* Indicate to the user, that we can configure it to true */
57
- if (0 == access (path , R_OK ))
52
+ if (! access (path , R_OK ))
58
53
git_config_set ("core.precomposeunicode" , "false" );
59
- /* To be backward compatible, set precomposed_unicode to 0 */
54
+ /* To be backward compatible, set precomposed_unicode to 0 */
60
55
precomposed_unicode = 0 ;
61
- path [len ] = 0 ;
62
56
strcpy (path + len , auml_nfc );
63
- unlink (path );
57
+ if (unlink (path ))
58
+ die_errno (_ ("failed to unlink '%s'" ), path );
64
59
}
65
60
}
66
61
@@ -82,7 +77,7 @@ void precompose_argv(int argc, const char **argv)
82
77
while (i < argc ) {
83
78
size_t namelen ;
84
79
oldarg = argv [i ];
85
- if (has_utf8 (oldarg , (size_t )-1 , & namelen )) {
80
+ if (has_non_ascii (oldarg , (size_t )-1 , & namelen )) {
86
81
newarg = reencode_string_iconv (oldarg , namelen , ic_precompose );
87
82
if (newarg )
88
83
argv [i ] = newarg ;
@@ -135,7 +130,7 @@ struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
135
130
prec_dir -> dirent_nfc -> d_ino = res -> d_ino ;
136
131
prec_dir -> dirent_nfc -> d_type = res -> d_type ;
137
132
138
- if ((precomposed_unicode == 1 ) && has_utf8 (res -> d_name , (size_t )-1 , NULL )) {
133
+ if ((precomposed_unicode == 1 ) && has_non_ascii (res -> d_name , (size_t )-1 , NULL )) {
139
134
if (prec_dir -> ic_precompose == (iconv_t )- 1 ) {
140
135
die ("iconv_open(%s,%s) failed, but needed:\n"
141
136
" precomposed unicode is not supported.\n"
@@ -160,8 +155,7 @@ struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
160
155
namelenz = 0 ; /* trigger strlcpy */
161
156
}
162
157
}
163
- }
164
- else
158
+ } else
165
159
namelenz = 0 ;
166
160
167
161
if (!namelenz )
0 commit comments