chiark / gitweb /
sd-rtnl: introduce sd_rtnl_new_from_netlink
[elogind.git] / src / libsystemd-terminal / subterm.c
index f2651b24ac3759a148a3d623ad7bc3b1b8c56f0d..63cd2a5ad689d6ee07f3ddc6011e3f8a7c51f9a9 100644 (file)
@@ -41,6 +41,7 @@
 #include "sd-event.h"
 #include "term-internal.h"
 #include "util.h"
+#include "utf8.h"
 
 typedef struct Output Output;
 typedef struct Terminal Terminal;
@@ -102,10 +103,8 @@ static int output_winch(Output *o) {
         assert_return(o, -EINVAL);
 
         r = ioctl(o->fd, TIOCGWINSZ, &wsz);
-        if (r < 0) {
-                log_error_errno(errno, "error: cannot read window-size: %m");
-                return -errno;
-        }
+        if (r < 0)
+                return log_error_errno(errno, "error: cannot read window-size: %m");
 
         if (wsz.ws_col != o->width || wsz.ws_row != o->height) {
                 o->width = wsz.ws_col;
@@ -119,14 +118,14 @@ static int output_winch(Output *o) {
 }
 
 static int output_flush(Output *o) {
-        ssize_t len;
+        int r;
 
         if (o->n_obuf < 1)
                 return 0;
 
-        len = loop_write(o->fd, o->obuf, o->n_obuf, false);
-        if (len < 0)
-                return log_error_errno(len, "error: cannot write to TTY (%zd): %m", len);
+        r = loop_write(o->fd, o->obuf, o->n_obuf, false);
+        if (r < 0)
+                return log_error_errno(r, "error: cannot write to TTY: %m");
 
         o->n_obuf = 0;
 
@@ -162,16 +161,14 @@ static int output_write(Output *o, const void *buf, size_t size) {
 
 _printf_(3,0)
 static int output_vnprintf(Output *o, size_t max, const char *format, va_list args) {
-        char buf[4096];
+        char buf[max];
         int r;
 
         assert_return(o, -EINVAL);
         assert_return(format, -EINVAL);
-        assert_return(max <= sizeof(buf), -EINVAL);
+        assert_return(max <= 4096, -EINVAL);
 
-        r = vsnprintf(buf, max, format, args);
-        if (r > (ssize_t)max)
-                r = max;
+        r = MIN(vsnprintf(buf, max, format, args), (int) max);
 
         return output_write(o, buf, r);
 }
@@ -461,7 +458,7 @@ static int output_draw_cell_fn(term_screen *screen,
                 output_printf(o, " ");
         } else {
                 for (k = 0; k < n_ch; ++k) {
-                        ulen = term_utf8_encode(utf8, ch[k]);
+                        ulen = utf8_encode_unichar(utf8, ch[k]);
                         output_write(o, utf8, ulen);
                 }
         }
@@ -627,7 +624,7 @@ static int terminal_push_tmp(Terminal *t, uint32_t ucs4) {
 
         assert(t);
 
-        len = term_utf8_encode(buf, ucs4);
+        len = utf8_encode_unichar(buf, ucs4);
         if (len < 1)
                 return 0;
 
@@ -822,16 +819,12 @@ static int terminal_new(Terminal **out, int in_fd, int out_fd) {
         assert_return(out, -EINVAL);
 
         r = tcgetattr(in_fd, &in_attr);
-        if (r < 0) {
-                log_error_errno(errno, "error: tcgetattr() (%d): %m", -errno);
-                return -errno;
-        }
+        if (r < 0)
+                return log_error_errno(errno, "error: tcgetattr() (%d): %m", -errno);
 
         r = tcgetattr(out_fd, &out_attr);
-        if (r < 0) {
-                log_error_errno(errno, "error: tcgetattr() (%d): %m", -errno);
-                return -errno;
-        }
+        if (r < 0)
+                return log_error_errno(errno, "error: tcgetattr() (%d): %m", -errno);
 
         t = new0(Terminal, 1);
         if (!t)