fileio.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* File-I/O functions for GDB, the GNU debugger.
  2. Copyright (C) 2003-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef COMMON_FILEIO_H
  15. #define COMMON_FILEIO_H
  16. #include "gdb/fileio.h"
  17. #include <sys/stat.h>
  18. /* Convert a host-format errno value to a File-I/O error number. */
  19. extern int host_to_fileio_error (int error);
  20. /* Convert File-I/O open flags FFLAGS to host format, storing
  21. the result in *FLAGS. Return 0 on success, -1 on error. */
  22. extern int fileio_to_host_openflags (int fflags, int *flags);
  23. /* Convert File-I/O mode FMODE to host format, storing
  24. the result in *MODE. Return 0 on success, -1 on error. */
  25. extern int fileio_to_host_mode (int fmode, mode_t *mode);
  26. /* Pack a host-format integer into a byte buffer in big-endian
  27. format. BYTES specifies the size of the integer to pack in
  28. bytes. */
  29. static inline void
  30. host_to_bigendian (LONGEST num, char *buf, int bytes)
  31. {
  32. int i;
  33. for (i = 0; i < bytes; ++i)
  34. buf[i] = (num >> (8 * (bytes - i - 1))) & 0xff;
  35. }
  36. /* Pack a host-format integer into an fio_uint_t. */
  37. static inline void
  38. host_to_fileio_uint (long num, fio_uint_t fnum)
  39. {
  40. host_to_bigendian ((LONGEST) num, (char *) fnum, 4);
  41. }
  42. /* Pack a host-format time_t into an fio_time_t. */
  43. static inline void
  44. host_to_fileio_time (time_t num, fio_time_t fnum)
  45. {
  46. host_to_bigendian ((LONGEST) num, (char *) fnum, 4);
  47. }
  48. /* Pack a host-format struct stat into a struct fio_stat. */
  49. extern void host_to_fileio_stat (struct stat *st, struct fio_stat *fst);
  50. #endif /* COMMON_FILEIO_H */