int openFiles(int argc, char **argv) { uint32_t pid; char msg[128]; Stream *lcd; pid = getCurrentPID(); lcd = svc_myFopen("/dev/lcd/lcd"); svc_myFopen("/dev/button/sw1"); svc_myCreate("dev/fs/data"); svc_myFopen("/dev/fs/data"); sprintf(msg, "Hello from PID %d. Leaving 3 files open, will be closed on kill.\r\n", (int) pid); efputs(msg, STDOUT); efflush(STDOUT); svc_myFputs(msg, lcd); sprintf(msg, "About to kill PID %d.\r\n", (int) pid); efputs(msg, STDOUT); efflush(STDOUT); svc_myFputs(msg, lcd); /* kill me */ svc_myKill(pid); return 0; }
int cmd_settimer(int argc, char *argv[], FILE *ostrm) { #else int cmd_settimer(int argc, char *argv[]) { #endif int res; int count; if (argc != 2) { res = efputs("usage: settimer [count]\r\n", ostrm); if (res == EOF) { return WRITE_ERROR; } return WRONG_NUMBER_ARGS; } count = myAtoi(argv[1]); if (count < 0 || count > 65535) { res = efputs("Duration must be between 0 and 65535\r\n", ostrm); if (res == EOF) { return WRITE_ERROR; } return INVALID_INPUT; } interrupt_fired = 0; svc_setTimer(count, my_timer_action); while(!interrupt_fired) { ; } efputs("Interrupt Fired\r\n", STDOUT); efflush(ostrm); return SUCCESS; }
int file_flush(STRING * sval) { int ret = 0; FILE_NODE *p = file_list; size_t len = sval->len; char *str = sval->str; if (len == 0) { /* for consistency with gawk */ ret = flush_all_output(); } else { int found = 0; while (p) { if (IS_OUTPUT(p->type) && len == p->name->len && strcmp(str, p->name->str) == 0) { found = 1; if (efflush((FILE *) p->ptr) != 0) ret = -1; /* it's possible for a command and a file to have the same name -- so keep looking */ } p = p->link; } if (!found) ret = -1; } return ret; }
int flush_all_output(void) { int ret = 0; FILE_NODE *p; for (p = file_list; p; p = p->link) { if (IS_OUTPUT(p->type)) { if (efflush((FILE *) p->ptr) != 0) ret = -1; } } return ret; }