From: Sami Kerola Date: Sat, 2 Apr 2011 20:56:53 +0000 (+0200) Subject: setterm: function screendump coding style fixed X-Git-Tag: v2.20-rc1~381 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a973947c8822c5172d4daf96a415665c3f6b921d;p=thirdparty%2Futil-linux.git setterm: function screendump coding style fixed Signed-off-by: Sami Kerola --- diff --git a/term-utils/setterm.c b/term-utils/setterm.c index c0aa531319..f9e7a755ac 100644 --- a/term-utils/setterm.c +++ b/term-utils/setterm.c @@ -1151,68 +1151,69 @@ perform_sequence(int vcterm) { } static void -screendump(int vcnum, FILE *F) { - char infile[MAXPATHLEN]; - unsigned char header[4]; - unsigned int rows, cols; - int fd, i, j; - char *inbuf, *outbuf, *p, *q; - - sprintf(infile, "/dev/vcsa%d", vcnum); - fd = open(infile, O_RDONLY); - if (fd < 0 && vcnum == 0) { - /* vcsa0 is often called vcsa */ - sprintf(infile, "/dev/vcsa"); - fd = open(infile, O_RDONLY); - } - if (fd < 0) { - /* try devfs name - for zero vcnum just /dev/vcc/a */ - /* some gcc's warn for %.u - add 0 */ - sprintf(infile, "/dev/vcc/a%.0u", vcnum); - fd = open(infile, O_RDONLY); - } - if (fd < 0) { +screendump(int vcnum, FILE * F) +{ + char infile[MAXPATHLEN]; + unsigned char header[4]; + unsigned int rows, cols; + int fd, i, j; + char *inbuf, *outbuf, *p, *q; + sprintf(infile, "/dev/vcsa%d", vcnum); - goto read_error; - } - if (read(fd, header, 4) != 4) - goto read_error; - rows = header[0]; - cols = header[1]; - if (rows * cols == 0) - goto read_error; - inbuf = malloc(rows*cols*2); - outbuf = malloc(rows*(cols+1)); - if(!inbuf || !outbuf) { - fputs(_("Out of memory"), stderr); - goto error; - } - if (read(fd, inbuf, rows*cols*2) != rows*cols*2) - goto read_error; - p = inbuf; - q = outbuf; - for(i=0; i 0 && q[-1] == ' ') + q--; + *q++ = '\n'; + } + if (fwrite(outbuf, 1, q - outbuf, F) != q - outbuf) { + warnx(_("Error writing screendump")); + goto error; } - while(j-- > 0 && q[-1] == ' ') - q--; - *q++ = '\n'; - } - if (fwrite(outbuf, 1, q-outbuf, F) != q-outbuf) { - warnx(_("Error writing screendump")); - goto error; - } - close(fd); - return; - -read_error: - warnx(_("Couldn't read %s"), infile); -error: - if (fd >= 0) - close(fd); - exit(EXIT_FAILURE); + close(fd); + return; + + read_error: + warnx(_("Couldn't read %s"), infile); + error: + if (fd >= 0) + close(fd); + exit(EXIT_FAILURE); } int