1 /* $Id: read.c,v 1.4 2002/10/29 04:45:48 rex Exp $
4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS POSIX+ Subsystem
6 * FILE: subsys/psx/lib/psxdll/unistd/read.c
7 * PURPOSE: Read from a file
8 * PROGRAMMER: KJK::Hyperion <noog@libero.it>
13 #include <ddk/ntddk.h>
16 #include <sys/types.h>
17 #include <psx/debug.h>
18 #include <psx/errno.h>
20 ssize_t
__read(int fildes
, void *buf
, size_t nbyte
, off_t
*offset
)
24 IO_STATUS_BLOCK isbStatus
;
26 /* get the file handle for the specified file descriptor */
27 if(fcntl(fildes
, F_GETFH
, &hFile
) == -1)
32 /* NT always moves the file pointer, while Unix pread() must not: we have to
33 duplicate the handle and work on the duplicate */ /* FIXME? better save
34 the file position and restore it later? */
37 /* duplicate the handle */
38 nErrCode
= NtDuplicateObject
50 if(!NT_SUCCESS(nErrCode
))
52 errno
= __status_to_errno(nErrCode
);
56 /* read data from file at the specified offset */
66 (PLARGE_INTEGER
)offset
,
73 if(!NT_SUCCESS(nErrCode
))
75 errno
= __status_to_errno(nErrCode
);
81 /* read data from file at the current offset */
96 if(!NT_SUCCESS(nErrCode
))
98 errno
= __status_to_errno(nErrCode
);
103 return ((ssize_t
)isbStatus
.Information
);
106 ssize_t
read(int fildes
, void *buf
, size_t nbyte
)
108 return (__read(fildes
, buf
, nbyte
, NULL
));
111 ssize_t
pread(int fildes
, void *buf
, size_t nbyte
, off_t offset
)
113 return (__read(fildes
, buf
, nbyte
, &offset
));