/* To do*/ static ssize_t list_write(struct file *filp, const char __user *buf, size_t len, loff_t *off) { char kbuf[len]; int num; /* Transfer data from user to kernel space */ if (copy_from_user(&kbuf, buf, len)) return -EFAULT; if(sscanf(kbuf, "add %i", &num) == 1) { // add command trace_printk("Executing command 'add %i'\n", num); list_item_t *new_node; new_node = vmalloc(sizeof(list_item_t)); new_node->data = num; list_add_tail(&(new_node->links), &mylist); }else if(sscanf(kbuf, "remove %i", &num) == 1){ // remove command, trace_printk("Executing command 'remove %i'\n", num); Foreach(pos, aux, &mylist) elem = list_entry(pos, list_item_t, links); trace_printk("At elem '%i' (@%p)\n", elem->data, elem); if(elem->data == num){ trace_printk("Found elem '%i'. Removing...\n", elem->data); list_del(pos); vfree(elem); } Endforeach() }else if(sscanf(kbuf, "cleanup") == 0){ // cleanup command,
const prop_info* SystemProperties::FindNth(unsigned n) { struct find_nth { const uint32_t sought; uint32_t current; const prop_info* result; explicit find_nth(uint32_t n) : sought(n), current(0), result(nullptr) { } static void fn(const prop_info* pi, void* ptr) { find_nth* self = reinterpret_cast<find_nth*>(ptr); if (self->current++ == self->sought) self->result = pi; } } state(n); Foreach(find_nth::fn, &state); return state.result; }
bool Address::validateString(const QString &str) { auto firstcolon = str.indexOf(":"); auto firstslash = str.indexOf("/"); bool valid = str == QString(str.toUtf8()) && (firstcolon > 0) && (firstslash == (firstcolon + 1) && !str.contains("//")); QStringList path = str.split("/"); valid &= path.size() > 0; path.first().remove(":"); Foreach(path, [&] (const auto& fragment) { valid &= validateFragment(fragment); }); return valid; }