forked from analogdevicesinc/libiio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mask.c
43 lines (33 loc) · 899 Bytes
/
mask.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libiio - Library for interfacing industrial I/O (IIO) devices
*
* Copyright (C) 2022 Analog Devices, Inc.
* Author: Paul Cercueil <[email protected]>
*/
#include "iio-private.h"
#include <errno.h>
#include <string.h>
struct iio_channels_mask * iio_create_channels_mask(unsigned int nb_channels)
{
struct iio_channels_mask *mask;
size_t nb_words = (nb_channels + 31) / 32;
if (!nb_words)
return NULL;
mask = zalloc(sizeof(*mask) + nb_words * sizeof(uint32_t));
if (mask)
mask->words = nb_words;
return mask;
}
int iio_channels_mask_copy(struct iio_channels_mask *dst,
const struct iio_channels_mask *src)
{
if (dst->words != src->words)
return -EINVAL;
memcpy(dst->mask, src->mask, src->words * sizeof(uint32_t));
return 0;
}
void iio_channels_mask_destroy(struct iio_channels_mask *mask)
{
free(mask);
}