summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2013-11-01 17:07:44 +0100
committerVicent Marti <tanoku@gmail.com>2013-11-01 17:36:09 +0100
commit0bfa73234263de03e5f797c2f4c514def145433a (patch)
tree229fc54b09b13cd6283a513edfd0174f4d12641f /src
parent95352b7058fe3166689e5af0b3b0a38e7c6f63a0 (diff)
downloadlibgit2-0bfa73234263de03e5f797c2f4c514def145433a.tar.gz
iconv: Do not fake an API when iconv is not available
Diffstat (limited to 'src')
-rw-r--r--src/path.c30
-rw-r--r--src/path.h10
-rw-r--r--src/refs.c7
3 files changed, 35 insertions, 12 deletions
diff --git a/src/path.c b/src/path.c
index d45751cd1..750dd3ef7 100644
--- a/src/path.c
+++ b/src/path.c
@@ -834,7 +834,12 @@ int git_path_direach(
DIR *dir;
path_dirent_data de_data;
struct dirent *de, *de_buf = (struct dirent *)&de_data;
+
+ (void)flags;
+
+#ifdef GIT_USE_ICONV
git_path_iconv_t ic = GIT_PATH_ICONV_INIT;
+#endif
if (git_path_to_dir(path) < 0)
return -1;
@@ -846,8 +851,10 @@ int git_path_direach(
return -1;
}
+#ifdef GIT_USE_ICONV
if ((flags & GIT_PATH_DIR_PRECOMPOSE_UNICODE) != 0)
(void)git_path_iconv_init_precompose(&ic);
+#endif
while (p_readdir_r(dir, de_buf, &de) == 0 && de != NULL) {
char *de_path = de->d_name;
@@ -856,8 +863,12 @@ int git_path_direach(
if (git_path_is_dot_or_dotdot(de_path))
continue;
- if ((error = git_path_iconv(&ic, &de_path, &de_len)) < 0 ||
- (error = git_buf_put(path, de_path, de_len)) < 0)
+#ifdef GIT_USE_ICONV
+ if ((error = git_path_iconv(&ic, &de_path, &de_len)) < 0)
+ break;
+#endif
+
+ if ((error = git_buf_put(path, de_path, de_len)) < 0)
break;
error = fn(arg, path);
@@ -871,7 +882,10 @@ int git_path_direach(
}
closedir(dir);
+
+#ifdef GIT_USE_ICONV
git_path_iconv_clear(&ic);
+#endif
return error;
}
@@ -888,7 +902,12 @@ int git_path_dirload(
size_t path_len;
path_dirent_data de_data;
struct dirent *de, *de_buf = (struct dirent *)&de_data;
+
+ (void)flags;
+
+#ifdef GIT_USE_ICONV
git_path_iconv_t ic = GIT_PATH_ICONV_INIT;
+#endif
assert(path && contents);
@@ -903,8 +922,10 @@ int git_path_dirload(
return -1;
}
+#ifdef GIT_USE_ICONV
if ((flags & GIT_PATH_DIR_PRECOMPOSE_UNICODE) != 0)
(void)git_path_iconv_init_precompose(&ic);
+#endif
path += prefix_len;
path_len -= prefix_len;
@@ -917,8 +938,10 @@ int git_path_dirload(
if (git_path_is_dot_or_dotdot(de_path))
continue;
+#ifdef GIT_USE_ICONV
if ((error = git_path_iconv(&ic, &de_path, &de_len)) < 0)
break;
+#endif
alloc_size = path_len + need_slash + de_len + 1 + alloc_extra;
if ((entry_path = git__calloc(alloc_size, 1)) == NULL) {
@@ -937,7 +960,10 @@ int git_path_dirload(
}
closedir(dir);
+
+#ifdef GIT_USE_ICONV
git_path_iconv_clear(&ic);
+#endif
if (error != 0)
giterr_set(GITERR_OS, "Failed to process directory entry in '%s'", path);
diff --git a/src/path.h b/src/path.h
index 17f4f7726..3daafd265 100644
--- a/src/path.h
+++ b/src/path.h
@@ -425,16 +425,6 @@ extern void git_path_iconv_clear(git_path_iconv_t *ic);
*/
extern int git_path_iconv(git_path_iconv_t *ic, char **in, size_t *inlen);
-#else
-
-typedef struct {
- int unused;
-} git_path_iconv_t;
-#define GIT_PATH_ICONV_INIT { 0 }
-#define git_path_iconv_init_precompose(X) 0
-#define git_path_iconv_clear(X) (void)(X)
-#define git_path_iconv(X,Y,Z) 0
-
#endif /* GIT_USE_ICONV */
#endif
diff --git a/src/refs.c b/src/refs.c
index 269c5f54e..472a79890 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -737,7 +737,10 @@ int git_reference__normalize_name(
int segment_len, segments_count = 0, error = GIT_EINVALIDSPEC;
unsigned int process_flags;
bool normalize = (buf != NULL);
+
+#ifdef GIT_USE_ICONV
git_path_iconv_t ic = GIT_PATH_ICONV_INIT;
+#endif
assert(name);
@@ -750,6 +753,7 @@ int git_reference__normalize_name(
if (normalize)
git_buf_clear(buf);
+#ifdef GIT_USE_ICONV
if ((flags & GIT_REF_FORMAT__PRECOMPOSE_UNICODE) != 0) {
size_t namelen = strlen(current);
if ((error = git_path_iconv_init_precompose(&ic)) < 0 ||
@@ -757,6 +761,7 @@ int git_reference__normalize_name(
goto cleanup;
error = GIT_EINVALIDSPEC;
}
+#endif
while (true) {
segment_len = ensure_segment_validity(current);
@@ -834,7 +839,9 @@ cleanup:
if (error && normalize)
git_buf_free(buf);
+#ifdef GIT_USE_ICONV
git_path_iconv_clear(&ic);
+#endif
return error;
}