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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [sys/] [mmixware/] [read.c] - Blame information for rev 1773

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

Line No. Rev Author Line
1 1010 ivang
/* read 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/syscall.h"
18
#include <errno.h>
19
 
20
int
21
_read (int file,
22
       char *ptr,
23
       size_t len)
24
{
25
  long ret;
26
 
27
  if ((unsigned int) file >= 32 || _MMIX_allocated_filehandle[file] == 0)
28
    {
29
      errno = EBADF;
30
      return -1;
31
    }
32
 
33
  ret = TRAP3f (SYS_Fread, file, ptr, len);
34
 
35
  /* Map the return codes:
36
     -1-len: an error.  We return -1.
37
     0: success.  We return len.
38
     n-len: end-of-file after n chars read.  We return n. */
39
  if (ret == 0)
40
    return len;
41
 
42
  if (ret == -1 - (long) len)
43
    {
44
      /* We don't know the nature of the failure, so this is an
45
         approximation.  */
46
      errno = EIO;
47
      return -1;
48
    }
49
 
50
  return ret + len;
51
}

powered by: WebSVN 2.1.0

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