FileSystemLike.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* mbed Microcontroller Library
  2. * Copyright (c) 2006-2013 ARM Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MBED_FILESYSTEMLIKE_H
  17. #define MBED_FILESYSTEMLIKE_H
  18. #include "platform/platform.h"
  19. #include "platform/FileSystemHandle.h"
  20. #include "platform/FileHandle.h"
  21. #include "platform/DirHandle.h"
  22. #include "platform/NonCopyable.h"
  23. namespace mbed {
  24. /** \addtogroup platform */
  25. /** @{*/
  26. /**
  27. * \defgroup platform_FileSystemLike FileSystemLike functions
  28. * @{
  29. */
  30. /** A filesystem-like object is one that can be used to open file-like
  31. * objects though it by fopen("/name/filename", mode)
  32. *
  33. * Implementations must define at least open (the default definitions
  34. * of the rest of the functions just return error values).
  35. *
  36. * @note Synchronization level: Set by subclass
  37. */
  38. class FileSystemLike : public FileSystemHandle, public FileBase, private NonCopyable<FileSystemLike> {
  39. public:
  40. /** FileSystemLike lifetime
  41. */
  42. FileSystemLike(const char *name = NULL) : FileBase(name, FileSystemPathType) {}
  43. virtual ~FileSystemLike() {}
  44. // Inherited functions with name conflicts
  45. using FileSystemHandle::open;
  46. /** Open a file on the filesystem
  47. *
  48. * @param path The name of the file to open
  49. * @param flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR,
  50. * bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
  51. * @return A file handle on success, NULL on failure
  52. * @deprecated Replaced by `int open(FileHandle **, ...)` for propagating error codes
  53. */
  54. MBED_DEPRECATED_SINCE("mbed-os-5.5",
  55. "Replaced by `int open(FileHandle **, ...)` for propagating error codes")
  56. FileHandle *open(const char *path, int flags)
  57. {
  58. FileHandle *file;
  59. int err = open(&file, path, flags);
  60. return err ? NULL : file;
  61. }
  62. /** Open a directory on the filesystem
  63. *
  64. * @param path Name of the directory to open
  65. * @return A directory handle on success, NULL on failure
  66. * @deprecated Replaced by `int open(DirHandle **, ...)` for propagating error codes
  67. */
  68. MBED_DEPRECATED_SINCE("mbed-os-5.5",
  69. "Replaced by `int open(DirHandle **, ...)` for propagating error codes")
  70. DirHandle *opendir(const char *path)
  71. {
  72. DirHandle *dir;
  73. int err = open(&dir, path);
  74. return err ? NULL : dir;
  75. }
  76. };
  77. /**@}*/
  78. /**@}*/
  79. } // namespace mbed
  80. #endif