[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[commits] r5487 - in /fsf/trunk/libc: ChangeLog iconv/iconv_charmap.c iconv/iconv_prog.c iconv/iconv_prog.h
- To: commits@xxxxxxxxxx
- Subject: [commits] r5487 - in /fsf/trunk/libc: ChangeLog iconv/iconv_charmap.c iconv/iconv_prog.c iconv/iconv_prog.h
- From: eglibc@xxxxxxxxxx
- Date: Wed, 12 Mar 2008 07:05:05 -0000
Author: eglibc
Date: Wed Mar 12 00:05:04 2008
New Revision: 5487
Log:
Import glibc-mainline for 2008-03-12
Modified:
fsf/trunk/libc/ChangeLog
fsf/trunk/libc/iconv/iconv_charmap.c
fsf/trunk/libc/iconv/iconv_prog.c
fsf/trunk/libc/iconv/iconv_prog.h
Modified: fsf/trunk/libc/ChangeLog
==============================================================================
--- fsf/trunk/libc/ChangeLog (original)
+++ fsf/trunk/libc/ChangeLog Wed Mar 12 00:05:04 2008
@@ -1,3 +1,15 @@
+2008-03-11 Ulrich Drepper <drepper@xxxxxxxxxx>
+
+ [BZ #5903]
+ * iconv/iconv_charmap.c (charmap_conversion): Pass name of output file
+ not stream for output file. Open output file here.
+ * iconv/iconv_prog.c (process_lock): Take pointer to output stream
+ and output file name.
+ (process_fd): Likewise.
+ (process_file): Likewise.
+ (main): Adjust callers of changed functions.
+ * iconv/iconv_prog.h: Adjust prototype.
+
2008-03-09 Andreas Jaeger <aj@xxxxxxx>
[BZ #5753]
Modified: fsf/trunk/libc/iconv/iconv_charmap.c
==============================================================================
--- fsf/trunk/libc/iconv/iconv_charmap.c (original)
+++ fsf/trunk/libc/iconv/iconv_charmap.c Wed Mar 12 00:05:04 2008
@@ -1,5 +1,5 @@
/* Convert using charmaps and possibly iconv().
- Copyright (C) 2001, 2005, 2006 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2005, 2006, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@xxxxxxxxxx>, 2001.
@@ -94,7 +94,8 @@
int
charmap_conversion (const char *from_code, struct charmap_t *from_charmap,
const char *to_code, struct charmap_t *to_charmap,
- int argc, int remaining, char *argv[], FILE *output)
+ int argc, int remaining, char *argv[],
+ const char *output_file)
{
struct convtable *cvtbl;
int status = EXIT_SUCCESS;
@@ -131,6 +132,17 @@
/* If we couldn't generate a table stop now. */
if (cvtbl == NULL)
return EXIT_FAILURE;
+
+ /* Determine output file. */
+ FILE *output;
+ if (output_file != NULL && strcmp (output_file, "-") != 0)
+ {
+ output = fopen (output_file, "w");
+ if (output == NULL)
+ error (EXIT_FAILURE, errno, _("cannot open output file"));
+ }
+ else
+ output = stdout;
/* We can now start the conversion. */
if (remaining == argc)
Modified: fsf/trunk/libc/iconv/iconv_prog.c
==============================================================================
--- fsf/trunk/libc/iconv/iconv_prog.c (original)
+++ fsf/trunk/libc/iconv/iconv_prog.c Wed Mar 12 00:05:04 2008
@@ -108,9 +108,12 @@
int omit_invalid;
/* Prototypes for the functions doing the actual work. */
-static int process_block (iconv_t cd, char *addr, size_t len, FILE *output);
-static int process_fd (iconv_t cd, int fd, FILE *output);
-static int process_file (iconv_t cd, FILE *input, FILE *output);
+static int process_block (iconv_t cd, char *addr, size_t len, FILE **output,
+ const char *output_file);
+static int process_fd (iconv_t cd, int fd, FILE **output,
+ const char *output_file);
+static int process_file (iconv_t cd, FILE *input, FILE **output,
+ const char *output_file);
static void print_known_names (void) internal_function;
@@ -119,7 +122,6 @@
{
int status = EXIT_SUCCESS;
int remaining;
- FILE *output;
iconv_t cd;
const char *orig_to_code;
struct charmap_t *from_charmap = NULL;
@@ -192,16 +194,6 @@
to_charmap = charmap_read (orig_to_code, /*0, 1,*/1, 0, 0, 0);
- /* Determine output file. */
- if (output_file != NULL && strcmp (output_file, "-") != 0)
- {
- output = fopen (output_file, "w");
- if (output == NULL)
- error (EXIT_FAILURE, errno, _("cannot open output file"));
- }
- else
- output = stdout;
-
/* At this point we have to handle two cases. The first one is
where a charmap is used for the from- or to-charset, or both. We
handle this special since it is very different from the sane way of
@@ -210,7 +202,7 @@
if (from_charmap != NULL || to_charmap != NULL)
/* Construct the conversion table and do the conversion. */
status = charmap_conversion (from_code, from_charmap, to_code, to_charmap,
- argc, remaining, argv, output);
+ argc, remaining, argv, output_file);
else
{
/* Let's see whether we have these coded character sets. */
@@ -268,12 +260,16 @@
_("failed to start conversion processing"));
}
+ /* The output file. Will be opened when we are ready to produce
+ output. */
+ FILE *output = NULL;
+
/* Now process the remaining files. Write them to stdout or the file
specified with the `-o' parameter. If we have no file given as
the parameter process all from stdin. */
if (remaining == argc)
{
- if (process_file (cd, stdin, output) != 0)
+ if (process_file (cd, stdin, &output, output_file) != 0)
status = EXIT_FAILURE;
}
else
@@ -316,7 +312,8 @@
_("error while closing input `%s'"),
argv[remaining]);
- ret = process_block (cd, addr, st.st_size, output);
+ ret = process_block (cd, addr, st.st_size, &output,
+ output_file);
/* We don't need the input data anymore. */
munmap ((void *) addr, st.st_size);
@@ -336,7 +333,7 @@
#endif /* _POSIX_MAPPED_FILES */
{
/* Read the file in pieces. */
- ret = process_fd (cd, fd, output);
+ ret = process_fd (cd, fd, &output, output_file);
/* Now close the file. */
close (fd);
@@ -355,11 +352,11 @@
}
}
while (++remaining < argc);
- }
-
- /* Close the output file now. */
- if (fclose (output))
- error (EXIT_FAILURE, errno, _("error while closing output file"));
+
+ /* Close the output file now. */
+ if (output != NULL && fclose (output))
+ error (EXIT_FAILURE, errno, _("error while closing output file"));
+ }
return status;
}
@@ -433,7 +430,43 @@
static int
-process_block (iconv_t cd, char *addr, size_t len, FILE *output)
+write_output (const char *outbuf, const char *outptr, FILE **output,
+ const char *output_file)
+{
+ /* We have something to write out. */
+ int errno_save = errno;
+
+ if (*output == NULL)
+ {
+ /* Determine output file. */
+ if (output_file != NULL && strcmp (output_file, "-") != 0)
+ {
+ *output = fopen (output_file, "w");
+ if (output == NULL)
+ error (EXIT_FAILURE, errno, _("cannot open output file"));
+ }
+ else
+ *output = stdout;
+ }
+
+ if (fwrite (outbuf, 1, outptr - outbuf, *output) < (size_t) (outptr - outbuf)
+ || ferror (*output))
+ {
+ /* Error occurred while printing the result. */
+ error (0, 0, _("\
+conversion stopped due to problem in writing the output"));
+ return -1;
+ }
+
+ errno = errno_save;
+
+ return 0;
+}
+
+
+static int
+process_block (iconv_t cd, char *addr, size_t len, FILE **output,
+ const char *output_file)
{
#define OUTBUF_SIZE 32768
const char *start = addr;
@@ -460,20 +493,9 @@
if (outptr != outbuf)
{
- /* We have something to write out. */
- int errno_save = errno;
-
- if (fwrite (outbuf, 1, outptr - outbuf, output)
- < (size_t) (outptr - outbuf)
- || ferror (output))
- {
- /* Error occurred while printing the result. */
- error (0, 0, _("\
-conversion stopped due to problem in writing the output"));
- return -1;
- }
-
- errno = errno_save;
+ ret = write_output (outbuf, outptr, output, output_file);
+ if (ret != 0)
+ break;
}
if (n != (size_t) -1)
@@ -486,20 +508,9 @@
if (outptr != outbuf)
{
- /* We have something to write out. */
- int errno_save = errno;
-
- if (fwrite (outbuf, 1, outptr - outbuf, output)
- < (size_t) (outptr - outbuf)
- || ferror (output))
- {
- /* Error occurred while printing the result. */
- error (0, 0, _("\
-conversion stopped due to problem in writing the output"));
- return -1;
- }
-
- errno = errno_save;
+ ret = write_output (outbuf, outptr, output, output_file);
+ if (ret != 0)
+ break;
}
if (n != (size_t) -1)
@@ -543,7 +554,7 @@
static int
-process_fd (iconv_t cd, int fd, FILE *output)
+process_fd (iconv_t cd, int fd, FILE **output, const char *output_file)
{
/* we have a problem with reading from a desriptor since we must not
provide the iconv() function an incomplete character or shift
@@ -617,16 +628,16 @@
}
/* Now we have all the input in the buffer. Process it in one run. */
- return process_block (cd, inbuf, actlen, output);
+ return process_block (cd, inbuf, actlen, output, output_file);
}
static int
-process_file (iconv_t cd, FILE *input, FILE *output)
+process_file (iconv_t cd, FILE *input, FILE **output, const char *output_file)
{
/* This should be safe since we use this function only for `stdin' and
we haven't read anything so far. */
- return process_fd (cd, fileno (input), output);
+ return process_fd (cd, fileno (input), output, output_file);
}
Modified: fsf/trunk/libc/iconv/iconv_prog.h
==============================================================================
--- fsf/trunk/libc/iconv/iconv_prog.h (original)
+++ fsf/trunk/libc/iconv/iconv_prog.h Wed Mar 12 00:05:04 2008
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2001, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@xxxxxxxxxx>, 2001.
@@ -36,7 +36,7 @@
const char *to_code,
struct charmap_t *to_charmap,
int argc, int remaining, char *argv[],
- FILE *output);
+ const char *output_file);
#endif /* iconv_prog.h */