1 /* File-I/O functions for GDB, the GNU debugger.
3 Copyright (C) 2003-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef COMMON_FILEIO_H
21 #define COMMON_FILEIO_H
25 /* The following flags are defined to be independent of the host
26 as well as the target side implementation of these constants.
27 All constants are defined with a leading FILEIO_ in the name
28 to allow the usage of these constants together with the
29 corresponding implementation dependent constants in one module. */
32 #define FILEIO_O_RDONLY 0x0
33 #define FILEIO_O_WRONLY 0x1
34 #define FILEIO_O_RDWR 0x2
35 #define FILEIO_O_APPEND 0x8
36 #define FILEIO_O_CREAT 0x200
37 #define FILEIO_O_TRUNC 0x400
38 #define FILEIO_O_EXCL 0x800
39 #define FILEIO_O_SUPPORTED (FILEIO_O_RDONLY | FILEIO_O_WRONLY| \
40 FILEIO_O_RDWR | FILEIO_O_APPEND| \
41 FILEIO_O_CREAT | FILEIO_O_TRUNC| \
45 #define FILEIO_S_IFREG 0100000
46 #define FILEIO_S_IFDIR 040000
47 #define FILEIO_S_IFCHR 020000
48 #define FILEIO_S_IRUSR 0400
49 #define FILEIO_S_IWUSR 0200
50 #define FILEIO_S_IXUSR 0100
51 #define FILEIO_S_IRWXU 0700
52 #define FILEIO_S_IRGRP 040
53 #define FILEIO_S_IWGRP 020
54 #define FILEIO_S_IXGRP 010
55 #define FILEIO_S_IRWXG 070
56 #define FILEIO_S_IROTH 04
57 #define FILEIO_S_IWOTH 02
58 #define FILEIO_S_IXOTH 01
59 #define FILEIO_S_IRWXO 07
60 #define FILEIO_S_SUPPORTED (FILEIO_S_IFREG|FILEIO_S_IFDIR| \
61 FILEIO_S_IRWXU|FILEIO_S_IRWXG| \
65 #define FILEIO_SEEK_SET 0
66 #define FILEIO_SEEK_CUR 1
67 #define FILEIO_SEEK_END 2
93 FILEIO_ENAMETOOLONG
= 91,
94 FILEIO_EUNKNOWN
= 9999,
98 #define FIO_UINT_LEN 4
99 #define FIO_MODE_LEN 4
100 #define FIO_TIME_LEN 4
101 #define FIO_LONG_LEN 8
102 #define FIO_ULONG_LEN 8
104 typedef char fio_int_t
[FIO_INT_LEN
];
105 typedef char fio_uint_t
[FIO_UINT_LEN
];
106 typedef char fio_mode_t
[FIO_MODE_LEN
];
107 typedef char fio_time_t
[FIO_TIME_LEN
];
108 typedef char fio_long_t
[FIO_LONG_LEN
];
109 typedef char fio_ulong_t
[FIO_ULONG_LEN
];
111 /* Struct stat as used in protocol. For complete independence
112 of host/target systems, it's defined as an array with offsets
120 fio_uint_t fst_nlink
;
124 fio_ulong_t fst_size
;
125 fio_ulong_t fst_blksize
;
126 fio_ulong_t fst_blocks
;
127 fio_time_t fst_atime
;
128 fio_time_t fst_mtime
;
129 fio_time_t fst_ctime
;
138 /* Convert a host-format errno value to a File-I/O error number. */
140 extern fileio_error
host_to_fileio_error (int error
);
142 /* Convert a File-I/O error number to a host-format errno value. */
144 extern int fileio_error_to_host (fileio_error errnum
);
146 /* Convert File-I/O open flags FFLAGS to host format, storing
147 the result in *FLAGS. Return 0 on success, -1 on error. */
149 extern int fileio_to_host_openflags (int fflags
, int *flags
);
151 /* Convert File-I/O mode FMODE to host format, storing
152 the result in *MODE. Return 0 on success, -1 on error. */
154 extern int fileio_to_host_mode (int fmode
, mode_t
*mode
);
156 /* Pack a host-format integer into a byte buffer in big-endian
157 format. BYTES specifies the size of the integer to pack in
161 host_to_bigendian (LONGEST num
, char *buf
, int bytes
)
165 for (i
= 0; i
< bytes
; ++i
)
166 buf
[i
] = (num
>> (8 * (bytes
- i
- 1))) & 0xff;
169 /* Pack a host-format integer into an fio_uint_t. */
172 host_to_fileio_uint (long num
, fio_uint_t fnum
)
174 host_to_bigendian ((LONGEST
) num
, (char *) fnum
, 4);
177 /* Pack a host-format time_t into an fio_time_t. */
180 host_to_fileio_time (time_t num
, fio_time_t fnum
)
182 host_to_bigendian ((LONGEST
) num
, (char *) fnum
, 4);
185 /* Pack a host-format struct stat into a struct fio_stat. */
187 extern void host_to_fileio_stat (struct stat
*st
, struct fio_stat
*fst
);
189 #endif /* COMMON_FILEIO_H */