[ad28599] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Petr Koupy
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup libposix
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
[4cf8ca6] | 32 | /** @file File control.
|
---|
[ad28599] | 33 | */
|
---|
| 34 |
|
---|
| 35 | #define LIBPOSIX_INTERNAL
|
---|
| 36 |
|
---|
[9b1503e] | 37 | #include "internal/common.h"
|
---|
[ad28599] | 38 | #include "fcntl.h"
|
---|
[ec18957a] | 39 |
|
---|
[4ec6820] | 40 | #include "libc/unistd.h"
|
---|
| 41 | #include "libc/vfs/vfs.h"
|
---|
[ec18957a] | 42 | #include "errno.h"
|
---|
[ad28599] | 43 |
|
---|
| 44 | /**
|
---|
[4ec6820] | 45 | * Performs set of operations on the opened files.
|
---|
| 46 | *
|
---|
| 47 | * @param fd File descriptor of the opened file.
|
---|
| 48 | * @param cmd Operation to carry out.
|
---|
| 49 | * @return Non-negative on success. Might have special meaning corresponding
|
---|
| 50 | * to the requested operation.
|
---|
[ad28599] | 51 | */
|
---|
| 52 | int posix_fcntl(int fd, int cmd, ...)
|
---|
| 53 | {
|
---|
[4ec6820] | 54 | int flags;
|
---|
| 55 |
|
---|
| 56 | switch (cmd) {
|
---|
| 57 | case F_DUPFD:
|
---|
[f00af83] | 58 | case F_DUPFD_CLOEXEC:
|
---|
| 59 | /* VFS currently does not provide the functionality to duplicate
|
---|
| 60 | * opened file descriptor. */
|
---|
| 61 | // FIXME: implement this once dup() is available
|
---|
| 62 | errno = ENOTSUP;
|
---|
| 63 | return -1;
|
---|
[4ec6820] | 64 | case F_GETFD:
|
---|
| 65 | /* FD_CLOEXEC is not supported. There are no other flags. */
|
---|
| 66 | return 0;
|
---|
| 67 | case F_SETFD:
|
---|
| 68 | /* FD_CLOEXEC is not supported. Ignore arguments and report success. */
|
---|
| 69 | return 0;
|
---|
| 70 | case F_GETFL:
|
---|
| 71 | /* File status flags (i.e. O_APPEND) are currently private to the
|
---|
| 72 | * VFS server so it cannot be easily retrieved. */
|
---|
| 73 | flags = 0;
|
---|
| 74 | /* File access flags are currently not supported for file descriptors.
|
---|
| 75 | * Provide full access. */
|
---|
| 76 | flags |= O_RDWR;
|
---|
| 77 | return flags;
|
---|
| 78 | case F_SETFL:
|
---|
| 79 | /* File access flags are currently not supported for file descriptors.
|
---|
| 80 | * Ignore arguments and report success. */
|
---|
| 81 | return 0;
|
---|
| 82 | case F_GETOWN:
|
---|
| 83 | case F_SETOWN:
|
---|
| 84 | case F_GETLK:
|
---|
| 85 | case F_SETLK:
|
---|
| 86 | case F_SETLKW:
|
---|
| 87 | /* Signals (SIGURG) and file locks are not supported. */
|
---|
| 88 | errno = ENOTSUP;
|
---|
| 89 | return -1;
|
---|
| 90 | default:
|
---|
| 91 | /* Unknown command */
|
---|
| 92 | errno = EINVAL;
|
---|
| 93 | return -1;
|
---|
| 94 | }
|
---|
[ad28599] | 95 | }
|
---|
| 96 |
|
---|
| 97 | /** @}
|
---|
| 98 | */
|
---|