9182e26c6bee06644577c8eb618081d928075469
[reactos.git] / posix / lib / psxdll / unistd / write.c
1 /* $Id: write.c,v 1.3 2002/03/21 22:46:30 hyperion Exp $
2 */
3 /*
4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS POSIX+ Subsystem
6 * FILE: subsys/psx/lib/psxdll/unistd/write.c
7 * PURPOSE: Write on a file
8 * PROGRAMMER: KJK::Hyperion <noog@libero.it>
9 * UPDATE HISTORY:
10 * 15/02/2002: Created
11 * 21/03/2002: Implemented write() (KJK::Hyperion <noog@libero.it>)
12 */
13
14 #include <ddk/ntddk.h>
15 #include <fcntl.h>
16 #include <unistd.h>
17 #include <sys/types.h>
18 #include <psx/debug.h>
19 #include <psx/errno.h>
20 #include <psx/fdtable.h>
21
22 ssize_t write(int fildes, const void *buf, size_t nbyte)
23 {
24 __fildes_t fdDescriptor;
25 NTSTATUS nErrCode;
26 IO_STATUS_BLOCK isbStatus;
27
28 if(nbyte == 0)
29 return (0);
30
31 if(fcntl(fildes, F_GETALL, &fdDescriptor) == -1)
32 return (0);
33
34 if((fdDescriptor.OpenFlags && O_APPEND) == O_APPEND)
35 {
36 TODO("move file pointer to the end");
37 }
38
39 nErrCode = NtWriteFile
40 (
41 fdDescriptor.FileHandle,
42 NULL,
43 NULL,
44 NULL,
45 &isbStatus,
46 (PVOID)buf,
47 nbyte,
48 NULL,
49 NULL
50 );
51
52 if(!NT_SUCCESS(nErrCode))
53 {
54 errno = __status_to_errno(nErrCode);
55 return (0);
56 }
57
58 return (isbStatus.Information);
59 }
60
61 /* EOF */
62