diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-20 13:29:34 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-20 13:29:37 +0900 |
commit | 0077b68f7eb84ff84bc271256e4ac0e178e531f9 (patch) | |
tree | fcec8afa85d4c7c259f81e3bbe95145cd1d77510 /common.c | |
parent | 988f99500ba83724242b161936adaa960b677653 (diff) | |
download | dos2unix-0077b68f7eb84ff84bc271256e4ac0e178e531f9.tar.gz dos2unix-0077b68f7eb84ff84bc271256e4ac0e178e531f9.tar.bz2 dos2unix-0077b68f7eb84ff84bc271256e4ac0e178e531f9.zip |
Imported Upstream version 7.3.1
Change-Id: I838c61f0002c36df152a67302d8881f8b6d3ded2
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'common.c')
-rw-r--r-- | common.c | 40 |
1 files changed, 33 insertions, 7 deletions
@@ -37,11 +37,9 @@ #endif #endif -#if defined(D2U_UNICODE) #if !defined(__MSDOS__) && !defined(_WIN32) && !defined(__OS2__) /* Unix, Cygwin */ # include <langinfo.h> #endif -#endif #if defined(__GLIBC__) /* on glibc, canonicalize_file_name() broken prior to 2.4 (06-Mar-2006) */ @@ -547,10 +545,10 @@ int glob_warg(int argc, wchar_t *wargv[], char ***argv, CFlag *ipFlag, const cha path_and_filename = (wchar_t *)malloc(len*sizeof(wchar_t)); if (path_and_filename == NULL) goto glob_failed; if (add_path) { - wcsncpy_s(path_and_filename, len, path, wcslen(path)); - wcsncat_s(path_and_filename, len, FindFileData.cFileName, wcslen(FindFileData.cFileName)); + wcsncpy(path_and_filename, path, wcslen(path)+1); + wcsncat(path_and_filename, FindFileData.cFileName, wcslen(FindFileData.cFileName)+1); } else { - wcsncpy_s(path_and_filename, len, FindFileData.cFileName, wcslen(FindFileData.cFileName)); + wcsncpy(path_and_filename, FindFileData.cFileName, wcslen(FindFileData.cFileName)+1); } found = 1; @@ -1230,6 +1228,16 @@ int check_unicode(FILE *InF, FILE *TempF, CFlag *ipFlag, const char *ipInFN, co } if (ipFlag->verbose > 1) print_bom(ipFlag->bomtype, ipInFN, progname); +#ifndef D2U_UNICODE + /* It is possible that an UTF-16 has no 8-bit binary symbols. We must stop + * processing an UTF-16 file when UTF-16 is not supported. Don't trust on + * finding a binary symbol. + */ + if ((ipFlag->bomtype == FILE_UTF16LE) || (ipFlag->bomtype == FILE_UTF16BE)) { + ipFlag->status |= UNICODE_NOT_SUPPORTED ; + return -1; + } +#endif #ifdef D2U_UNICODE if ((ipFlag->bomtype == FILE_MBS) && (ipFlag->ConvMode == CONVMODE_UTF16LE)) ipFlag->bomtype = FILE_UTF16LE; @@ -1615,12 +1623,18 @@ void print_messages_stdio(const CFlag *pFlag, const char *progname) } else if (pFlag->status & WRONG_CODEPAGE) { d2u_fprintf(stderr,"%s: ",progname); d2u_fprintf(stderr, _("code page %d is not supported.\n"), pFlag->ConvMode); +#ifdef D2U_UNICODE } else if (pFlag->status & WCHAR_T_TOO_SMALL) { d2u_fprintf(stderr,"%s: ",progname); d2u_fprintf(stderr, _("Skipping UTF-16 file %s, the size of wchar_t is %d bytes.\n"), "stdin", (int)sizeof(wchar_t)); } else if (pFlag->status & UNICODE_CONVERSION_ERROR) { d2u_fprintf(stderr,"%s: ",progname); d2u_fprintf(stderr, _("Skipping UTF-16 file %s, an UTF-16 conversion error occurred on line %u.\n"), "stdin", pFlag->line_nr); +#else + } else if (pFlag->status & UNICODE_NOT_SUPPORTED) { + d2u_fprintf(stderr,"%s: ",progname); + d2u_fprintf(stderr, _("Skipping UTF-16 file %s, UTF-16 conversion is not supported in this version of %s.\n"), "stdin", progname); +#endif } } @@ -1635,7 +1649,6 @@ void print_format(const CFlag *pFlag, char *informat, char *outformat, size_t li strncpy(informat,_("UTF-16BE"),lin); informat[lin-1]='\0'; -#ifdef D2U_UNICODE if ((pFlag->bomtype == FILE_UTF16LE)||(pFlag->bomtype == FILE_UTF16BE)) { #if !defined(__MSDOS__) && !defined(_WIN32) && !defined(__OS2__) /* Unix, Cygwin */ strncpy(outformat,nl_langinfo(CODESET),lout); @@ -1657,7 +1670,6 @@ void print_format(const CFlag *pFlag, char *informat, char *outformat, size_t li } outformat[lout-1]='\0'; } -#endif } void print_messages_newfile(const CFlag *pFlag, const char *infile, const char *outfile, const char *progname, const int RetVal) @@ -1701,12 +1713,18 @@ void print_messages_newfile(const CFlag *pFlag, const char *infile, const char * } else if (pFlag->status & WRONG_CODEPAGE) { d2u_fprintf(stderr,"%s: ",progname); d2u_fprintf(stderr, _("code page %d is not supported.\n"), pFlag->ConvMode); +#ifdef D2U_UNICODE } else if (pFlag->status & WCHAR_T_TOO_SMALL) { d2u_fprintf(stderr,"%s: ",progname); d2u_fprintf(stderr, _("Skipping UTF-16 file %s, the size of wchar_t is %d bytes.\n"), infile, (int)sizeof(wchar_t)); } else if (pFlag->status & UNICODE_CONVERSION_ERROR) { d2u_fprintf(stderr,"%s: ",progname); d2u_fprintf(stderr, _("Skipping UTF-16 file %s, an UTF-16 conversion error occurred on line %u.\n"), infile, pFlag->line_nr); +#else + } else if (pFlag->status & UNICODE_NOT_SUPPORTED) { + d2u_fprintf(stderr,"%s: ",progname); + d2u_fprintf(stderr, _("Skipping UTF-16 file %s, UTF-16 conversion is not supported in this version of %s.\n"), infile, progname); +#endif } else { d2u_fprintf(stderr,"%s: ",progname); if (informat[0] == '\0') { @@ -1781,12 +1799,18 @@ void print_messages_oldfile(const CFlag *pFlag, const char *infile, const char * } else if (pFlag->status & WRONG_CODEPAGE) { d2u_fprintf(stderr,"%s: ",progname); d2u_fprintf(stderr, _("code page %d is not supported.\n"), pFlag->ConvMode); +#ifdef D2U_UNICODE } else if (pFlag->status & WCHAR_T_TOO_SMALL) { d2u_fprintf(stderr,"%s: ",progname); d2u_fprintf(stderr, _("Skipping UTF-16 file %s, the size of wchar_t is %d bytes.\n"), infile, (int)sizeof(wchar_t)); } else if (pFlag->status & UNICODE_CONVERSION_ERROR) { d2u_fprintf(stderr,"%s: ",progname); d2u_fprintf(stderr, _("Skipping UTF-16 file %s, an UTF-16 conversion error occurred on line %u.\n"), infile, pFlag->line_nr); +#else + } else if (pFlag->status & UNICODE_NOT_SUPPORTED) { + d2u_fprintf(stderr,"%s: ",progname); + d2u_fprintf(stderr, _("Skipping UTF-16 file %s, UTF-16 conversion is not supported in this version of %s.\n"), infile, progname); +#endif } else { d2u_fprintf(stderr,"%s: ",progname); if (informat[0] == '\0') { @@ -1834,11 +1858,13 @@ void print_messages_info(const CFlag *pFlag, const char *infile, const char *pro d2u_fprintf(stderr,"%s: ",progname); d2u_fprintf(stderr, _("Skipping symbolic link %s, target is not a regular file.\n"), infile); } +#ifdef D2U_UNICODE } else if (pFlag->status & WCHAR_T_TOO_SMALL) { if (pFlag->verbose) { d2u_fprintf(stderr,"%s: ",progname); d2u_fprintf(stderr, _("Skipping UTF-16 file %s, the size of wchar_t is %d bytes.\n"), infile, (int)sizeof(wchar_t)); } +#endif } } |