summaryrefslogtreecommitdiff
path: root/dos2unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'dos2unix.c')
-rw-r--r--dos2unix.c58
1 files changed, 39 insertions, 19 deletions
diff --git a/dos2unix.c b/dos2unix.c
index 01f217c..a0d582b 100644
--- a/dos2unix.c
+++ b/dos2unix.c
@@ -7,7 +7,7 @@
* See also http://www.freebsd.org/copyright/freebsd-license.html
* --------
*
- * Copyright (C) 2009-2012 Erwin Waterlander
+ * Copyright (C) 2009-2013 Erwin Waterlander
* Copyright (C) 1998 Christian Wurll
* Copyright (C) 1998 Bernd Johannes Wuebben
* Copyright (C) 1994-1995 Benjamin Lin.
@@ -66,7 +66,7 @@
#include "dos2unix.h"
#include "querycp.h"
#ifdef D2U_UNICODE
-#if !defined(__MSDOS__) && !defined(__WIN32__) && !defined(__OS2__) /* Unix, Cygwin */
+#if !defined(__MSDOS__) && !defined(_WIN32) && !defined(__OS2__) /* Unix, Cygwin */
# include <langinfo.h>
#endif
#endif
@@ -74,7 +74,7 @@
void PrintLicense(void)
{
fprintf(stderr, "%s", _("\
-Copyright (C) 2009-2012 Erwin Waterlander\n\
+Copyright (C) 2009-2013 Erwin Waterlander\n\
Copyright (C) 1998 Christian Wurll (Version 3.1)\n\
Copyright (C) 1998 Bernd Johannes Wuebben (Version 3.0)\n\
Copyright (C) 1994-1995 Benjamin Lin\n\
@@ -135,6 +135,7 @@ int ConvertDosToUnixW(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, char *progname)
wint_t TempChar;
wint_t TempNextChar;
int line_nr = 1;
+ char *errstr;
ipFlag->status = 0;
@@ -173,8 +174,9 @@ int ConvertDosToUnixW(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, char *progname)
{
if (!(ipFlag->status & UNICODE_CONVERSION_ERROR))
{
+ errstr = strerror(errno);
fprintf(stderr, "%s: ", progname);
- fprintf(stderr, "%s", _("can not write to output file\n"));
+ fprintf(stderr, _("can not write to output file: %s\n"), errstr);
}
}
break;
@@ -211,8 +213,9 @@ int ConvertDosToUnixW(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, char *progname)
{
if (!(ipFlag->status & UNICODE_CONVERSION_ERROR))
{
+ errstr = strerror(errno);
fprintf(stderr, "%s: ", progname);
- fprintf(stderr, "%s", _("can not write to output file\n"));
+ fprintf(stderr, _("can not write to output file: %s\n"), errstr);
}
}
break;
@@ -235,8 +238,9 @@ int ConvertDosToUnixW(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, char *progname)
{
if (!(ipFlag->status & UNICODE_CONVERSION_ERROR))
{
+ errstr = strerror(errno);
fprintf(stderr, "%s: ", progname);
- fprintf(stderr, "%s", _("can not write to output file\n"));
+ fprintf(stderr, _("can not write to output file: %s\n"), errstr);
}
}
break;
@@ -271,6 +275,7 @@ int ConvertDosToUnix(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, char *progname)
int TempNextChar;
int *ConvTable;
int line_nr = 1;
+ char *errstr;
ipFlag->status = 0;
@@ -343,8 +348,9 @@ int ConvertDosToUnix(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, char *progname)
RetVal = -1;
if (!ipFlag->Quiet)
{
+ errstr = strerror(errno);
fprintf(stderr, "%s: ", progname);
- fprintf(stderr, "%s", _("can not write to output file\n"));
+ fprintf(stderr, _("can not write to output file: %s\n"), errstr);
}
break;
}
@@ -378,8 +384,9 @@ int ConvertDosToUnix(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, char *progname)
RetVal = -1;
if (!ipFlag->Quiet)
{
+ errstr = strerror(errno);
fprintf(stderr, "%s: ", progname);
- fprintf(stderr, "%s", _("can not write to output file\n"));
+ fprintf(stderr, _("can not write to output file: %s\n"), errstr);
}
break;
}
@@ -399,8 +406,9 @@ int ConvertDosToUnix(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, char *progname)
RetVal = -1;
if (!ipFlag->Quiet)
{
+ errstr = strerror(errno);
fprintf(stderr, "%s: ", progname);
- fprintf(stderr, "%s", _("can not write to output file\n"));
+ fprintf(stderr, _("can not write to output file: %s\n"), errstr);
}
break;
}
@@ -548,7 +556,7 @@ int ConvertDosToUnixNewFile(char *ipInFN, char *ipOutFN, CFlag *ipFlag, char *pr
InF = read_bom(InF, &ipFlag->bomtype);
#ifdef D2U_UNICODE
-#if !defined(__MSDOS__) && !defined(__WIN32__) && !defined(__OS2__) /* Unix, Cygwin */
+#if !defined(__MSDOS__) && !defined(_WIN32) && !defined(__OS2__) /* Unix, Cygwin */
if ((ipFlag->bomtype == FILE_UTF16LE) || (ipFlag->bomtype == FILE_UTF16BE))
{
if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0)
@@ -561,7 +569,7 @@ int ConvertDosToUnixNewFile(char *ipInFN, char *ipOutFN, CFlag *ipFlag, char *pr
}
}
#endif
-#if !defined(__WIN32__) && !defined(__CYGWIN__) /* Not Windows or Cygwin */
+#if !defined(_WIN32) && !defined(__CYGWIN__) /* Not Windows or Cygwin */
if ((ipFlag->bomtype == FILE_UTF16LE) || (ipFlag->bomtype == FILE_UTF16BE))
{
if (sizeof(wchar_t) < 4)
@@ -607,8 +615,20 @@ int ConvertDosToUnixNewFile(char *ipInFN, char *ipOutFN, CFlag *ipFlag, char *pr
RetVal = -1;
/* can close output file? */
- if ((TempF) && (fclose(TempF) == EOF))
- RetVal = -1;
+ if (TempF)
+ {
+ if (fclose(TempF) == EOF)
+ {
+ if (!ipFlag->Quiet)
+ {
+ ipFlag->error = errno;
+ errstr = strerror(errno);
+ fprintf(stderr, "%s: ", progname);
+ fprintf(stderr, _("Failed to write to temporary output file %s: %s\n"), TempPath, errstr);
+ }
+ RetVal = -1;
+ }
+ }
#ifdef NO_MKSTEMP
if(fd!=NULL)
@@ -769,18 +789,18 @@ int ConvertDosToUnixStdio(CFlag *ipFlag, char *progname)
ipFlag->KeepDate = 0;
ipFlag->Force = 1;
-#if defined(__WIN32__) && !defined(__CYGWIN__)
+#if defined(_WIN32) && !defined(__CYGWIN__)
/* stdin and stdout are by default text streams. We need
* to set them to binary mode. Otherwise an LF will
* automatically be converted to CR-LF on DOS/Windows.
* Erwin */
- /* 'setmode' was deprecated by MicroSoft
- * since Visual C++ 2005. Use '_setmode' instead. */
+ /* POSIX 'setmode' was deprecated by MicroSoft since
+ * Visual C++ 2005. Use ISO C++ conformant '_setmode' instead. */
- _setmode(fileno(stdout), O_BINARY);
- _setmode(fileno(stdin), O_BINARY);
+ _setmode(_fileno(stdout), _O_BINARY);
+ _setmode(_fileno(stdin), _O_BINARY);
#elif defined(__MSDOS__) || defined(__CYGWIN__) || defined(__OS2__)
setmode(fileno(stdout), O_BINARY);
setmode(fileno(stdin), O_BINARY);
@@ -842,7 +862,7 @@ int main (int argc, char *argv[])
}
#endif
-#if defined(ENABLE_NLS) || (defined(D2U_UNICODE) && !defined(__MSDOS__) && !defined(__WIN32__) && !defined(__OS2__))
+#if defined(ENABLE_NLS) || (defined(D2U_UNICODE) && !defined(__MSDOS__) && !defined(_WIN32) && !defined(__OS2__))
/* setlocale() is also needed for nl_langinfo() */
setlocale (LC_ALL, "");
#endif