Converting from free-form macros to an enum gives a bit of type-safety.
This caught places where we would assign host error numbers to what
should contain a target fileio error number, for instance in
target_fileio_pread.
I added the FILEIO_SUCCESS enumerator, because
remote.c:remote_hostio_parse_result initializes the remote_errno output
variable to 0. It seems better to have an explicit enumerator than to
assign a value for which there is no enumerator. I considered
initializing this variable to FILEIO_EUNKNOWN instead, such that if the
remote side replies with an error and omits the errno value, we'll get
an errno that represents an error instead of 0 (which reprensents no
error). But it's not clear what the consequences of that change would
be, so I prefer to err on the side of caution and just keep the existing
behavior (there is no intended change in behavior with this patch).
Note that remote_hostio_parse_resul still reads blindly what the remote
side sends as a target errno into this variable, so we can still end up
with a nonsensical value here. It's not good, but out of the scope of
this patch.
Convert host_to_fileio_error and fileio_errno_to_host to return / accept
a fileio_error instead of an int, and cascade the change in the whole
chain that uses that.
Change-Id: I454b0e3fcf0732447bc872252fa8e57d138b0e03
/* Return the system error number corresponding to ERRNUM. */
static int
-fileio_errno_to_host (int errnum)
+fileio_errno_to_host (fileio_error errnum)
{
switch (errnum)
{
gdb_bfd_iovec_fileio_open (struct bfd *abfd, void *open_closure)
{
const char *filename = bfd_get_filename (abfd);
- int fd, target_errno;
+ int fd;
+ fileio_error target_errno;
int *stream;
gdb_bfd_open_closure *oclosure = (gdb_bfd_open_closure *) open_closure;
file_ptr nbytes, file_ptr offset)
{
int fd = *(int *) stream;
- int target_errno;
+ fileio_error target_errno;
file_ptr pos, bytes;
pos = 0;
gdb_bfd_iovec_fileio_close (struct bfd *abfd, void *stream)
{
int fd = *(int *) stream;
- int target_errno;
+ fileio_error target_errno;
xfree (stream);
struct stat *sb)
{
int fd = *(int *) stream;
- int target_errno;
+ fileio_error target_errno;
int result;
result = target_fileio_fstat (fd, sb, &target_errno);
int
inf_child_target::fileio_open (struct inferior *inf, const char *filename,
int flags, int mode, int warn_if_slow,
- int *target_errno)
+ fileio_error *target_errno)
{
int nat_flags;
mode_t nat_mode;
int
inf_child_target::fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
- ULONGEST offset, int *target_errno)
+ ULONGEST offset, fileio_error *target_errno)
{
int ret;
int
inf_child_target::fileio_pread (int fd, gdb_byte *read_buf, int len,
- ULONGEST offset, int *target_errno)
+ ULONGEST offset, fileio_error *target_errno)
{
int ret;
/* Implementation of to_fileio_fstat. */
int
-inf_child_target::fileio_fstat (int fd, struct stat *sb, int *target_errno)
+inf_child_target::fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno)
{
int ret;
/* Implementation of to_fileio_close. */
int
-inf_child_target::fileio_close (int fd, int *target_errno)
+inf_child_target::fileio_close (int fd, fileio_error *target_errno)
{
int ret;
int
inf_child_target::fileio_unlink (struct inferior *inf, const char *filename,
- int *target_errno)
+ fileio_error *target_errno)
{
int ret;
gdb::optional<std::string>
inf_child_target::fileio_readlink (struct inferior *inf, const char *filename,
- int *target_errno)
+ fileio_error *target_errno)
{
/* We support readlink only on systems that also provide a compile-time
maximum path length (PATH_MAX), at least for now. */
int fileio_open (struct inferior *inf, const char *filename,
int flags, int mode, int warn_if_slow,
- int *target_errno) override;
+ fileio_error *target_errno) override;
int fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
- ULONGEST offset, int *target_errno) override;
+ ULONGEST offset, fileio_error *target_errno) override;
int fileio_pread (int fd, gdb_byte *read_buf, int len,
- ULONGEST offset, int *target_errno) override;
- int fileio_fstat (int fd, struct stat *sb, int *target_errno) override;
- int fileio_close (int fd, int *target_errno) override;
+ ULONGEST offset, fileio_error *target_errno) override;
+ int fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno) override;
+ int fileio_close (int fd, fileio_error *target_errno) override;
int fileio_unlink (struct inferior *inf,
const char *filename,
- int *target_errno) override;
+ fileio_error *target_errno) override;
gdb::optional<std::string> fileio_readlink (struct inferior *inf,
const char *filename,
- int *target_errno) override;
+ fileio_error *target_errno) override;
bool use_agent (bool use) override;
bool can_use_agent () override;
int
linux_nat_target::fileio_open (struct inferior *inf, const char *filename,
int flags, int mode, int warn_if_slow,
- int *target_errno)
+ fileio_error *target_errno)
{
int nat_flags;
mode_t nat_mode;
gdb::optional<std::string>
linux_nat_target::fileio_readlink (struct inferior *inf, const char *filename,
- int *target_errno)
+ fileio_error *target_errno)
{
char buf[PATH_MAX];
int len;
int
linux_nat_target::fileio_unlink (struct inferior *inf, const char *filename,
- int *target_errno)
+ fileio_error *target_errno)
{
int ret;
int fileio_open (struct inferior *inf, const char *filename,
int flags, int mode, int warn_if_slow,
- int *target_errno) override;
+ fileio_error *target_errno) override;
gdb::optional<std::string>
fileio_readlink (struct inferior *inf,
const char *filename,
- int *target_errno) override;
+ fileio_error *target_errno) override;
int fileio_unlink (struct inferior *inf,
const char *filename,
- int *target_errno) override;
+ fileio_error *target_errno) override;
int insert_fork_catchpoint (int) override;
int remove_fork_catchpoint (int) override;
int status_f = (what == IP_STATUS || what == IP_ALL);
int stat_f = (what == IP_STAT || what == IP_ALL);
char filename[100];
- int target_errno;
+ fileio_error target_errno;
if (args && isdigit (args[0]))
{
int fileio_open (struct inferior *inf, const char *filename,
int flags, int mode, int warn_if_slow,
- int *target_errno) override;
+ fileio_error *target_errno) override;
int fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
- ULONGEST offset, int *target_errno) override;
+ ULONGEST offset, fileio_error *target_errno) override;
int fileio_pread (int fd, gdb_byte *read_buf, int len,
- ULONGEST offset, int *target_errno) override;
+ ULONGEST offset, fileio_error *target_errno) override;
- int fileio_fstat (int fd, struct stat *sb, int *target_errno) override;
+ int fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno) override;
- int fileio_close (int fd, int *target_errno) override;
+ int fileio_close (int fd, fileio_error *target_errno) override;
int fileio_unlink (struct inferior *inf,
const char *filename,
- int *target_errno) override;
+ fileio_error *target_errno) override;
gdb::optional<std::string>
fileio_readlink (struct inferior *inf,
const char *filename,
- int *target_errno) override;
+ fileio_error *target_errno) override;
bool supports_enable_disable_tracepoint () override;
void remote_file_delete (const char *remote_file, int from_tty);
int remote_hostio_pread (int fd, gdb_byte *read_buf, int len,
- ULONGEST offset, int *remote_errno);
+ ULONGEST offset, fileio_error *remote_errno);
int remote_hostio_pwrite (int fd, const gdb_byte *write_buf, int len,
- ULONGEST offset, int *remote_errno);
+ ULONGEST offset, fileio_error *remote_errno);
int remote_hostio_pread_vFile (int fd, gdb_byte *read_buf, int len,
- ULONGEST offset, int *remote_errno);
+ ULONGEST offset, fileio_error *remote_errno);
int remote_hostio_send_command (int command_bytes, int which_packet,
- int *remote_errno, const char **attachment,
+ fileio_error *remote_errno, const char **attachment,
int *attachment_len);
int remote_hostio_set_filesystem (struct inferior *inf,
- int *remote_errno);
+ fileio_error *remote_errno);
/* We should get rid of this and use fileio_open directly. */
int remote_hostio_open (struct inferior *inf, const char *filename,
int flags, int mode, int warn_if_slow,
- int *remote_errno);
- int remote_hostio_close (int fd, int *remote_errno);
+ fileio_error *remote_errno);
+ int remote_hostio_close (int fd, fileio_error *remote_errno);
int remote_hostio_unlink (inferior *inf, const char *filename,
- int *remote_errno);
+ fileio_error *remote_errno);
struct remote_state *get_remote_state ();
}
/* Parse an I/O result packet from BUFFER. Set RETCODE to the return
- value, *REMOTE_ERRNO to the remote error number or zero if none
+ value, *REMOTE_ERRNO to the remote error number or FILEIO_SUCCESS if none
was included, and *ATTACHMENT to point to the start of the annex
if any. The length of the packet isn't needed here; there may
be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
static int
remote_hostio_parse_result (const char *buffer, int *retcode,
- int *remote_errno, const char **attachment)
+ fileio_error *remote_errno, const char **attachment)
{
char *p, *p2;
- *remote_errno = 0;
+ *remote_errno = FILEIO_SUCCESS;
*attachment = NULL;
if (buffer[0] != 'F')
if (*p == ',')
{
errno = 0;
- *remote_errno = strtol (p + 1, &p2, 16);
+ *remote_errno = (fileio_error) strtol (p + 1, &p2, 16);
if (errno != 0 || p + 1 == p2)
return -1;
p = p2;
int
remote_target::remote_hostio_send_command (int command_bytes, int which_packet,
- int *remote_errno, const char **attachment,
+ fileio_error *remote_errno, const char **attachment,
int *attachment_len)
{
struct remote_state *rs = get_remote_state ();
int
remote_target::remote_hostio_set_filesystem (struct inferior *inf,
- int *remote_errno)
+ fileio_error *remote_errno)
{
struct remote_state *rs = get_remote_state ();
int required_pid = (inf == NULL || inf->fake_pid_p) ? 0 : inf->pid;
int
remote_target::remote_hostio_open (inferior *inf, const char *filename,
int flags, int mode, int warn_if_slow,
- int *remote_errno)
+ fileio_error *remote_errno)
{
struct remote_state *rs = get_remote_state ();
char *p = rs->buf.data ();
int
remote_target::fileio_open (struct inferior *inf, const char *filename,
int flags, int mode, int warn_if_slow,
- int *remote_errno)
+ fileio_error *remote_errno)
{
return remote_hostio_open (inf, filename, flags, mode, warn_if_slow,
remote_errno);
int
remote_target::remote_hostio_pwrite (int fd, const gdb_byte *write_buf, int len,
- ULONGEST offset, int *remote_errno)
+ ULONGEST offset, fileio_error *remote_errno)
{
struct remote_state *rs = get_remote_state ();
char *p = rs->buf.data ();
int
remote_target::fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
- ULONGEST offset, int *remote_errno)
+ ULONGEST offset, fileio_error *remote_errno)
{
return remote_hostio_pwrite (fd, write_buf, len, offset, remote_errno);
}
int
remote_target::remote_hostio_pread_vFile (int fd, gdb_byte *read_buf, int len,
- ULONGEST offset, int *remote_errno)
+ ULONGEST offset, fileio_error *remote_errno)
{
struct remote_state *rs = get_remote_state ();
char *p = rs->buf.data ();
int
remote_target::remote_hostio_pread (int fd, gdb_byte *read_buf, int len,
- ULONGEST offset, int *remote_errno)
+ ULONGEST offset, fileio_error *remote_errno)
{
int ret;
struct remote_state *rs = get_remote_state ();
int
remote_target::fileio_pread (int fd, gdb_byte *read_buf, int len,
- ULONGEST offset, int *remote_errno)
+ ULONGEST offset, fileio_error *remote_errno)
{
return remote_hostio_pread (fd, read_buf, len, offset, remote_errno);
}
/* Implementation of to_fileio_close. */
int
-remote_target::remote_hostio_close (int fd, int *remote_errno)
+remote_target::remote_hostio_close (int fd, fileio_error *remote_errno)
{
struct remote_state *rs = get_remote_state ();
char *p = rs->buf.data ();
}
int
-remote_target::fileio_close (int fd, int *remote_errno)
+remote_target::fileio_close (int fd, fileio_error *remote_errno)
{
return remote_hostio_close (fd, remote_errno);
}
int
remote_target::remote_hostio_unlink (inferior *inf, const char *filename,
- int *remote_errno)
+ fileio_error *remote_errno)
{
struct remote_state *rs = get_remote_state ();
char *p = rs->buf.data ();
int
remote_target::fileio_unlink (struct inferior *inf, const char *filename,
- int *remote_errno)
+ fileio_error *remote_errno)
{
return remote_hostio_unlink (inf, filename, remote_errno);
}
gdb::optional<std::string>
remote_target::fileio_readlink (struct inferior *inf, const char *filename,
- int *remote_errno)
+ fileio_error *remote_errno)
{
struct remote_state *rs = get_remote_state ();
char *p = rs->buf.data ();
/* Implementation of to_fileio_fstat. */
int
-remote_target::fileio_fstat (int fd, struct stat *st, int *remote_errno)
+remote_target::fileio_fstat (int fd, struct stat *st, fileio_error *remote_errno)
{
struct remote_state *rs = get_remote_state ();
char *p = rs->buf.data ();
if (ps == PACKET_SUPPORT_UNKNOWN)
{
- int fd, remote_errno;
+ int fd;
+ fileio_error remote_errno;
/* Try opening a file to probe support. The supplied
filename is irrelevant, we only care about whether
}
static int
-remote_fileio_errno_to_host (int errnum)
+remote_fileio_errno_to_host (fileio_error errnum)
{
switch (errnum)
{
}
static char *
-remote_hostio_error (int errnum)
+remote_hostio_error (fileio_error errnum)
{
int host_error = remote_fileio_errno_to_host (errnum);
{
try
{
- int remote_errno;
+ fileio_error remote_errno;
m_remote->remote_hostio_close (m_fd, &remote_errno);
}
catch (...)
remote_target::remote_file_put (const char *local_file, const char *remote_file,
int from_tty)
{
- int retcode, remote_errno, bytes, io_size;
+ int retcode, bytes, io_size;
+ fileio_error remote_errno;
int bytes_in_buffer;
int saw_eof;
ULONGEST offset;
remote_target::remote_file_get (const char *remote_file, const char *local_file,
int from_tty)
{
- int remote_errno, bytes, io_size;
+ fileio_error remote_errno;
+ int bytes, io_size;
ULONGEST offset;
scoped_remote_fd fd
void
remote_target::remote_file_delete (const char *remote_file, int from_tty)
{
- int retcode, remote_errno;
+ int retcode;
+ fileio_error remote_errno;
retcode = remote_hostio_unlink (NULL, remote_file, &remote_errno);
if (retcode == -1)
void
sparc64_forget_process (pid_t pid)
{
- int target_errno;
+ fileio_error target_errno;
for (auto pit = adi_proc_list.before_begin (),
it = std::next (pit);
char cl_name[MAX_PROC_NAME_SIZE];
snprintf (cl_name, sizeof(cl_name), "/proc/%ld/adi/tags", (long) pid);
- int target_errno;
+ fileio_error target_errno;
proc->stat.tag_fd = target_fileio_open (NULL, cl_name, O_RDWR|O_EXCL,
false, 0, &target_errno);
return proc->stat.tag_fd;
paddress (target_gdbarch (), vaddr * ast.blksize));
}
- int target_errno;
+ fileio_error target_errno;
return target_fileio_pread (fd, tags, size, vaddr, &target_errno);
}
paddress (target_gdbarch (), vaddr * ast.blksize));
}
- int target_errno;
+ fileio_error target_errno;
return target_fileio_pwrite (fd, tags, size, vaddr, &target_errno);
}
int
target_ops::fileio_open (struct inferior *inf, const char *filename,
int flags, int mode, int warn_if_slow,
- int *target_errno)
+ fileio_error *target_errno)
{
*target_errno = FILEIO_ENOSYS;
return -1;
int
target_ops::fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
- ULONGEST offset, int *target_errno)
+ ULONGEST offset, fileio_error *target_errno)
{
*target_errno = FILEIO_ENOSYS;
return -1;
int
target_ops::fileio_pread (int fd, gdb_byte *read_buf, int len,
- ULONGEST offset, int *target_errno)
+ ULONGEST offset, fileio_error *target_errno)
{
*target_errno = FILEIO_ENOSYS;
return -1;
}
int
-target_ops::fileio_fstat (int fd, struct stat *sb, int *target_errno)
+target_ops::fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno)
{
*target_errno = FILEIO_ENOSYS;
return -1;
}
int
-target_ops::fileio_close (int fd, int *target_errno)
+target_ops::fileio_close (int fd, fileio_error *target_errno)
{
*target_errno = FILEIO_ENOSYS;
return -1;
int
target_ops::fileio_unlink (struct inferior *inf, const char *filename,
- int *target_errno)
+ fileio_error *target_errno)
{
*target_errno = FILEIO_ENOSYS;
return -1;
gdb::optional<std::string>
target_ops::fileio_readlink (struct inferior *inf, const char *filename,
- int *target_errno)
+ fileio_error *target_errno)
{
*target_errno = FILEIO_ENOSYS;
return {};
int
target_fileio_open (struct inferior *inf, const char *filename,
- int flags, int mode, bool warn_if_slow, int *target_errno)
+ int flags, int mode, bool warn_if_slow, fileio_error *target_errno)
{
for (target_ops *t = default_fileio_target (); t != NULL; t = t->beneath ())
{
int
target_fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
- ULONGEST offset, int *target_errno)
+ ULONGEST offset, fileio_error *target_errno)
{
fileio_fh_t *fh = fileio_fd_to_fh (fd);
int ret = -1;
if (fh->is_closed ())
- *target_errno = EBADF;
+ *target_errno = FILEIO_EBADF;
else if (fh->target == NULL)
- *target_errno = EIO;
+ *target_errno = FILEIO_EIO;
else
ret = fh->target->fileio_pwrite (fh->target_fd, write_buf,
len, offset, target_errno);
int
target_fileio_pread (int fd, gdb_byte *read_buf, int len,
- ULONGEST offset, int *target_errno)
+ ULONGEST offset, fileio_error *target_errno)
{
fileio_fh_t *fh = fileio_fd_to_fh (fd);
int ret = -1;
if (fh->is_closed ())
- *target_errno = EBADF;
+ *target_errno = FILEIO_EBADF;
else if (fh->target == NULL)
- *target_errno = EIO;
+ *target_errno = FILEIO_EIO;
else
ret = fh->target->fileio_pread (fh->target_fd, read_buf,
len, offset, target_errno);
/* See target.h. */
int
-target_fileio_fstat (int fd, struct stat *sb, int *target_errno)
+target_fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno)
{
fileio_fh_t *fh = fileio_fd_to_fh (fd);
int ret = -1;
if (fh->is_closed ())
- *target_errno = EBADF;
+ *target_errno = FILEIO_EBADF;
else if (fh->target == NULL)
- *target_errno = EIO;
+ *target_errno = FILEIO_EIO;
else
ret = fh->target->fileio_fstat (fh->target_fd, sb, target_errno);
/* See target.h. */
int
-target_fileio_close (int fd, int *target_errno)
+target_fileio_close (int fd, fileio_error *target_errno)
{
fileio_fh_t *fh = fileio_fd_to_fh (fd);
int ret = -1;
if (fh->is_closed ())
- *target_errno = EBADF;
+ *target_errno = FILEIO_EBADF;
else
{
if (fh->target != NULL)
int
target_fileio_unlink (struct inferior *inf, const char *filename,
- int *target_errno)
+ fileio_error *target_errno)
{
for (target_ops *t = default_fileio_target (); t != NULL; t = t->beneath ())
{
gdb::optional<std::string>
target_fileio_readlink (struct inferior *inf, const char *filename,
- int *target_errno)
+ fileio_error *target_errno)
{
for (target_ops *t = default_fileio_target (); t != NULL; t = t->beneath ())
{
{
if (m_fd >= 0)
{
- int target_errno;
+ fileio_error target_errno;
target_fileio_close (m_fd, &target_errno);
}
size_t buf_alloc, buf_pos;
gdb_byte *buf;
LONGEST n;
- int target_errno;
+ fileio_error target_errno;
scoped_target_fd fd (target_fileio_open (inf, filename, FILEIO_O_RDONLY,
0700, false, &target_errno));
#include "command.h"
#include "disasm-flags.h"
#include "tracepoint.h"
+#include "gdbsupport/fileio.h"
#include "gdbsupport/break-common.h" /* For enum target_hw_bp_type. */
*TARGET_ERRNO). */
virtual int fileio_open (struct inferior *inf, const char *filename,
int flags, int mode, int warn_if_slow,
- int *target_errno);
+ fileio_error *target_errno);
/* Write up to LEN bytes from WRITE_BUF to FD on the target.
Return the number of bytes written, or -1 if an error occurs
(and set *TARGET_ERRNO). */
virtual int fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
- ULONGEST offset, int *target_errno);
+ ULONGEST offset, fileio_error *target_errno);
/* Read up to LEN bytes FD on the target into READ_BUF.
Return the number of bytes read, or -1 if an error occurs
(and set *TARGET_ERRNO). */
virtual int fileio_pread (int fd, gdb_byte *read_buf, int len,
- ULONGEST offset, int *target_errno);
+ ULONGEST offset, fileio_error *target_errno);
/* Get information about the file opened as FD and put it in
SB. Return 0 on success, or -1 if an error occurs (and set
*TARGET_ERRNO). */
- virtual int fileio_fstat (int fd, struct stat *sb, int *target_errno);
+ virtual int fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno);
/* Close FD on the target. Return 0, or -1 if an error occurs
(and set *TARGET_ERRNO). */
- virtual int fileio_close (int fd, int *target_errno);
+ virtual int fileio_close (int fd, fileio_error *target_errno);
/* Unlink FILENAME on the target, in the filesystem as seen by
INF. If INF is NULL, use the filesystem seen by the debugger
-1 if an error occurs (and set *TARGET_ERRNO). */
virtual int fileio_unlink (struct inferior *inf,
const char *filename,
- int *target_errno);
+ fileio_error *target_errno);
/* Read value of symbolic link FILENAME on the target, in the
filesystem as seen by INF. If INF is NULL, use the filesystem
occurs (and set *TARGET_ERRNO). */
virtual gdb::optional<std::string> fileio_readlink (struct inferior *inf,
const char *filename,
- int *target_errno);
+ fileio_error *target_errno);
/* Implement the "info proc" command. Returns true if the target
actually implemented the command, false otherwise. */
extern int target_fileio_open (struct inferior *inf,
const char *filename, int flags,
int mode, bool warn_if_slow,
- int *target_errno);
+ fileio_error *target_errno);
/* Write up to LEN bytes from WRITE_BUF to FD on the target.
Return the number of bytes written, or -1 if an error occurs
(and set *TARGET_ERRNO). */
extern int target_fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
- ULONGEST offset, int *target_errno);
+ ULONGEST offset, fileio_error *target_errno);
/* Read up to LEN bytes FD on the target into READ_BUF.
Return the number of bytes read, or -1 if an error occurs
(and set *TARGET_ERRNO). */
extern int target_fileio_pread (int fd, gdb_byte *read_buf, int len,
- ULONGEST offset, int *target_errno);
+ ULONGEST offset, fileio_error *target_errno);
/* Get information about the file opened as FD on the target
and put it in SB. Return 0 on success, or -1 if an error
occurs (and set *TARGET_ERRNO). */
extern int target_fileio_fstat (int fd, struct stat *sb,
- int *target_errno);
+ fileio_error *target_errno);
/* Close FD on the target. Return 0, or -1 if an error occurs
(and set *TARGET_ERRNO). */
-extern int target_fileio_close (int fd, int *target_errno);
+extern int target_fileio_close (int fd, fileio_error *target_errno);
/* Unlink FILENAME on the target, in the filesystem as seen by INF.
If INF is NULL, use the filesystem seen by the debugger (GDB or,
occurs (and set *TARGET_ERRNO). */
extern int target_fileio_unlink (struct inferior *inf,
const char *filename,
- int *target_errno);
+ fileio_error *target_errno);
/* Read value of symbolic link FILENAME on the target, in the
filesystem as seen by INF. If INF is NULL, use the filesystem seen
Return a null-terminated string allocated via xmalloc, or NULL if
an error occurs (and set *TARGET_ERRNO). */
extern gdb::optional<std::string> target_fileio_readlink
- (struct inferior *inf, const char *filename, int *target_errno);
+ (struct inferior *inf, const char *filename, fileio_error *target_errno);
/* Read target file FILENAME, in the filesystem as seen by INF. If
INF is NULL, use the filesystem seen by the debugger (GDB or, for
/* See fileio.h. */
-int
+fileio_error
host_to_fileio_error (int error)
{
switch (error)
#define FILEIO_SEEK_END 2
/* errno values */
-#define FILEIO_EPERM 1
-#define FILEIO_ENOENT 2
-#define FILEIO_EINTR 4
-#define FILEIO_EIO 5
-#define FILEIO_EBADF 9
-#define FILEIO_EACCES 13
-#define FILEIO_EFAULT 14
-#define FILEIO_EBUSY 16
-#define FILEIO_EEXIST 17
-#define FILEIO_ENODEV 19
-#define FILEIO_ENOTDIR 20
-#define FILEIO_EISDIR 21
-#define FILEIO_EINVAL 22
-#define FILEIO_ENFILE 23
-#define FILEIO_EMFILE 24
-#define FILEIO_EFBIG 27
-#define FILEIO_ENOSPC 28
-#define FILEIO_ESPIPE 29
-#define FILEIO_EROFS 30
-#define FILEIO_ENOSYS 88
-#define FILEIO_ENAMETOOLONG 91
-#define FILEIO_EUNKNOWN 9999
+enum fileio_error
+{
+ FILEIO_SUCCESS = 0,
+ FILEIO_EPERM = 1,
+ FILEIO_ENOENT = 2,
+ FILEIO_EINTR = 4,
+ FILEIO_EIO = 5,
+ FILEIO_EBADF = 9,
+ FILEIO_EACCES = 13,
+ FILEIO_EFAULT = 14,
+ FILEIO_EBUSY = 16,
+ FILEIO_EEXIST = 17,
+ FILEIO_ENODEV = 19,
+ FILEIO_ENOTDIR = 20,
+ FILEIO_EISDIR = 21,
+ FILEIO_EINVAL = 22,
+ FILEIO_ENFILE = 23,
+ FILEIO_EMFILE = 24,
+ FILEIO_EFBIG = 27,
+ FILEIO_ENOSPC = 28,
+ FILEIO_ESPIPE = 29,
+ FILEIO_EROFS = 30,
+ FILEIO_ENOSYS = 88,
+ FILEIO_ENAMETOOLONG = 91,
+ FILEIO_EUNKNOWN = 9999,
+};
#define FIO_INT_LEN 4
#define FIO_UINT_LEN 4
/* Convert a host-format errno value to a File-I/O error number. */
-extern int host_to_fileio_error (int error);
+extern fileio_error host_to_fileio_error (int error);
/* Convert File-I/O open flags FFLAGS to host format, storing
the result in *FLAGS. Return 0 on success, -1 on error. */