011-backport_strscpy.patch 908 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --- a/backport-include/linux/string.h
  2. +++ b/backport-include/linux/string.h
  3. @@ -25,4 +25,8 @@ extern void *memdup_user_nul(const void
  4. void memzero_explicit(void *s, size_t count);
  5. #endif
  6. +#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,3,0))
  7. +ssize_t strscpy(char *dest, const char *src, size_t count);
  8. +#endif
  9. +
  10. #endif /* __BACKPORT_LINUX_STRING_H */
  11. --- a/compat/backport-4.3.c
  12. +++ b/compat/backport-4.3.c
  13. @@ -57,3 +57,29 @@ void seq_hex_dump(struct seq_file *m, co
  14. }
  15. }
  16. EXPORT_SYMBOL_GPL(seq_hex_dump);
  17. +
  18. +ssize_t strscpy(char *dest, const char *src, size_t count)
  19. +{
  20. + long res = 0;
  21. +
  22. + if (count == 0)
  23. + return -E2BIG;
  24. +
  25. + while (count) {
  26. + char c;
  27. +
  28. + c = src[res];
  29. + dest[res] = c;
  30. + if (!c)
  31. + return res;
  32. + res++;
  33. + count--;
  34. + }
  35. +
  36. + /* Hit buffer length without finding a NUL; force NUL-termination. */
  37. + if (res)
  38. + dest[res-1] = '\0';
  39. +
  40. + return -E2BIG;
  41. +}
  42. +EXPORT_SYMBOL_GPL(strscpy);