From 159ddb872986f121818e816d2ea75d271075ba1f Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sun, 24 Jun 2018 23:09:16 +0430 Subject: [PATCH] Treat - just as /dev/stdin and remove one extra file reader (#1065) --- util/options.cc | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/util/options.cc b/util/options.cc index 682e40c4d..57cc4aa8d 100644 --- a/util/options.cc +++ b/util/options.cc @@ -647,29 +647,20 @@ font_options_t::get_font (void) const if (!font_file) fail (true, "No font file set"); - if (0 == strcmp (font_file, "-")) { - /* read it */ - GString *gs = g_string_new (nullptr); - char buf[BUFSIZ]; + const char *font_path = font_file; + + if (0 == strcmp (font_path, "-")) + { #if defined(_WIN32) || defined(__CYGWIN__) setmode (fileno (stdin), O_BINARY); + font_path = "STDIN"; +#else + font_path = "/dev/stdin"; #endif - while (!feof (stdin)) { - size_t ret = fread (buf, 1, sizeof (buf), stdin); - if (ferror (stdin)) - fail (false, "Failed reading font from standard input: %s", - strerror (errno)); - g_string_append_len (gs, buf, ret); - } - unsigned int len = gs->len; - char *font_data = g_string_free (gs, false); - blob = hb_blob_create (font_data, len, - HB_MEMORY_MODE_WRITABLE, font_data, - (hb_destroy_func_t) g_free); - } else { - blob = hb_blob_create_from_file (font_file); } + blob = hb_blob_create_from_file (font_path); + if (blob == hb_blob_get_empty ()) fail (false, "No such file or directory");