Advertisement
Weegee

Untitled

Aug 16th, 2011
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. struct event * create_event(struct eventlist * list_ev, int todelete, float duration, void(* func)(void *), int arg_count, ...)
  2. {
  3.     va_list ptr;
  4.     int i;
  5.     void ** arg_array = malloc(sizeof(void *) * arg_count);
  6.     struct event * ev_new = malloc(sizeof(struct event));
  7.    
  8.     va_start(ptr, arg_count);
  9.     for (i = 0; i < arg_count; i++)
  10.     {
  11.         arg_array[i] = va_arg(ptr, void *);
  12.     }
  13.     va_end(ptr);
  14.    
  15.     ev_new->todelete = todelete;
  16.     ev_new->start = clock();
  17.     ev_new->duration = (clock_t) duration * CLOCKS_PER_SEC;
  18.     ev_new->func = func;
  19.     ev_new->arg = arg_array;
  20.    
  21.     if (list_ev->tail != NULL)
  22.     {
  23.         list_ev->tail->next = ev_new;
  24.     }
  25.    
  26.     if (list_ev->count == 0)
  27.     {
  28.         assert(list_ev->head == NULL && list_ev->tail == NULL);
  29.         list_ev->head = ev_new;
  30.     }
  31.    
  32.     list_ev->tail = ev_new;
  33.     list_ev->count++;
  34.    
  35.     /* Debug */
  36.     fprintf(debuglog, "create_event()\n\tCreated event %p\n", (void *) ev_new);
  37.     fflush(debuglog);
  38.    
  39.     return ev_new;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement