Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct {
- unsigned int count;
- unsigned int capacity;
- int *fds;
- } rb_fd_list;
- int
- rb_fd_list_reset(rb_fd_list *list) {
- int *mem;
- mem = realloc(list->fds, sizeof(int) * INITIAL_FD_LIST_CAPACITY);
- if (mem == NULL) {
- return 0;
- } else {
- list->fds = mem;
- list->capacity = INITIAL_FD_LIST_CAPACITY;
- list->count = 0;
- return 1;
- }
- }
- int
- rb_fd_list_push(rb_fd_list *list, int fd) {
- size_t new_capacity;
- int *mem;
- if (list->count >= list->capacity) {
- if (list->capacity == 0) {
- new_capacity = INITIAL_FD_LIST_CAPACITY;
- } else {
- new_capacity = list->capacity * 2;
- }
- mem = realloc(list->fds, sizeof(int) * new_capacity);
- if (mem == NULL) {
- return 0;
- } else {
- list->fds = mem;
- list->capacity = new_capacity;
- }
- }
- list->fds[list->count] = fd;
- list->count++;
- return 1;
- }
Add Comment
Please, Sign In to add comment