Ejemplo n.º 1
0
/* Read value of symbolic link FILENAME on the target.  Return a
   null-terminated string allocated via xmalloc, or NULL if an error
   occurs (and set *TARGET_ERRNO).  */
static char *
inf_child_fileio_readlink (const char *filename, int *target_errno)
{
  /* We support readlink only on systems that also provide a compile-time
     maximum path length (MAXPATHLEN), at least for now.  */
#if defined (HAVE_READLINK) && defined (MAXPATHLEN)
  char buf[MAXPATHLEN - 1];
  int len;
  char *ret;

  len = readlink (filename, buf, sizeof buf);
  if (len < 0)
    {
      *target_errno = inf_child_errno_to_fileio_error (errno);
      return NULL;
    }

  ret = xmalloc (len + 1);
  memcpy (ret, buf, len);
  ret[len] = '\0';
  return ret;
#else
  *target_errno = FILEIO_ENOSYS;
  return NULL;
#endif
}
Ejemplo n.º 2
0
/* 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).  */
static int
inf_child_fileio_pread (struct target_ops *self,
			int fd, gdb_byte *read_buf, int len,
			ULONGEST offset, int *target_errno)
{
  int ret;

#ifdef HAVE_PREAD
  ret = pread (fd, read_buf, len, (long) offset);
#else
  ret = -1;
#endif
  /* If we have no pread or it failed for this file, use lseek/read.  */
  if (ret == -1)
    {
      ret = lseek (fd, (long) offset, SEEK_SET);
      if (ret != -1)
	ret = read (fd, read_buf, len);
    }

  if (ret == -1)
    *target_errno = inf_child_errno_to_fileio_error (errno);

  return ret;
}
Ejemplo n.º 3
0
/* 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).  */
static int
inf_child_fileio_pwrite (struct target_ops *self,
			 int fd, const gdb_byte *write_buf, int len,
			 ULONGEST offset, int *target_errno)
{
  int ret;

#ifdef HAVE_PWRITE
  ret = pwrite (fd, write_buf, len, (long) offset);
#else
  ret = -1;
#endif
  /* If we have no pwrite or it failed for this file, use lseek/write.  */
  if (ret == -1)
    {
      ret = lseek (fd, (long) offset, SEEK_SET);
      if (ret != -1)
	ret = write (fd, write_buf, len);
    }

  if (ret == -1)
    *target_errno = inf_child_errno_to_fileio_error (errno);

  return ret;
}
Ejemplo n.º 4
0
/* Unlink FILENAME on the target.  Return 0, or -1 if an error
   occurs (and set *TARGET_ERRNO).  */
static int
inf_child_fileio_unlink (const char *filename, int *target_errno)
{
  int ret;

  ret = unlink (filename);
  if (ret == -1)
    *target_errno = inf_child_errno_to_fileio_error (errno);

  return ret;
}
Ejemplo n.º 5
0
/* Close FD on the target.  Return 0, or -1 if an error occurs
   (and set *TARGET_ERRNO).  */
static int
inf_child_fileio_close (int fd, int *target_errno)
{
  int ret;

  ret = close (fd);
  if (ret == -1)
    *target_errno = inf_child_errno_to_fileio_error (errno);

  return ret;
}
Ejemplo n.º 6
0
/* Open FILENAME on the target, using FLAGS and MODE.  Return a
   target file descriptor, or -1 if an error occurs (and set
   *TARGET_ERRNO).  */
static int
inf_child_fileio_open (const char *filename, int flags, int mode,
		       int *target_errno)
{
  int nat_flags;
  int fd;

  if (inf_child_fileio_open_flags_to_host (flags, &nat_flags) == -1)
    {
      *target_errno = FILEIO_EINVAL;
      return -1;
    }

  /* We do not need to convert MODE, since the fileio protocol uses
     the standard values.  */
  fd = gdb_open_cloexec (filename, nat_flags, mode);
  if (fd == -1)
    *target_errno = inf_child_errno_to_fileio_error (errno);

  return fd;
}