remote: fix compilation with glibc
[project/usteer.git] / node.c
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
14 *
15 * Copyright (C) 2020 embedd.ch
16 * Copyright (C) 2020 Felix Fietkau <nbd@nbd.name>
17 * Copyright (C) 2020 John Crispin <john@phrozen.org>
18 */
19
20 #include "usteer.h"
21
22 void usteer_node_set_blob(struct blob_attr **dest, struct blob_attr *val)
23 {
24 int new_len;
25 int len;
26
27 if (!val) {
28 free(*dest);
29 *dest = NULL;
30 return;
31 }
32
33 len = *dest ? blob_pad_len(*dest) : 0;
34 new_len = blob_pad_len(val);
35 if (new_len != len)
36 *dest = realloc(*dest, new_len);
37 memcpy(*dest, val, new_len);
38 }