static void *ralloc(void *ptr, size_t size, enum m_state state) { //LOG("Request for size change to %zd\n", size); if (size == 0) { shee(ptr); return NULL; } if (ptr == NULL) { return shalloc(size); } struct block *b = B_HEAD(ptr); unsigned long size_pow = get_pow(B_SIZE + size); /* No need for allocation, size would be the same */ if (b->k_size == size_pow) { return ptr; } void *new_ptr; if (state == ZERO) { new_ptr = shcalloc(1, size); } else { new_ptr = shalloc(size); } /* In case of failure, previous data is lost */ if (new_ptr == NULL) { shee(ptr); return NULL; } /* Previous data must be preserved, if possible */ memcpy(new_ptr, ptr, MIN(B_DATA_SIZE(b), B_DATA_SIZE(B_HEAD(new_ptr)))); shee(ptr); return new_ptr; }
/* * Allocates and initializes a window stack. */ CoreWindowStack* dfb_windowstack_new( DisplayLayer *layer, int width, int height ) { CardCapabilities caps; CoreWindowStack *stack; DFB_ASSERT( layer != NULL ); DFB_ASSERT( width > 0 ); DFB_ASSERT( height > 0 ); /* Allocate window stack data (completely shared) */ stack = (CoreWindowStack*) shcalloc( 1, sizeof(CoreWindowStack) ); /* Remember layer id for access to it's local data later */ stack->layer_id = dfb_layer_id( layer ); /* Choose window surface policy */ if (dfb_config->window_policy != -1) { /* From configuration */ stack->wsp_opaque = stack->wsp_alpha = dfb_config->window_policy; } else { /* Examine hardware capabilities */ caps = dfb_gfxcard_capabilities(); /* If blitting is supported... */ if (caps.accel & DFXL_BLIT) { /* Auto video policy for opaque windows */ stack->wsp_opaque = CSP_VIDEOHIGH; /* If blending is supported, then use auto video policy for alpha windows */ if (caps.blitting & DSBLIT_BLEND_ALPHACHANNEL) stack->wsp_alpha = CSP_VIDEOHIGH; } } /* Create the pool of windows. */ stack->pool = fusion_object_pool_create( "Window Pool", sizeof(CoreWindow), sizeof(DFBWindowEvent), window_destructor ); /* Initialize the modify/update lock */ skirmish_init( &stack->lock ); /* Set default acceleration */ stack->cursor.numerator = 2; stack->cursor.denominator = 1; stack->cursor.threshold = 4; /* Setup size and cursor clipping region */ dfb_windowstack_resize( stack, width, height ); /* Attach to all input devices */ dfb_input_enumerate_devices( stack_attach_devices, stack ); return stack; }
char *read_line(int fd) { size_t buf_len = 24; size_t line_len = buf_len + 1; char BUF[buf_len]; ssize_t readed; char *line; if ((line = (char *) shcalloc(1, line_len)) == NULL) { return NULL; } //TODO promazat + osetrit close(fd) zde? - MP 0 //int i=0; while ((readed = read(fd, &BUF, buf_len)) > 0) { //printf("OTOCKA %d: ", i++); //printf("line = %s\n", line); strncat(line, BUF, readed); char *pos; if ((pos = strchr(line, '\n')) == NULL) { /* New-line not found, read more bytes */ line_len += buf_len; if ((line = (char *) reshcalloc(line, line_len)) == NULL) { return NULL; } } else { // printf("line pred upravou: >>%s<<\n", line); line_len = strlen(line); memcpy(pos, "\0", 1); // printf("line po uprave: >>%s<<\n", line); // printf("RETURN: line=>>%s<<, line_len=%lu, real_len=%lu\n\n", line, line_len, strlen(line)); /* File descriptor must be returned back */ if (lseek(fd, strlen(line) - line_len + 1, SEEK_CUR) == (off_t) -1) { perror("lseek"); return NULL; } return line; } } /* End of file, line must be complete (possibly empty) */ if (readed == 0 && line[0] != '\0') { return line; } /* Other type of error or nothing was readed */ shee(line); return NULL; }
void *calloc(size_t nmemb, size_t size) { LOG("someone called calloc()\n"); return shcalloc(nmemb, size); }