char * estrdup_impl( const char * str #ifdef EREALLOC_CALLSITE , const char * file, int line #endif ) { char * copy; size_t bytes; bytes = strlen(str) + 1; copy = ereallocz(NULL, bytes, 0, FALSE #ifdef EREALLOC_CALLSITE , file, line #endif ); memcpy(copy, str, bytes); return copy; }
/** * Actually performs updating for the specified network graph widget. * @param widget * The widget. * @param type * The network graph type. * @param traffic * The traffic type (tx/rx). * @param bytes * Bytes. */ static void widget_network_graph_update(widgetdata *widget, int type, int traffic, size_t bytes) { HARD_ASSERT(widget != NULL); if (!widget->show) { return; } network_graph_widget_t *network_graph = widget->subwidget; network_graph_data_t *data = &network_graph->data[type]; if (data->data == NULL || data->width != widget->w) { if (data->data == NULL) { data->ticks = LastTick; } data->data = ereallocz(data->data, sizeof(*data->data) * NETWORK_GRAPH_TRAFFIC_MAX * data->width, sizeof(*data->data) * NETWORK_GRAPH_TRAFFIC_MAX * widget->w); data->width = widget->w; } if (data->width == 0) { return; } if (LastTick - data->ticks > 1000) { data->pos++; data->ticks = LastTick; } if (data->pos == data->width) { data->pos--; bool recalc_max = false; for (int i = 0; i < NETWORK_GRAPH_TRAFFIC_MAX; i++) { if (data->data[i] >= data->max) { recalc_max = true; } } memmove(data->data, data->data + NETWORK_GRAPH_TRAFFIC_MAX, sizeof(*data->data) * (NETWORK_GRAPH_TRAFFIC_MAX * (data->width - 1))); if (recalc_max) { data->max = 0; } for (int i = 0; i < NETWORK_GRAPH_TRAFFIC_MAX; i++) { data->data[data->pos * NETWORK_GRAPH_TRAFFIC_MAX + i] = 0; if (recalc_max) { for (int x = 0; x < data->pos; x++) { size_t bytes2 = data->data[x * NETWORK_GRAPH_TRAFFIC_MAX + i]; if (bytes2 > data->max) { data->max = bytes2; } } } } } size_t *dst = &data->data[data->pos * NETWORK_GRAPH_TRAFFIC_MAX + traffic]; *dst += bytes; if (*dst > data->max) { data->max = *dst; } widget->redraw = 1; }
void * emalloc(size_t newsz) { return ereallocz(NULL, newsz, 0, FALSE); }