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

Subversion Repositories or1k_old

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

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

Line No. Rev Author Line
1 39 lampret
/*
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
 
25
ANSI_SYNOPSIS
26
        #include <stdio.h>
27
        size_t fwrite(const void *<[buf]>, size_t <[size]>,
28
                      size_t <[count]>, FILE *<[fp]>);
29
 
30
TRAD_SYNOPSIS
31
        #include <stdio.h>
32
        size_t fwrite(<[buf]>, <[size]>, <[count]>, <[fp]>)
33
        char *<[buf]>;
34
        size_t <[size]>;
35
        size_t <[count]>;
36
        FILE *<[fp]>;
37
 
38
DESCRIPTION
39
<<fwrite>> attempts to copy, starting from the memory location
40
<[buf]>, <[count]> elements (each of size <[size]>) into the file or
41
stream identified by <[fp]>.  <<fwrite>> may copy fewer elements than
42
<[count]> if an error intervenes.
43
 
44
<<fwrite>> also advances the file position indicator (if any) for
45
<[fp]> by the number of @emph{characters} actually written.
46
 
47
RETURNS
48
If <<fwrite>> succeeds in writing all the elements you specify, the
49
result is the same as the argument <[count]>.  In any event, the
50
result is the number of complete elements that <<fwrite>> copied to
51
the file.
52
 
53
PORTABILITY
54
ANSI C requires <<fwrite>>.
55
 
56
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
57
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
58
*/
59
 
60
#if defined(LIBC_SCCS) && !defined(lint)
61
static char sccsid[] = "%W% (Berkeley) %G%";
62
#endif /* LIBC_SCCS and not lint */
63
 
64
#include <stdio.h>
65
#include <string.h>
66
#if 0
67
#include <sys/stdc.h>
68
#endif
69
#include "local.h"
70
#if 1
71
#include "fvwrite.h"
72
#endif
73
 
74
/*
75
 * Write `count' objects (each size `size') from memory to the given file.
76
 * Return the number of whole objects written.
77
 */
78
 
79
size_t
80
_DEFUN (fwrite, (buf, size, count, fp),
81
        _CONST _PTR buf _AND
82
        size_t size _AND
83
        size_t count _AND
84
        FILE * fp)
85
{
86
  size_t n;
87
  struct __suio uio;
88
  struct __siov iov;
89
 
90
  iov.iov_base = buf;
91
  uio.uio_resid = iov.iov_len = n = count * size;
92
  uio.uio_iov = &iov;
93
  uio.uio_iovcnt = 1;
94
 
95
  /*
96
   * The usual case is success (__sfvwrite returns 0);
97
   * skip the divide if this happens, since divides are
98
   * generally slow and since this occurs whenever size==0.
99
   */
100
 
101
  if (__sfvwrite (fp, &uio) == 0)
102
    return count;
103
  return (n - uio.uio_resid) / size;
104
}

powered by: WebSVN 2.1.0

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