static void printc(char **str, struct vmm_chardev *cdev, char ch) { if (str) { vmm_printchar(str, cdev, ch, TRUE); } else { vmm_cputc(cdev, ch); } }
void vmm_cputs(struct vmm_chardev *cdev, char *str) { if (!str) { return; } while (*str) { vmm_cputc(cdev, *str); str++; } }
static void printc(char **out, u32 *out_len, struct vmm_chardev *cdev, char ch) { if (out) { if (*out) { if (out_len && (0 < *out_len)) { **out = ch; ++(*out); (*out_len)--; } else { **out = ch; ++(*out); } } } else { vmm_cputc(cdev, ch); } }
static int cmd_vserial_recv_putchar(struct cmd_vserial_recvcntx *v, u8 ch) { switch (ch) { case '\r': vmm_cprintf(v->cdev, "\r[%s] ", v->name); break; case '\n': vmm_cprintf(v->cdev, "\n[%s] ", v->name); break; default: vmm_cputc(v->cdev, ch); break; }; return VMM_OK; }
static int cmd_vfs_cat(struct vmm_chardev *cdev, const char *path) { int fd, rc; u32 i, off, len; bool found_non_printable; size_t buf_rd; char buf[VFS_LOAD_BUF_SZ]; struct stat st; fd = vfs_open(path, O_RDONLY, 0); if (fd < 0) { vmm_cprintf(cdev, "Failed to open %s\n", path); return fd; } rc = vfs_fstat(fd, &st); if (rc) { vfs_close(fd); vmm_cprintf(cdev, "Failed to stat %s\n", path); return rc; } if (!(st.st_mode & S_IFREG)) { vfs_close(fd); vmm_cprintf(cdev, "Cannot read %s\n", path); return VMM_EINVALID; } off = 0; len = st.st_size; while (len) { buf_rd = (len < VFS_LOAD_BUF_SZ) ? len : VFS_LOAD_BUF_SZ; buf_rd = vfs_read(fd, buf, buf_rd); if (buf_rd < 1) { break; } found_non_printable = FALSE; for (i = 0; i < buf_rd; i++) { if (!vmm_isprintable(buf[i])) { found_non_printable = TRUE; break; } vmm_cputc(cdev, buf[i]); } if (found_non_printable) { vmm_cprintf(cdev, "\nFound non-printable char %d " "at offset %d\n", buf[i], (off + i)); break; } off += buf_rd; len -= buf_rd; } rc = vfs_close(fd); if (rc) { vmm_cprintf(cdev, "Failed to close %s\n", path); return rc; } return VMM_OK; }
void vmm_putc(char ch) { vmm_cputc(stdio_ctrl.dev, ch); }