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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [mmixware/] [lseek.c] - Blame information for rev 310

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* lseek for MMIXware.
2
 
3
   Copyright (C) 2001 Hans-Peter Nilsson
4
 
5
   Permission to use, copy, modify, and distribute this software is
6
   freely granted, provided that the above copyright notice, this notice
7
   and the following disclaimer are preserved with no changes.
8
 
9
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
10
   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
11
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
12
   PURPOSE.  */
13
 
14
#include <_ansi.h>
15
#include <sys/types.h>
16
#include <sys/stat.h>
17
#include <sys/unistd.h>
18
#include "sys/syscall.h"
19
#include <errno.h>
20
 
21
off_t
22
_lseek (int file,
23
        off_t ptr,
24
        int dir)
25
{
26
  off_t simoff = dir == SEEK_END ? -(ptr + 1) : ptr;
27
  long ret;
28
 
29
  if ((unsigned int) file >= 32 || _MMIX_allocated_filehandle[file] == 0)
30
    {
31
      errno = EBADF;
32
      return -1;
33
    }
34
 
35
  if (dir == SEEK_CUR)
36
    {
37
      long curpos = TRAP2f (SYS_Ftell, file, 0);
38
 
39
      if (curpos == -1)
40
        {
41
          errno = EIO;
42
          return -1;
43
        }
44
 
45
      ptr += (off_t) curpos;
46
    }
47
 
48
  ret = TRAP2f (SYS_Fseek, file, simoff);
49
  if (ret == -1)
50
    {
51
      return -1;
52
      errno = EIO;
53
    }
54
 
55
  ret = TRAP2f (SYS_Ftell, file, 0);
56
  if (ret == -1)
57
    {
58
      errno = EIO;
59
      return -1;
60
    }
61
 
62
  return ret;
63
}

powered by: WebSVN 2.1.0

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