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 <robin.rosenberg@dewire.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Robin Rosenberg committed Aug 17, 2012 at 16:53 UTC 5f8580ad471ecd1745107b5ab1f9792e1d855743
1 file changed +14 -20
compat/precompose_utf8.c
+14 -20
@@ -1,8 +1,7 @@
1 /*
2 * Converts filenames from decomposed unicode into precomposed unicode.
3 * Used on MacOS X.
4 -*/
5 -
4 + */
5
6 #define PRECOMPOSE_UNICODE_C
7
@@ -11,21 +10,19 @@
10 #include "precompose_utf8.h"
11
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";
15
16 static size_t has_utf8(const char *s, size_t maxlen, size_t *strlen_c)
17 {
20 - const uint8_t *utf8p = (const uint8_t*) s;
18 + const uint8_t *utf8p = (const uint8_t *)s;
19 size_t strlen_chars = 0;
20 size_t ret = 0;
21
24 - if ((!utf8p) || (!*utf8p)) {
22 + if (!utf8p || !*utf8p)
23 return 0;
26 - }
24
28 - while((*utf8p) && maxlen) {
25 + while (*utf8p && maxlen) {
26 if (*utf8p & 0x80)
27 ret++;
28 strlen_chars++;
@@ -41,26 +38,24 @@ static size_t has_utf8(const char *s, size_t maxlen, size_t *strlen_c)
38
39 void probe_utf8_pathname_composition(char *path, int len)
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";
43 int output_fd;
44 if (precomposed_unicode != -1)
45 return; /* We found it defined in the global config, respect it */
49 - path[len] = 0;
46 strcpy(path + len, auml_nfc);
47 output_fd = open(path, O_CREAT|O_EXCL|O_RDWR, 0600);
52 - if (output_fd >=0) {
48 + if (output_fd >= 0) {
49 close(output_fd);
54 - path[len] = 0;
50 strcpy(path + len, auml_nfd);
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))
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 */
55 precomposed_unicode = 0;
61 - path[len] = 0;
56 strcpy(path + len, auml_nfc);
63 - unlink(path);
57 + if (unlink(path))
58 + die_errno(_("failed to unlink '%s'"), path);
59 }
60 }
61
@@ -160,8 +155,7 @@ struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
155 namelenz = 0; /* trigger strlcpy */
156 }
157 }
163 - }
164 - else
158 + } else
159 namelenz = 0;
160
161 if (!namelenz)