1 /* 2 Copyright (C) 2001, 2004, 2005 Axis Communications AB. 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 1. Redistributions of source code must retain the above copyright 10 notice, this list of conditions and the following disclaimer. 11 12 2. Neither the name of Axis Communications nor the names of its 13 contributors may be used to endorse or promote products derived 14 from this software without specific prior written permission. 15 16 THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS 17 AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS 20 COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 POSSIBILITY OF SUCH DAMAGE. 28 */ 29 /* This file is to be kept in sync with newlib/libc/include/sys/fcntl.h, 30 on which it is based, except values used or returned by syscalls must 31 be those of the Linux/CRIS kernel. */ 32 33 #ifndef _FCNTL_ 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 #define _FCNTL_ 38 #define _FOPEN (-1) /* from sys/file.h, kernel use only */ 39 #define _FREAD 0x0001 /* read enabled */ 40 #define _FWRITE 0x0002 /* write enabled */ 41 #define _FNDELAY 0x0800 /* non blocking I/O (4.2 style) */ 42 #define _FAPPEND 0x0400 /* append (writes guaranteed at the end) */ 43 #define _FMARK 0x0010 /* internal; mark during gc() */ 44 #define _FDEFER 0x0020 /* internal; defer for next gc pass */ 45 #define _FASYNC 0x2000 /* signal pgrp when data ready */ 46 #define _FCREAT 0x0040 /* open with file create */ 47 #define _FTRUNC 0x0200 /* open with truncation */ 48 #define _FEXCL 0x0080 /* error on open if file exists */ 49 #define _FNBIO _FNONBLOCK /* non blocking I/O (sys5 style) */ 50 #define _FSYNC 0x1000 /* do all writes synchronously */ 51 #define _FNONBLOCK 0x0800 /* non blocking I/O (POSIX style) */ 52 #define _FNOCTTY 0x0100 /* don't assign a ctty on this open */ 53 54 #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) 55 56 /* 57 * Flag values for open(2) and fcntl(2) 58 * The kernel adds 1 to the open modes to turn it into some 59 * combination of FREAD and FWRITE. 60 */ 61 #define O_RDONLY 0 /* +1 == FREAD */ 62 #define O_WRONLY 1 /* +1 == FWRITE */ 63 #define O_RDWR 2 /* +1 == FREAD|FWRITE */ 64 #define O_APPEND _FAPPEND 65 #define O_CREAT _FCREAT 66 #define O_TRUNC _FTRUNC 67 #define O_EXCL _FEXCL 68 /* O_SYNC _FSYNC not posix, defined below */ 69 /* O_NDELAY _FNDELAY set in include/fcntl.h */ 70 /* O_NDELAY _FNBIO set in 5include/fcntl.h */ 71 #define O_NONBLOCK _FNONBLOCK 72 #define O_NOCTTY _FNOCTTY 73 74 #ifndef _POSIX_SOURCE 75 76 #define O_SYNC _FSYNC 77 78 /* 79 * Flags that work for fcntl(fd, F_SETFL, FXXXX) 80 */ 81 #define FAPPEND _FAPPEND 82 #define FSYNC _FSYNC 83 #define FASYNC _FASYNC 84 #define FNBIO _FNBIO 85 #define FNONBIO _FNONBLOCK /* XXX fix to be NONBLOCK everywhere */ 86 #define FNDELAY _FNDELAY 87 88 /* 89 * Flags that are disallowed for fcntl's (FCNTLCANT); 90 * used for opens, internal state, or locking. 91 */ 92 #define FREAD _FREAD 93 #define FWRITE _FWRITE 94 #define FMARK _FMARK 95 #define FDEFER _FDEFER 96 #define FSHLOCK _FSHLOCK 97 #define FEXLOCK _FEXLOCK 98 99 /* 100 * The rest of the flags, used only for opens 101 */ 102 #define FOPEN _FOPEN 103 #define FCREAT _FCREAT 104 #define FTRUNC _FTRUNC 105 #define FEXCL _FEXCL 106 #define FNOCTTY _FNOCTTY 107 108 #endif /* !_POSIX_SOURCE */ 109 110 /* XXX close on exec request; must match UF_EXCLOSE in user.h */ 111 #define FD_CLOEXEC 1 /* posix */ 112 113 /* fcntl(2) requests */ 114 #define F_DUPFD 0 /* dup */ 115 #define F_GETFD 1 /* get f_flags */ 116 #define F_SETFD 2 /* set f_flags */ 117 #define F_GETFL 3 /* more flags (cloexec) */ 118 #define F_SETFL 4 119 #define F_GETLK 5 120 #define F_SETLK 6 121 #define F_SETLKW 7 122 123 #define F_SETOWN 8 /* for sockets. */ 124 #define F_GETOWN 9 /* for sockets. */ 125 126 /* for F_[GET|SET]FL */ 127 #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ 128 129 /* for posix fcntl() and lockf() */ 130 #define F_RDLCK 0 131 #define F_WRLCK 1 132 #define F_UNLCK 2 133 134 /* for old implementation of bsd flock () */ 135 #define F_EXLCK 4 /* or 3 */ 136 #define F_SHLCK 8 /* or 4 */ 137 138 /* operations for bsd flock(), also used by the kernel implementation */ 139 #define LOCK_SH 1 /* shared lock */ 140 #define LOCK_EX 2 /* exclusive lock */ 141 #define LOCK_NB 4 /* or'd with one of the above to prevent 142 blocking */ 143 #define LOCK_UN 8 /* remove lock */ 144 145 /* file segment locking set data type - information passed to system by user */ 146 struct flock { 147 short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ 148 short l_whence; /* flag to choose starting offset */ 149 long l_start; /* relative offset, in bytes */ 150 long l_len; /* length, in bytes; 0 means lock to EOF */ 151 short l_pid; /* returned with F_GETLK */ 152 short l_xxx; /* reserved for future use */ 153 }; 154 155 #ifndef _POSIX_SOURCE 156 /* extended file segment locking set data type */ 157 struct eflock { 158 short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ 159 short l_whence; /* flag to choose starting offset */ 160 long l_start; /* relative offset, in bytes */ 161 long l_len; /* length, in bytes; 0 means lock to EOF */ 162 short l_pid; /* returned with F_GETLK */ 163 short l_xxx; /* reserved for future use */ 164 long l_rpid; /* Remote process id wanting this lock */ 165 long l_rsys; /* Remote system id wanting this lock */ 166 }; 167 #endif /* !_POSIX_SOURCE */ 168 169 170 #include <sys/types.h> 171 #include <sys/stat.h> /* sigh. for the mode bits for open/creat */ 172 173 extern int open (const char *, int, ...); 174 extern int creat (const char *, mode_t); 175 extern int fcntl (int, int, ...); 176 177 /* Provide _<systemcall> prototypes for functions provided by some versions 178 of newlib. */ 179 #ifdef _LIBC 180 extern int _open (const char *, int, ...); 181 extern int _fcntl (int, int, ...); 182 #ifdef __LARGE64_FILES 183 extern int _open64 (const char *, int, ...); 184 #endif 185 #endif 186 187 #ifdef __cplusplus 188 } 189 #endif 190 #endif /* !_FCNTL_ */ 191