source: trunk/libs/newlib/src/newlib/libc/sys/linux/pwrite64.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.2 KB
Line 
1/*
2FUNCTION
3<<pwrite64>>---write a large file from specified position
4
5INDEX
6        pwrite64
7
8SYNOPSIS
9        #include <unistd.h>
10        ssize_t pwrite64(int <[fd]>, void *<[buf]>, size_t <[n]>, loff_t <[off]>);
11
12DESCRIPTION
13The <<pwrite64>> function is similar to <<pwrite>>.  The only difference is
14that it operates on large files and so takes a 64-bit offset.  Like <<pwrite>>>,
15the file position is unchanged by the function (i.e. the file position
16is the same before and after a call to <<pwrite>>).
17
18RETURNS
19<<pwrite64>> returns the number of bytes written or <<-1>> if failure occurred.
20
21PORTABILITY
22<<pwrite64>> is an EL/IX extension.
23
24Supporting OS subroutine required: <<write>>, <<lseek64>>.
25*/
26
27#include <_ansi.h>
28#include <unistd.h>
29#include <reent.h>
30#include <machine/weakalias.h>
31
32ssize_t
33__libc_pwrite64 (int fd,
34     void *buf,
35     size_t n,
36     loff_t off)
37{
38  loff_t cur_pos;
39  _READ_WRITE_RETURN_TYPE num_written;
40 
41  if ((cur_pos = lseek64 (fd, 0, SEEK_CUR)) == (loff_t)-1)
42    return -1;
43
44  if (lseek64 (fd, off, SEEK_SET) == (loff_t)-1)
45    return -1;
46
47  num_written = write (fd, buf, n);
48
49  if (lseek64 (fd, cur_pos, SEEK_SET) == (loff_t)-1)
50    return -1;
51
52  return (ssize_t)num_written;
53}
54weak_alias(__libc_pwrite64,pwrite64)
55
Note: See TracBrowser for help on using the repository browser.