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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [stdio/] [fwrite.c] - Blame information for rev 283

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

Line No. Rev Author Line
1 207 jeremybenn
/*
2
 * Copyright (c) 1990 The Regents of the University of California.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms are permitted
6
 * provided that the above copyright notice and this paragraph are
7
 * duplicated in all such forms and that any documentation,
8
 * advertising materials, and other materials related to such
9
 * distribution and use acknowledge that the software was developed
10
 * by the University of California, Berkeley.  The name of the
11
 * University may not be used to endorse or promote products derived
12
 * from this software without specific prior written permission.
13
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
 
18
/*
19
FUNCTION
20
<<fwrite>>---write array elements
21
 
22
INDEX
23
        fwrite
24
INDEX
25
        _fwrite_r
26
 
27
ANSI_SYNOPSIS
28
        #include <stdio.h>
29
        size_t fwrite(const void *<[buf]>, size_t <[size]>,
30
                      size_t <[count]>, FILE *<[fp]>);
31
 
32
        #include <stdio.h>
33
        size_t _fwrite_r(struct _reent *<[ptr]>, const void *<[buf]>, size_t <[size]>,
34
                      size_t <[count]>, FILE *<[fp]>);
35
 
36
TRAD_SYNOPSIS
37
        #include <stdio.h>
38
        size_t fwrite(<[buf]>, <[size]>, <[count]>, <[fp]>)
39
        char *<[buf]>;
40
        size_t <[size]>;
41
        size_t <[count]>;
42
        FILE *<[fp]>;
43
 
44
        #include <stdio.h>
45
        size_t _fwrite_r(<[ptr]>, <[buf]>, <[size]>, <[count]>, <[fp]>)
46
        struct _reent *<[ptr]>;
47
        char *<[buf]>;
48
        size_t <[size]>;
49
        size_t <[count]>;
50
        FILE *<[fp]>;
51
 
52
DESCRIPTION
53
<<fwrite>> attempts to copy, starting from the memory location
54
<[buf]>, <[count]> elements (each of size <[size]>) into the file or
55
stream identified by <[fp]>.  <<fwrite>> may copy fewer elements than
56
<[count]> if an error intervenes.
57
 
58
<<fwrite>> also advances the file position indicator (if any) for
59
<[fp]> by the number of @emph{characters} actually written.
60
 
61
<<_fwrite_r>> is simply the reentrant version of <<fwrite>> that
62
takes an additional reentrant structure argument: <[ptr]>.
63
 
64
RETURNS
65
If <<fwrite>> succeeds in writing all the elements you specify, the
66
result is the same as the argument <[count]>.  In any event, the
67
result is the number of complete elements that <<fwrite>> copied to
68
the file.
69
 
70
PORTABILITY
71
ANSI C requires <<fwrite>>.
72
 
73
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
74
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
75
*/
76
 
77
#if defined(LIBC_SCCS) && !defined(lint)
78
static char sccsid[] = "%W% (Berkeley) %G%";
79
#endif /* LIBC_SCCS and not lint */
80
 
81
#include <_ansi.h>
82
#include <stdio.h>
83
#include <string.h>
84
#if 0
85
#include <sys/stdc.h>
86
#endif
87
#include "local.h"
88
#if 1
89
#include "fvwrite.h"
90
#endif
91
 
92
/*
93
 * Write `count' objects (each size `size') from memory to the given file.
94
 * Return the number of whole objects written.
95
 */
96
 
97
size_t
98
_DEFUN(_fwrite_r, (ptr, buf, size, count, fp),
99
       struct _reent * ptr _AND
100
       _CONST _PTR buf _AND
101
       size_t size     _AND
102
       size_t count    _AND
103
       FILE * fp)
104
{
105
  size_t n;
106
  struct __suio uio;
107
  struct __siov iov;
108
 
109
  iov.iov_base = buf;
110
  uio.uio_resid = iov.iov_len = n = count * size;
111
  uio.uio_iov = &iov;
112
  uio.uio_iovcnt = 1;
113
 
114
  /*
115
   * The usual case is success (__sfvwrite_r returns 0);
116
   * skip the divide if this happens, since divides are
117
   * generally slow and since this occurs whenever size==0.
118
   */
119
 
120
  CHECK_INIT(ptr, fp);
121
 
122
  _flockfile (fp);
123
  ORIENT (fp, -1);
124
  if (__sfvwrite_r (ptr, fp, &uio) == 0)
125
    {
126
      _funlockfile (fp);
127
      return count;
128
    }
129
  _funlockfile (fp);
130
  return (n - uio.uio_resid) / size;
131
}
132
 
133
#ifndef _REENT_ONLY
134
size_t
135
_DEFUN(fwrite, (buf, size, count, fp),
136
       _CONST _PTR buf _AND
137
       size_t size     _AND
138
       size_t count    _AND
139
       FILE * fp)
140
{
141
  return _fwrite_r (_REENT, buf, size, count, fp);
142
}
143
#endif

powered by: WebSVN 2.1.0

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