Signed-off-by: Timur Sufiev <timur@xxxxxxxxxxxx> --- Makefile | 2 + io-i18n.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ io-i18n.h | 23 +++++++++++ 3 files changed, 154 insertions(+), 0 deletions(-) create mode 100644 io-i18n.h diff --git a/Makefile b/Makefile index 42b7d60..ac8e807 100644 --- a/Makefile +++ b/Makefile @@ -459,6 +459,7 @@ LIB_H += tree-walk.h LIB_H += unpack-trees.h LIB_H += userdiff.h LIB_H += utf8.h +LIB_H += io-i18n.h LIB_H += wt-status.h LIB_OBJS += abspath.o @@ -562,6 +563,7 @@ LIB_OBJS += unpack-trees.o LIB_OBJS += usage.o LIB_OBJS += userdiff.o LIB_OBJS += utf8.o +LIB_OBJS += io-i18n.o LIB_OBJS += walker.o LIB_OBJS += wrapper.o LIB_OBJS += write_or_die.o diff --git a/io-i18n.c b/io-i18n.c index 4dcc2db..9d89ac3 100644 --- a/io-i18n.c +++ b/io-i18n.c @@ -1,3 +1,4 @@ +#include "io-i18n.h" #include "utf8.h" #include "cache.h" @@ -80,3 +81,131 @@ char *filename_to_local(const char *filename) return NULL; #endif } + +int stat_i18n(const char *filename, struct stat *buf) +{ + int ret; + char *out = filename_to_local(filename); + + if (out != NULL) { + ret = stat(out, buf); + free(out); + } else + ret = stat(filename, buf); + return ret; +} + +int lstat_i18n(const char *filename, struct stat *buf) +{ + + int ret; + char *out = filename_to_local(filename); + + if (out != NULL) { + ret = lstat(out, buf); + free(out); + } else + ret = lstat(filename, buf); + return ret; +} + +DIR *opendir_i18n(const char *dirname) +{ + DIR *dir; + char *out = filename_to_local(dirname); + + if (out != NULL) { + dir = opendir(out); + free(out); + } else + dir = opendir(dirname); + return dir; +} + +struct dirent *readdir_i18n(DIR * dirstream) +{ + struct dirent *de = readdir(dirstream); + + if (de) { + char *out = filename_to_utf8(de->d_name); + + if (out) { + int len = strlen(out); + if (len >= NAME_MAX) { + warning("readdir_i18n: converted dir entry name length exceeds NAME_MAX and will be truncated\n"); + len = NAME_MAX - 1; + } + memcpy(de->d_name, out, len); + de->d_name[len] = '\0'; + free(out); + } + return de; + } else + return NULL; +} + +int open_i18n(const char *filename, int flags, mode_t mode) +{ + int ret; + char *out = filename_to_local(filename); + + if (out != NULL) { + ret = open(out, flags, mode); + free(out); + } else + ret = open(filename, flags, mode); + return ret; +} + +FILE *fopen_i18n(const char *filename, const char *opentype) +{ + FILE *file; + char *out = filename_to_local(filename); + + if (out != NULL) { + file = fopen(out, opentype); + free(out); + } else + file = fopen(filename, opentype); + return file; +} + +int chmod_i18n(const char *filename, mode_t mode) +{ + int ret; + char *out = filename_to_local(filename); + + if (out != NULL) { + ret = chmod(out, mode); + free(out); + } else + ret = chmod(filename, mode); + return ret; +} + +int link_i18n(const char *oldname, const char *newname) +{ + char *old_out = filename_to_local(oldname); + char *new_out = filename_to_local(newname); + int ret = link(old_out ? old_out : oldname, + new_out ? new_out : newname); + + if (old_out) + free(old_out); + if (new_out) + free(new_out); + return ret; +} + +int unlink_i18n(const char *filename) +{ + char *out = filename_to_local(filename); + int ret; + + if (out) { + ret = unlink(out); + free(out); + } else + ret = unlink(filename); + return ret; +} diff --git a/io-i18n.h b/io-i18n.h new file mode 100644 index 0000000..c386e20 --- /dev/null +++ b/io-i18n.h @@ -0,0 +1,23 @@ +#ifndef GIT_IO_I18N_H +#define GIT_IO_I18N_H + +#define _FILE_OFFSET_BITS 64 + +#include <sys/stat.h> +#include <dirent.h> +#include <stdio.h> + +#define DEFAULT_OPEN_MODE 0 + +char *filename_to_local (const char* filename); +int stat_i18n(const char *filename, struct stat *buf); +int lstat_i18n(const char *filename, struct stat *buf); +DIR* opendir_i18n(const char *dirname); +struct dirent *readdir_i18n(DIR *dirstream); +int open_i18n(const char *filename, int flags, mode_t mode); +FILE *fopen_i18n(const char *filename, const char *opentype); +int chmod_i18n(const char *filename, mode_t mode); +int link_i18n(const char *oldname, const char *newname); +int unlink_i18n(const char *filename); + +#endif /* GIT_IO_I18N_H */ -- 1.6.5.1 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html