OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [sys/] [mmixware/] [lseek.c] - Diff between revs 1010 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 1010 Rev 1765
/* lseek for MMIXware.
/* lseek for MMIXware.
 
 
   Copyright (C) 2001 Hans-Peter Nilsson
   Copyright (C) 2001 Hans-Peter Nilsson
 
 
   Permission to use, copy, modify, and distribute this software is
   Permission to use, copy, modify, and distribute this software is
   freely granted, provided that the above copyright notice, this notice
   freely granted, provided that the above copyright notice, this notice
   and the following disclaimer are preserved with no changes.
   and the following disclaimer are preserved with no changes.
 
 
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   PURPOSE.  */
   PURPOSE.  */
 
 
#include <_ansi.h>
#include <_ansi.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/unistd.h>
#include <sys/unistd.h>
#include "sys/syscall.h"
#include "sys/syscall.h"
#include <errno.h>
#include <errno.h>
 
 
off_t
off_t
_lseek (int file,
_lseek (int file,
        off_t ptr,
        off_t ptr,
        int dir)
        int dir)
{
{
  off_t simoff = dir == SEEK_END ? -(ptr + 1) : ptr;
  off_t simoff = dir == SEEK_END ? -(ptr + 1) : ptr;
  long ret;
  long ret;
 
 
  if ((unsigned int) file >= 32 || _MMIX_allocated_filehandle[file] == 0)
  if ((unsigned int) file >= 32 || _MMIX_allocated_filehandle[file] == 0)
    {
    {
      errno = EBADF;
      errno = EBADF;
      return -1;
      return -1;
    }
    }
 
 
  if (dir == SEEK_CUR)
  if (dir == SEEK_CUR)
    {
    {
      long curpos = TRAP2f (SYS_Ftell, file, 0);
      long curpos = TRAP2f (SYS_Ftell, file, 0);
 
 
      if (curpos == -1)
      if (curpos == -1)
        {
        {
          errno = EIO;
          errno = EIO;
          return -1;
          return -1;
        }
        }
 
 
      ptr += (off_t) curpos;
      ptr += (off_t) curpos;
    }
    }
 
 
  ret = TRAP2f (SYS_Fseek, file, simoff);
  ret = TRAP2f (SYS_Fseek, file, simoff);
  if (ret == -1)
  if (ret == -1)
    {
    {
      return -1;
      return -1;
      errno = EIO;
      errno = EIO;
    }
    }
 
 
  ret = TRAP2f (SYS_Ftell, file, 0);
  ret = TRAP2f (SYS_Ftell, file, 0);
  if (ret == -1)
  if (ret == -1)
    {
    {
      errno = EIO;
      errno = EIO;
      return -1;
      return -1;
    }
    }
 
 
  return ret;
  return ret;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.