static void doit (DDEV_REQ *packet) { switch (packet->header.msgtyp) { case DEV_OPN: /* デバイスのオープン */ if (!initialized) { init_console (); } open_console (packet->header.mbfid, &(packet->body.opn_req)); break; case DEV_CLS: /* デバイスのクローズ */ close_console (packet->header.mbfid, &(packet->body.cls_req)); break; case DEV_REA: read_console (packet->header.mbfid, &(packet->body.rea_req)); break; case DEV_WRI: write_console (packet->header.mbfid, &(packet->body.wri_req)); break; case DEV_CTL: control_console (packet->header.mbfid, &(packet->body.ctl_req)); break; } }
static int f() { char buf = '1'; while (1) { read_console(&buf, 1); write_console(&buf, 1); } return 0; }
static ssize_t do_read(void *handle, char *buffer, size_t size) { switch( use_console ) { case C_ATTACHED: return read_console(handle, buffer, size); case C_NONE: case C_READ: if ( ask_attach(TRUE) ) { if ( attach_console() ) return read_console(handle, buffer, size); } case C_NEVER: return -1; } return -1; }
static int test() { // CHECK: reg c1: 0 printf("reg c1: %d\n", register_console(&c1)); // CHECK: reg c2: 0 printf("reg c2: %d\n", register_console(&c2)); write_console(NULL, 0); // CHECK: read ret: 1 char tmp; printf("read ret: %d\n", read_console(&tmp, 1)); unregister_console(&c1); return 0; }
/** * getchar() without echo * wait until at least one character pressed * @return character readed */ int mygetchar(){ // аналог getchar() без необходимости жать Enter int ret; do ret = read_console(); while(ret == 0); return ret; }
/** * getchar() without echo * wait until at least one character pressed * @return character readed */ int mygetchar(){ // getchar() without need of pressing ENTER int ret; do ret = read_console(); while(ret == 0); return ret; }