Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

followup to 26513, add missing strlcpy #26532

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions Marlin/src/HAL/LINUX/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,14 @@ class MarlinHAL {
}

static void set_pwm_frequency(const pin_t, int) {}

/**
* Add missing strlcpy to HAL as str_lcpy
*/
size_t str_lcpy(char *dest, const char *source, size_t totalsize) {
strncpy(dest, source, totalsize - 1);
dest[totalsize - 1] = '\0';
return strlen(source);
}

};
5 changes: 5 additions & 0 deletions Marlin/src/HAL/LINUX/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@
*
*/
#pragma once

// Redirect strlcpy to hal.str_lcpy
#ifndef strlcpy
ellensp marked this conversation as resolved.
Show resolved Hide resolved
#define strlcpy(dest, source, totalsize) hal.str_lcpy(dest, source, totalsize)
#endif
3 changes: 0 additions & 3 deletions Marlin/src/HAL/LINUX/include/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

#include <pinmapping.h>

#define strlcpy(A, B, C) strncpy(A, B, (C) - 1)
#define strlcpy_P(A, B, C) strncpy_P(A, B, (C) - 1)

#define HIGH 0x01
#define LOW 0x00

Expand Down
9 changes: 9 additions & 0 deletions Marlin/src/HAL/NATIVE_SIM/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,13 @@ class MarlinHAL {
analogWrite(pin, v);
}

/**
* Add missing strlcpy to HAL as str_lcpy
*/
size_t str_lcpy(char *dest, const char *source, size_t totalsize) {
strncpy(dest, source, totalsize - 1);
dest[totalsize - 1] = '\0';
return strlen(source);
}

};
5 changes: 5 additions & 0 deletions Marlin/src/HAL/NATIVE_SIM/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@
#ifndef strcat_P
#define strcat_P(dest, src) strcat((dest), (src))
#endif

// Redirect strlcpy to hal.str_lcpy
#ifndef strlcpy
#define strlcpy(dest, source, totalsize) hal.str_lcpy(dest, source, totalsize)
#endif