Exemplo n.º 1
0
/* Truncate the file referenced by FD to LENGTH bytes.  */
int
__ftruncate (int fd, __off_t length)
{
  error_t err;
  if (err = HURD_DPORT_USE (fd, __file_set_size (port, length)))
    return __hurd_dfail (fd, err);
  return 0;
}
Exemplo n.º 2
0
/* Truncate FILE_NAME to LENGTH bytes.  */
int
__truncate64 (const char *file_name, off64_t length)
{
  error_t err;
  file_t file = __file_name_lookup (file_name, O_WRITE, 0);

  if (file == MACH_PORT_NULL)
    return -1;

  err = __file_set_size (file, length);
  __mach_port_deallocate (__mach_task_self (), file);

  if (err)
    return __hurd_fail (err);
  return 0;
}
Exemplo n.º 3
0
/* Create a new shared memory segment file without linking it into the
   filesystem.  Return the directory and file ports in R_DIR and R_FILE.  */
static error_t
create_shm_file (size_t size, int flags, file_t *r_dir, file_t *r_file)
{
  error_t err;
  file_t dir;
  file_t file;

  flags &= 0777;

  /* Get a port to the directory that will contain the file.  */
  dir = __file_name_lookup (SHM_DIR, 0, 0);
  if (dir == MACH_PORT_NULL)
    return errno;

  /* Create an unnamed file in the directory.  */
  err = __dir_mkfile (dir, O_RDWR, flags, &file);
  if (err)
    {
      __mach_port_deallocate (__mach_task_self (), dir);
      return err;
    }

  err = __file_set_size (file, size);
  if (err)
    {
      __mach_port_deallocate (__mach_task_self (), file);
      __mach_port_deallocate (__mach_task_self (), dir);

      return err;
    }

  *r_dir = dir;
  *r_file = file;

  return 0;
}