static long vgawrite(Chan* c, void* a, long n, vlong off) { char *p; ulong offset = off; switch((ulong)c->qid.path){ case Qdir: error(Eperm); case Qvgactl: if(offset || n >= READSTR) error(Ebadarg); p = malloc(READSTR); if(waserror()){ free(p); nexterror(); } memmove(p, a, n); p[n] = 0; vgactl(p); poperror(); free(p); return n; default: error(Egreg); break; } return 0; }
static int32_t vgawrite(Chan* c, void* a, int32_t n, int64_t off) { Proc *up = externup(); uint32_t offset = off; Cmdbuf *cb; VGAscr *scr; switch((uint32_t)c->qid.path){ case Qdir: error(Eperm); case Qvgactl: if(offset || n >= READSTR) error(Ebadarg); cb = parsecmd(a, n); if(waserror()){ free(cb); nexterror(); } vgactl(cb); poperror(); free(cb); return n; case Qvgaovl: scr = &vgascreen[0]; if (scr->dev == nil || scr->dev->ovlwrite == nil) { error(Enooverlay); break; } return scr->dev->ovlwrite(scr, a, n, off); case Qvgaovlctl: scr = &vgascreen[0]; if (scr->dev == nil || scr->dev->ovlctl == nil) { error(Enooverlay); break; } scr->dev->ovlctl(scr, c, a, n); return n; default: error(Egreg); break; } return 0; }