Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions platform_specific/socketcan/socketcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,25 @@
#include <linux/can.h>
#include <errno.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdint.h>

/// Returns the current errno as negated int16_t
static int16_t getErrorCode()
{
const int out = -abs(errno);
if (out < 0)
{
if (out >= INT16_MIN)
{
return (int16_t)out;
}
else
{
return INT16_MIN;
}
}
else
const int errno_val = errno;
if (errno_val == 0)
{
assert(false); // Requested an error when errno is zero?
return INT16_MIN;
}

if (errno_val > INT16_MAX || errno_val < INT16_MIN) {
assert(false); // Requested an error when errno is zero?
return INT16_MIN;
}
return -(int16_t)errno_val;
}

int16_t socketcanInit(SocketCANInstance* out_ins, const char* can_iface_name)
Expand Down Expand Up @@ -177,4 +175,4 @@ int16_t socketcanReceive(SocketCANInstance* ins, CanardCANFrame* out_frame, int3
int socketcanGetSocketFileDescriptor(const SocketCANInstance* ins)
{
return ins->fd;
}
}
Loading