static ptrdiff_t writeTimer(Portal* p, void* buf, size_t size, Offset offset) { UNUSED(offset); if (size == 0) return 0; if (p->crumb.flags & CRUMB_ISDIR) { errno = EPERM; return -1; } NodeInfo ni; if (getNodeInfoStaticNS(p, timerSNS, WalkSelf, &ni) == NULL) { errno = ENODEV; return -1; } Timer* timer = (Timer*)ni.contents; if (strcmp(timer->name, "k70PDB0") == 0) { char duration[21] = {0}; memcpy(duration, buf, size > 20 ? 20 : size); AlarmChain* alarm = syskmalloc0(sizeof *alarm); enterCriticalRegion(); alarm->wakeTime = systime + atoi(duration); alarm->pid = rp ? rp->pid : 0; INIT_LIST_HEAD(&alarm->next); listAddBefore(&alarm->next, &timer->alarms); leaveCriticalRegion(); return (sizeof duration); } char newBuf[8]; size_t bytes = size > 8 ? 8 : size; memcpy(newBuf + (8 - bytes), buf, size); memcpy(&timer->timestamp.msecs, newBuf, 8); return bytes; }
InterCodes* interCodeInsert(InterCodes *head, InterCode *p) { assert(head != NULL); assert(p != NULL); listAddBefore(head, &p->list); return head; }