string_helpers.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef _LINUX_STRING_HELPERS_H_
  2. #define _LINUX_STRING_HELPERS_H_
  3. #include <linux/types.h>
  4. struct file;
  5. /* Descriptions of the types of units to
  6. * print in */
  7. enum string_size_units {
  8. STRING_UNITS_10, /* use powers of 10^3 (standard SI) */
  9. STRING_UNITS_2, /* use binary powers of 2^10 */
  10. };
  11. void string_get_size(u64 size, u64 blk_size, enum string_size_units units,
  12. char *buf, int len);
  13. #define UNESCAPE_SPACE 0x01
  14. #define UNESCAPE_OCTAL 0x02
  15. #define UNESCAPE_HEX 0x04
  16. #define UNESCAPE_SPECIAL 0x08
  17. #define UNESCAPE_ANY \
  18. (UNESCAPE_SPACE | UNESCAPE_OCTAL | UNESCAPE_HEX | UNESCAPE_SPECIAL)
  19. int string_unescape(char *src, char *dst, size_t size, unsigned int flags);
  20. static inline int string_unescape_inplace(char *buf, unsigned int flags)
  21. {
  22. return string_unescape(buf, buf, 0, flags);
  23. }
  24. static inline int string_unescape_any(char *src, char *dst, size_t size)
  25. {
  26. return string_unescape(src, dst, size, UNESCAPE_ANY);
  27. }
  28. static inline int string_unescape_any_inplace(char *buf)
  29. {
  30. return string_unescape_any(buf, buf, 0);
  31. }
  32. #define ESCAPE_SPACE 0x01
  33. #define ESCAPE_SPECIAL 0x02
  34. #define ESCAPE_NULL 0x04
  35. #define ESCAPE_OCTAL 0x08
  36. #define ESCAPE_ANY \
  37. (ESCAPE_SPACE | ESCAPE_OCTAL | ESCAPE_SPECIAL | ESCAPE_NULL)
  38. #define ESCAPE_NP 0x10
  39. #define ESCAPE_ANY_NP (ESCAPE_ANY | ESCAPE_NP)
  40. #define ESCAPE_HEX 0x20
  41. int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz,
  42. unsigned int flags, const char *only);
  43. static inline int string_escape_mem_any_np(const char *src, size_t isz,
  44. char *dst, size_t osz, const char *only)
  45. {
  46. return string_escape_mem(src, isz, dst, osz, ESCAPE_ANY_NP, only);
  47. }
  48. static inline int string_escape_str(const char *src, char *dst, size_t sz,
  49. unsigned int flags, const char *only)
  50. {
  51. return string_escape_mem(src, strlen(src), dst, sz, flags, only);
  52. }
  53. static inline int string_escape_str_any_np(const char *src, char *dst,
  54. size_t sz, const char *only)
  55. {
  56. return string_escape_str(src, dst, sz, ESCAPE_ANY_NP, only);
  57. }
  58. char *kstrdup_quotable(const char *src, gfp_t gfp);
  59. char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp);
  60. char *kstrdup_quotable_file(struct file *file, gfp_t gfp);
  61. #endif