#include <poll.h>
#include <linux/gpio.h>
-#define MALLOC __attribute__((malloc))
-
struct gpiod_chip {
int fd;
struct gpiochip_info cinfo;
static const char dev_dir[] = "/dev/";
static const char cdev_prefix[] = "gpiochip";
-static MALLOC void * zalloc(size_t size)
-{
- void *ptr;
-
- ptr = malloc(size);
- if (ptr)
- memset(ptr, 0, size);
-
- return ptr;
-}
-
static bool is_unsigned_int(const char *str)
{
for (; *str && isdigit(*str); str++);
if (!verify_line_bulk(bulk))
return -1;
- handle = zalloc(sizeof(*handle));
+ handle = malloc(sizeof(*handle));
if (!handle)
return -1;
+ memset(handle, 0, sizeof(*handle));
+
req = &handle->request;
if (config->flags & GPIOD_REQUEST_OPEN_DRAIN)
if (fd < 0)
return NULL;
- chip = zalloc(sizeof(*chip));
+ chip = malloc(sizeof(*chip));
if (!chip) {
close(fd);
return NULL;
}
+ memset(chip, 0, sizeof(*chip));
chip->fd = fd;
status = ioctl(fd, GPIO_GET_CHIPINFO_IOCTL, &chip->cinfo);
return NULL;
}
- chip->lines = zalloc(chip->cinfo.lines * sizeof(*chip->lines));
+ chip->lines = calloc(chip->cinfo.lines, sizeof(*chip->lines));
if (!chip->lines) {
close(chip->fd);
free(chip);
{
struct gpiod_chip_iter *new;
- new = zalloc(sizeof(*new));
+ new = malloc(sizeof(*new));
if (!new)
return NULL;
+ memset(new, 0, sizeof(*new));
+
new->dir = opendir(dev_dir);
if (!new->dir)
return NULL;