From fd3f1c89d75950c3603661a7255866d680ec5033 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 2 Jul 2014 12:34:49 +0200 Subject: Handle UTF-8 BOM in input file --- odb/odb.cxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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. -- cgit v1.1