From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00, DNS_FROM_AHBL_RHSBL, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RP_MATCHES_RCVD, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Date: Wed, 22 Apr 2015 21:06:40 +0200 From: Felix Janda To: kbd@lists.altlinux.org Message-ID: <20150422190640.GD3170@euler> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Mailman-Approved-At: Thu, 23 Apr 2015 13:19:25 +0300 Subject: [kbd] [PATCH 4/5] setvtrgb: inline set_colormap X-BeenThere: kbd@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Linux console tools development discussion List-Id: Linux console tools development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Apr 2015 19:06:45 -0000 Archived-At: List-Archive: --- src/setvtrgb.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/setvtrgb.c b/src/setvtrgb.c index 94501ef..3fa03a7 100644 --- a/src/setvtrgb.c +++ b/src/setvtrgb.c @@ -54,18 +54,6 @@ usage(int code) } static void -set_colormap(unsigned char *colormap) -{ - int fd = getfd(NULL); - - /* Apply the color map to the tty via ioctl */ - if (ioctl(fd, PIO_CMAP, colormap) == -1) - error(EXIT_FAILURE, errno, "ioctl"); - - close(fd); -} - -static void parse_file(FILE *fd, const char *filename) { int c; @@ -100,9 +88,10 @@ parse_file(FILE *fd, const char *filename) int main(int argc, char **argv) { - int c; + int c, fd; const char *file; - FILE *fd; + unsigned char *colormap = cmap; + FILE *f; set_progname(argv[0]); @@ -127,21 +116,26 @@ main(int argc, char **argv) { file = argv[optind]; if (!strcmp(file, "vga")) { - set_colormap(vga_colors); - return EXIT_SUCCESS; + colormap = vga_colors; } else if (!strcmp(file, "-")) { parse_file(stdin, "stdin"); } else { - if ((fd = fopen(file, "r")) == NULL) + if ((f = fopen(file, "r")) == NULL) error(EXIT_FAILURE, errno, "fopen"); - parse_file(fd, file); - fclose(fd); + parse_file(f, file); + fclose(f); } - set_colormap(cmap); + fd = getfd(NULL); + + /* Apply the color map to the tty via ioctl */ + if (ioctl(fd, PIO_CMAP, colormap) == -1) + error(EXIT_FAILURE, errno, "ioctl"); + + close(fd); return EXIT_SUCCESS; } -- 2.0.5