aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-07-02 12:34:49 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-07-02 12:34:49 +0200
commitfd3f1c89d75950c3603661a7255866d680ec5033 (patch)
tree0ced34c0ddc2d6412c4ad7ba80f85adbfeb2c909
parentc3cb4c76130950bf461e9f8d802f45e97d4113a1 (diff)
Handle UTF-8 BOM in input file
-rw-r--r--odb/odb.cxx22
1 files changed, 22 insertions, 0 deletions
diff --git a/odb/odb.cxx b/odb/odb.cxx
index b0a712b..7ecc0e2 100644
--- a/odb/odb.cxx
+++ b/odb/odb.cxx
@@ -821,6 +821,28 @@ main (int argc, char* argv[])
pi.out_fd, ios_base::out | ios_base::binary);
ostream os (&fb);
+ if (!at_once)
+ {
+ // See if we there is a UTF-8 BOM in the input file. If so,
+ // then we need to write it before prologues.
+ //
+ if (ifs.peek () == 0xEF)
+ {
+ ifs.get ();
+ if (ifs.get () != 0xBB || ifs.get () != 0xBF)
+ {
+ e << name << ": error: invalid UTF-8 BOM sequence" << endl;
+ fb.close ();
+ wait_process (pi, argv[0]);
+ return 1;
+ }
+
+ os.put (0xEF);
+ os.put (0xBB);
+ os.put (0xBF);
+ }
+ }
+
if (!ops.trace ())
{
// Add the standard prologue.