int redirect_output(char ***ptr, char **cmd, int fd, int idx) { while (cmd[idx]) { if ((my_cmp(cmd[idx], ">") || my_cmp(cmd[idx], ">>")) && cmd[idx + 1]) { if (fd != 0 || ((fd = open(cmd[idx + 1], (my_cmp(cmd[idx], ">>") ? O_CREAT | O_APPEND : O_CREAT) | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1) || dup2(fd, STDOUT) == -1) { if (fd == -1) my_dprintf(STDERR, "%s: No such file or directory.\n", cmd[idx + 1]); else my_dprintf(STDERR, "Ambiguous input redirect.\n"); return (-1); } *ptr = remove_elem(cmd, idx); *ptr = remove_elem(cmd, idx); } ++idx; } return (fd); }
int redirect_input(char ***ptr, char **cmd, int fd) { int idx; idx = 0; while (cmd[idx]) { if (my_cmp(cmd[idx], "<") && cmd[idx + 1]) { if (fd != 0 || ((fd = open(cmd[idx + 1], O_RDONLY)) == -1) || dup2(fd, STDIN) == -1) { if (fd == -1) my_dprintf(STDERR, "%s: No such file or directory.\n", cmd[idx + 1]); else my_dprintf(STDERR, "Ambiguous input redirect.\n"); return (-1); } *ptr = remove_elem(cmd, idx); *ptr = remove_elem(cmd, idx); } ++idx; } return (fd); }
int redirect_input_double(char ***ptr, char **cmd, int fd) { int idx; idx = 0; while (cmd[idx]) { if (my_cmp(cmd[idx], "<<") && cmd[idx + 1]) { if (fd) { my_dprintf(STDERR, "Ambiguous input redirect.\n"); return (-1); } if (get_input_double(cmd[idx + 1])) { my_dprintf(STDERR, "FATAL ERR! Cannot create temparary file.\n"); return (-1); } *ptr = remove_elem(cmd, idx); *ptr = remove_elem(cmd, idx); } ++idx; } return (fd); }
int main() { add_elem('a'); add_elem('b'); add_elem('c'); print_arr(); printf("\nRemoved Elem: %c",remove_elem()); printf("\nRemoved Elem: %c",remove_elem()); add_elem('d'); print_arr(); add_elem('e'); print_arr(); add_elem('f'); print_arr(); return 0; }
/* Called in the interrupt context */ static void process_timer_expiry(struct hwt_info *hwt) { struct sw_timer *head = hwt->used_list; while(head) { /* Run through list to process all expired timers */ struct u64_val hwt_current; if(0 != hwt_get_current(head->hwt_obj, &hwt_current)) goto handle_timer_expiry_exit1; if(0 > cmp_u64(&hwt_current, &head->hwt_expires)) break; /* Timer is yet to reach expiry, so quit */ remove_elem(head, &hwt->used_list); handle_expired_timer(head); head = hwt->used_list; } if(head) sched_timer_if_new(head); else hwt_stop(hwt); handle_timer_expiry_exit1: return; }
void sequence(chatmessage_t* message, packet_t* newpacket) { message->seqnum = atoi(newpacket->packetbody); remove_elem(UNSEQ_CHAT_MSGS,(void*)message); q_enqueue(HBACK_Q,(void*)message); chatmessage_t* firstmessage = (chatmessage_t*)q_peek(HBACK_Q); pthread_mutex_lock(&seqno_mutex); if(firstmessage->messagetype == JOIN && SEQ_NO == -1) //my first message to display! { SEQ_NO = firstmessage->seqnum; } if(firstmessage->seqnum > SEQ_NO) { printf("SEQUENCE OUT OF SYNC. Skipping Ahead by %d messages\n",firstmessage->seqnum-SEQ_NO); SEQ_NO = firstmessage->seqnum; } if(firstmessage->seqnum <= SEQ_NO) { SEQ_NO = firstmessage->seqnum + 1; client_t* firstclientmatchbyname; if(firstmessage->messagetype == CHAT) { // printf("\E[34m%s\E(B\E[m (sequenced: %d):\t%s\n", firstmessage->sender, firstmessage->seqnum,firstmessage->messagebody); firstclientmatchbyname = find_client_by_uid(firstmessage->senderuid); } else { // printf("\E[34m%s\E(B\E[m joined the chat (sequenced: %d)\n", firstmessage->messagebody, firstmessage->seqnum); firstclientmatchbyname = find_client_by_uid(firstmessage->senderuid); } char* uid = ""; if(firstclientmatchbyname != NULL) { uid = firstclientmatchbyname->uid; remove_elem(UNSEQ_CHAT_MSGS,firstmessage); } if(firstmessage->messagetype == CHAT) print_msg_with_senderids(firstmessage->sender,firstmessage->messagebody, uid); q_dequeue(HBACK_Q); } pthread_mutex_unlock(&seqno_mutex); return; }
static void replace_previous_elem(GtDlistelem *previous_elem, GtFeatureNode *current_feature, GtDlist *trees, GtHashmap *target_to_elem, GtStr *key) { remove_elem(previous_elem, trees, target_to_elem, key); include_feature(trees, target_to_elem, current_feature, key); }
/** Remove n elements from the beginning of the list. */ static void remove_n_elems(ccd_cblist *l, int n) { int i; if(n==0 || (l->len < n)) return; for(i=0; i<n; i++) { remove_elem(l, l->first); } }
void remove_main_and_fork(t_champ *root, t_champ *tmp) { t_champ *tmp_2; tmp_2 = root->next; while (tmp_2 != root) { tmp_2 = tmp_2->next; if (tmp_2->previous != tmp && tmp_2->previous->father == tmp->pid) remove_main_and_fork(root, tmp_2->previous); } remove_elem(tmp); }
void clean(t_champ *champ, t_cycle *cycle, t_uchar *arena) { t_champ *tmp; free(arena); free(cycle); tmp = champ->next; while (tmp != champ) { tmp = tmp->next; remove_elem(tmp->previous); } free(champ); exit(0); }
int main() { node_t *temp; node_t *root = alloc_node(1); root->next = alloc_node(2); root->next->next = alloc_node(3); root->next->next->next = alloc_node(4); root->next->next->next->next = alloc_node(5); root = remove_elem(&root, 1); for (temp = root; temp != NULL; temp = temp->next) { printf("%d \n", temp->val); } }
static i32 timer_stop(struct sw_timer *swt) { struct hwt_info *hwt = swt->hwt_obj; if(0 != remove_elem(swt, &hwt->used_list)) { return -1; } set_scheduled(swt, false); set_periodic(swt, false); if(NULL != hwt->used_list) sched_timer_if_new(hwt->used_list); else hwt_stop(hwt); /* No pending request, stop HW */ return 0; }
void process_late_sequence(chatmessage_t* message, packet_t* newpacket) { pthread_mutex_lock(&STRAY_SEQ_MSGS->mutex); node_t* curr = STRAY_SEQ_MSGS->head; packet_t* seqpacket = NULL; bool founddeqpacket = FALSE; while(curr != NULL) { seqpacket = (packet_t*)curr->elem; if(seqpacket->uid == newpacket->uid) { founddeqpacket = TRUE; break; } curr = curr->next; } pthread_mutex_unlock(&STRAY_SEQ_MSGS->mutex); if(founddeqpacket) { remove_elem(STRAY_SEQ_MSGS,seqpacket); sequence(message, seqpacket); } return; }
/** * Cancel a previously registered conditional callback */ void CcdCancelCallOnConditionKeep(int condnum, int idx) { remove_elem(&(CpvAccess(conds).condcb_keep[condnum]), idx); }