source: trunk/libs/newlib/src/newlib/libc/sys/mmixware/read.c @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.3 KB
Line 
1/* 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
20int
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  if (isatty(file))
34    {
35      ret = TRAP3f (SYS_Fgets, file, ptr, len);
36
37      if (ret == -1)
38        return 0;
39
40      return ret;
41    }
42
43  ret = TRAP3f (SYS_Fread, file, ptr, len);
44
45  /* Map the return codes:
46     -1-len: an error.  We return -1.
47     0: success.  We return len.
48     n-len: end-of-file after n chars read.  We return n. */
49  if (ret == 0)
50    return len;
51
52  if (ret == -1 - (long) len)
53    {
54      /* We don't know the nature of the failure, so this is an
55         approximation.  */
56      errno = EIO;
57      return -1;
58    }
59
60  return ret + len;
61}
Note: See TracBrowser for help on using the repository browser.