Skip to content

Commit 5f8580a

Browse files
robinrosenberggitster
authored andcommitted
cleanup precompose_utf8
- Remove extraneous parentheses and braces; - Remove redundant NUL-termination before strcpy(); - Check result of unlink when probing for decomposed file names; - Adjust for the coding style by adding missing whitespaces; - Move storage class "static" at the beginning of the decl. Signed-off-by: Robin Rosenberg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 76759c7 commit 5f8580a

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

compat/precompose_utf8.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/*
22
* Converts filenames from decomposed unicode into precomposed unicode.
33
* Used on MacOS X.
4-
*/
5-
4+
*/
65

76
#define PRECOMPOSE_UNICODE_C
87

@@ -11,21 +10,19 @@
1110
#include "precompose_utf8.h"
1211

1312
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";
1715

1816
static size_t has_utf8(const char *s, size_t maxlen, size_t *strlen_c)
1917
{
20-
const uint8_t *utf8p = (const uint8_t*) s;
18+
const uint8_t *utf8p = (const uint8_t *)s;
2119
size_t strlen_chars = 0;
2220
size_t ret = 0;
2321

24-
if ((!utf8p) || (!*utf8p)) {
22+
if (!utf8p || !*utf8p)
2523
return 0;
26-
}
2724

28-
while((*utf8p) && maxlen) {
25+
while (*utf8p && maxlen) {
2926
if (*utf8p & 0x80)
3027
ret++;
3128
strlen_chars++;
@@ -41,26 +38,24 @@ static size_t has_utf8(const char *s, size_t maxlen, size_t *strlen_c)
4138

4239
void probe_utf8_pathname_composition(char *path, int len)
4340
{
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";
4643
int output_fd;
4744
if (precomposed_unicode != -1)
4845
return; /* We found it defined in the global config, respect it */
49-
path[len] = 0;
5046
strcpy(path + len, auml_nfc);
5147
output_fd = open(path, O_CREAT|O_EXCL|O_RDWR, 0600);
52-
if (output_fd >=0) {
48+
if (output_fd >= 0) {
5349
close(output_fd);
54-
path[len] = 0;
5550
strcpy(path + len, auml_nfd);
5651
/* Indicate to the user, that we can configure it to true */
57-
if (0 == access(path, R_OK))
52+
if (!access(path, R_OK))
5853
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 */
6055
precomposed_unicode = 0;
61-
path[len] = 0;
6256
strcpy(path + len, auml_nfc);
63-
unlink(path);
57+
if (unlink(path))
58+
die_errno(_("failed to unlink '%s'"), path);
6459
}
6560
}
6661

@@ -160,8 +155,7 @@ struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
160155
namelenz = 0; /* trigger strlcpy */
161156
}
162157
}
163-
}
164-
else
158+
} else
165159
namelenz = 0;
166160

167161
if (!namelenz)

0 commit comments

Comments
 (0)