FileHandle.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* mbed Microcontroller Library
  2. * Copyright (c) 2006-2016 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. #include "FileHandle.h"
  17. #include "platform/mbed_retarget.h"
  18. #include "platform/mbed_critical.h"
  19. namespace mbed {
  20. off_t FileHandle::size()
  21. {
  22. /* remember our current position */
  23. off_t off = seek(0, SEEK_CUR);
  24. if (off < 0) {
  25. return off;
  26. }
  27. /* seek to the end to get the file length */
  28. off_t size = seek(0, SEEK_END);
  29. /* return to our old position */
  30. seek(off, SEEK_SET);
  31. return size;
  32. }
  33. } // namespace mbed