2 * posix.c: Posix-specific support.
5 * Dick Porter (dick@ximian.com)
7 * (C) 2002 Ximian, Inc.
8 * Copyright (c) 2002-2009 Novell, Inc.
18 #include <sys/types.h>
21 #include <mono/io-layer/wapi.h>
22 #include <mono/io-layer/wapi-private.h>
23 #include <mono/io-layer/handles-private.h>
24 #include <mono/io-layer/io-private.h>
27 convert_from_flags(int flags
)
32 #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
35 if((flags
& O_ACCMODE
) == O_RDONLY
) {
36 fileaccess
=GENERIC_READ
;
37 } else if ((flags
& O_ACCMODE
) == O_WRONLY
) {
38 fileaccess
=GENERIC_WRITE
;
39 } else if ((flags
& O_ACCMODE
) == O_RDWR
) {
40 fileaccess
=GENERIC_READ
|GENERIC_WRITE
;
43 g_message("%s: Can't figure out flags 0x%x", __func__
, flags
);
47 /* Maybe sort out create mode too */
53 gpointer
_wapi_stdhandle_create (int fd
, const gchar
*name
)
55 struct _WapiHandle_file file_handle
= {0};
60 g_message("%s: creating standard handle type %s, fd %d", __func__
,
64 /* Check if fd is valid */
66 flags
=fcntl(fd
, F_GETFL
);
67 } while (flags
== -1 && errno
== EINTR
);
70 /* Invalid fd. Not really much point checking for EBADF
74 g_message("%s: fcntl error on fd %d: %s", __func__
, fd
,
78 SetLastError (_wapi_get_win32_file_error (errno
));
79 return(INVALID_HANDLE_VALUE
);
82 file_handle
.filename
= g_strdup(name
);
83 /* some default security attributes might be needed */
84 file_handle
.security_attributes
=0;
85 file_handle
.fileaccess
=convert_from_flags(flags
);
87 /* Apparently input handles can't be written to. (I don't
88 * know if output or error handles can't be read from.)
91 file_handle
.fileaccess
&= ~GENERIC_WRITE
;
94 file_handle
.sharemode
=0;
97 handle
= _wapi_handle_new_fd (WAPI_HANDLE_CONSOLE
, fd
, &file_handle
);
98 if (handle
== _WAPI_HANDLE_INVALID
) {
99 g_warning ("%s: error creating file handle", __func__
);
100 SetLastError (ERROR_GEN_FAILURE
);
101 return(INVALID_HANDLE_VALUE
);
105 g_message("%s: returning handle %p", __func__
, handle
);