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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [newlib/] [newlib/] [libc/] [stdio/] [stdio.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
/* No user fns here.  Pesch 15apr92. */
2
 
3
/*
4
 * Copyright (c) 1990 The Regents of the University of California.
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms are permitted
8
 * provided that the above copyright notice and this paragraph are
9
 * duplicated in all such forms and that any documentation,
10
 * advertising materials, and other materials related to such
11
 * distribution and use acknowledge that the software was developed
12
 * by the University of California, Berkeley.  The name of the
13
 * University may not be used to endorse or promote products derived
14
 * from this software without specific prior written permission.
15
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18
 */
19
 
20
#include <stdio.h>
21
#include <sys/types.h>
22
#include <fcntl.h>
23
#include <sys/unistd.h>
24
#include "local.h"
25
 
26
/*
27
 * Small standard I/O/seek/close functions.
28
 * These maintain the `known seek offset' for seek optimisation.
29
 */
30
 
31
int
32
__sread (cookie, buf, n)
33
     _PTR cookie;
34
     char *buf;
35
     int n;
36
{
37
  register FILE *fp = (FILE *) cookie;
38
  register int ret;
39
 
40
  ret = _read_r (fp->_data, fp->_file, buf, n);
41
 
42
  /* If the read succeeded, update the current offset.  */
43
 
44
  if (ret >= 0)
45
    fp->_offset += ret;
46
  else
47
    fp->_flags &= ~__SOFF;      /* paranoia */
48
  return ret;
49
}
50
 
51
int
52
__swrite (cookie, buf, n)
53
     _PTR cookie;
54
     char _CONST *buf;
55
     int n;
56
{
57
  register FILE *fp = (FILE *) cookie;
58
 
59
  if (fp->_flags & __SAPP)
60
    (void) _lseek_r (fp->_data, fp->_file, (off_t) 0, SEEK_END);
61
  fp->_flags &= ~__SOFF;        /* in case O_APPEND mode is set */
62
  return _write_r (fp->_data, fp->_file, buf, n);
63
}
64
 
65
fpos_t
66
__sseek (cookie, offset, whence)
67
     _PTR cookie;
68
     fpos_t offset;
69
     int whence;
70
{
71
  register FILE *fp = (FILE *) cookie;
72
  register off_t ret;
73
 
74
  ret = _lseek_r (fp->_data, fp->_file, (off_t) offset, whence);
75
  if (ret == -1L)
76
    fp->_flags &= ~__SOFF;
77
  else
78
    {
79
      fp->_flags |= __SOFF;
80
      fp->_offset = ret;
81
    }
82
  return ret;
83
}
84
 
85
int
86
__sclose (cookie)
87
     _PTR cookie;
88
{
89
  FILE *fp = (FILE *) cookie;
90
 
91
  return _close_r (fp->_data, fp->_file);
92
}

powered by: WebSVN 2.1.0

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