qdf_file.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /**
  19. * DOC: Thin filesystem API abstractions
  20. */
  21. #ifndef __QDF_FILE_H
  22. #define __QDF_FILE_H
  23. #include "qdf_status.h"
  24. /**
  25. * qdf_file_read() - read the entire contents of a file
  26. * @path: the full path of the file to read
  27. * @out_buf: double pointer for referring to the file contents buffer
  28. *
  29. * This API allocates a new, null-terminated buffer containing the contents of
  30. * the file at @path. On success, @out_buf points to this new buffer, otherwise
  31. * @out_buf is set to NULL.
  32. *
  33. * Consumers must free the allocated buffer by calling qdf_file_buf_free().
  34. *
  35. * Return: QDF_STATUS
  36. */
  37. QDF_STATUS qdf_file_read(const char *path, char **out_buf);
  38. /**
  39. * qdf_file_buf_free() - free a previously allocated file buffer
  40. * @file_buf: pointer to the file buffer to free
  41. *
  42. * This API is used in conjunction with qdf_file_read().
  43. *
  44. * Return: None
  45. */
  46. void qdf_file_buf_free(char *file_buf);
  47. #ifdef QCA_WIFI_MODULE_PARAMS_FROM_INI
  48. /**
  49. * qdf_module_param_file_read() - read the entire contents of a file
  50. * @path: the full path of the file to read
  51. * @out_buf: double pointer for referring to the file contents buffer
  52. *
  53. * This API allocates a new buffer before qdf_mem_init() is being called.
  54. * Thus, this API helps to allocate memory which is being used before qdf
  55. * memory tracking framework is available. Buffer is null-terminated,
  56. * containing the contents of the file at @path. On success, @out_buf
  57. * points to this new buffer, otherwise @out_buf is set to NULL.
  58. *
  59. * Consumers must free the allocated buffer by calling
  60. * qdf_module_param_file_free().
  61. *
  62. * Return: QDF_STATUS
  63. */
  64. QDF_STATUS qdf_module_param_file_read(const char *path, char **out_buf);
  65. /**
  66. * qdf_module_param_file_free() - free a previously allocated file buffer
  67. * @file_buf: pointer to the file buffer to free. The buffer allocated in
  68. * qdf_module_param_file_read is not tracked by qdf framework.
  69. *
  70. * This API is used in conjunction with qdf_module_param_file_read().
  71. *
  72. * Return: None
  73. */
  74. void qdf_module_param_file_free(char *file_buf);
  75. #else
  76. static inline
  77. QDF_STATUS qdf_module_param_file_read(const char *path, char **out_buf)
  78. {
  79. return QDF_STATUS_E_INVAL;
  80. }
  81. static inline
  82. void qdf_module_param_file_free(char *file_buf)
  83. {
  84. }
  85. #endif
  86. #endif /* __QDF_FILE_H */