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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [newlib-1.18.0/] [newlib/] [libc/] [unix/] [pwrite.c] - Blame information for rev 829

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
#ifndef _NO_PWRITE
2
/*
3
FUNCTION
4
<<pwrite>>---write a file from specified position
5
 
6
INDEX
7
        pwrite
8
INDEX
9
        _pwrite_r
10
 
11
ANSI_SYNOPSIS
12
        #include <unistd.h>
13
        ssize_t pwrite(int <[fd]>, const void *<[buf]>,
14
                       size_t <[n]>, off_t <[off]>);
15
        ssize_t _pwrite_r(struct _reent *<[rptr]>, int <[fd]>,
16
                          const void *<[buf]>, size_t <[n]>, off_t <[off]>);
17
 
18
TRAD_SYNOPSIS
19
        #include <unistd.h>
20
        ssize_t pwrite(<[fd]>, <[buf]>, <[n]>, <[off]>)
21
        int <[fd]>;
22
        const void *<[buf]>;
23
        size_t <[n]>;
24
        off_t <[off]>;
25
 
26
        ssize_t _pwrite_r(<[rptr]>, <[fd]>, <[buf]>, <[n]>, <[off]>)
27
        struct _reent *<[rptr]>;
28
        int <[fd]>;
29
        const void *<[buf]>;
30
        size_t <[n]>;
31
        off_t <[off]>;
32
 
33
DESCRIPTION
34
The <<pwrite>> function is similar to <<write>>.  One difference is that
35
<<pwrite>> has an additional parameter <[off]> which is the offset to
36
position in the file before writing.  The function also differs in that
37
the file position is unchanged by the function (i.e. the file position
38
is the same before and after a call to <<pwrite>>).
39
 
40
The <<_pwrite_r>> function is the same as <<pwrite>>, only a reentrant
41
struct pointer <[rptr]> is provided to preserve reentrancy.
42
 
43
RETURNS
44
<<pwrite>> returns the number of bytes written or <<-1>> if failure occurred.
45
 
46
PORTABILITY
47
<<pwrite>> is non-ANSI and is specified by the Single Unix Specification.
48
 
49
Supporting OS subroutine required: <<write>>, <<lseek>>.
50
*/
51
 
52
#include <_ansi.h>
53
#include <unistd.h>
54
#include <reent.h>
55
 
56
ssize_t
57
_DEFUN (_pwrite_r, (rptr, fd, buf, n, off),
58
     struct _reent *rptr _AND
59
     int fd _AND
60
     _CONST _PTR buf _AND
61
     size_t n _AND
62
     off_t off)
63
{
64
  off_t cur_pos;
65
  _READ_WRITE_RETURN_TYPE num_written;
66
 
67
  if ((cur_pos = _lseek_r (rptr, fd, 0, SEEK_CUR)) == (off_t)-1)
68
    return -1;
69
 
70
  if (_lseek_r (rptr, fd, off, SEEK_SET) == (off_t)-1)
71
    return -1;
72
 
73
  num_written = _write_r (rptr, fd, buf, n);
74
 
75
  if (_lseek_r (rptr, fd, cur_pos, SEEK_SET) == (off_t)-1)
76
    return -1;
77
 
78
  return (ssize_t)num_written;
79
}
80
 
81
#ifndef _REENT_ONLY
82
 
83
ssize_t
84
_DEFUN (pwrite, (fd, buf, n, off),
85
     int fd _AND
86
     _CONST _PTR buf _AND
87
     size_t n _AND
88
     off_t off)
89
{
90
  return _pwrite_r (_REENT, fd, buf, n, off);
91
}
92
 
93
#endif /* !_REENT_ONLY  */
94
#endif /* !_NO_PWRITE  */

powered by: WebSVN 2.1.0

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