nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* source: xio-file.c */ |
2 | /* Copyright Gerhard Rieger 2001-2007 */ |
||
3 | /* Published under the GNU General Public License V.2, see file COPYING */ |
||
4 | |||
5 | /* this file contains the source for opening addresses of open type */ |
||
6 | |||
7 | #include "xiosysincludes.h" |
||
8 | #include "xioopen.h" |
||
9 | |||
10 | #include "xio-named.h" |
||
11 | #include "xio-file.h" |
||
12 | |||
13 | |||
14 | static int xioopen_open1(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *fd, unsigned groups, int dummy1, int dummy2, int dummy3); |
||
15 | |||
16 | |||
17 | #if WITH_OPEN |
||
18 | |||
19 | /****** OPEN addresses ******/ |
||
20 | const struct optdesc opt_o_rdonly = { "o-rdonly", "rdonly", OPT_O_RDONLY, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG_PATTERN, O_RDONLY, O_ACCMODE }; |
||
21 | const struct optdesc opt_o_wronly = { "o-wronly", "wronly", OPT_O_WRONLY, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG_PATTERN, O_WRONLY, O_ACCMODE }; |
||
22 | const struct optdesc opt_o_rdwr = { "o-rdwr", "rdwr", OPT_O_RDWR, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG_PATTERN, O_RDWR, O_ACCMODE }; |
||
23 | const struct optdesc opt_o_create = { "o-create", "creat", OPT_O_CREATE, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_CREAT }; |
||
24 | const struct optdesc opt_o_excl = { "o-excl", "excl", OPT_O_EXCL, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_EXCL }; |
||
25 | const struct optdesc opt_o_noctty = { "o-noctty", "noctty", OPT_O_NOCTTY, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_NOCTTY }; |
||
26 | #ifdef O_SYNC |
||
27 | const struct optdesc opt_o_sync = { "o-sync", "sync", OPT_O_SYNC, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_SYNC }; |
||
28 | #endif |
||
29 | #ifdef O_NOFOLLOW |
||
30 | const struct optdesc opt_o_nofollow = { "o-nofollow", "nofollow",OPT_O_NOFOLLOW, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_NOFOLLOW }; |
||
31 | #endif |
||
32 | #ifdef O_DIRECTORY |
||
33 | const struct optdesc opt_o_directory = { "o-directory", "directory",OPT_O_DIRECTORY, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_DIRECTORY }; |
||
34 | #endif |
||
35 | #ifdef O_LARGEFILE |
||
36 | const struct optdesc opt_o_largefile = { "o-largefile", "largefile",OPT_O_LARGEFILE, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_LARGEFILE }; |
||
37 | #endif |
||
38 | #ifdef O_NSHARE |
||
39 | const struct optdesc opt_o_nshare = { "o-nshare", "nshare", OPT_O_NSHARE, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_NSHARE }; |
||
40 | #endif |
||
41 | #ifdef O_RSHARE |
||
42 | const struct optdesc opt_o_rshare = { "o-rshare", "rshare", OPT_O_RSHARE, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_RSHARE }; |
||
43 | #endif |
||
44 | #ifdef O_DEFER |
||
45 | const struct optdesc opt_o_defer = { "o-defer", "defer", OPT_O_DEFER, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_DEFER }; |
||
46 | #endif |
||
47 | #ifdef O_DIRECT |
||
48 | const struct optdesc opt_o_direct = { "o-direct", "direct", OPT_O_DIRECT, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_DIRECT }; |
||
49 | #endif |
||
50 | #ifdef O_DSYNC |
||
51 | const struct optdesc opt_o_dsync = { "o-dsync", "dsync", OPT_O_DSYNC, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_DSYNC }; |
||
52 | #endif |
||
53 | #ifdef O_RSYNC |
||
54 | const struct optdesc opt_o_rsync = { "o-rsync", "rsync", OPT_O_RSYNC, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_RSYNC }; |
||
55 | #endif |
||
56 | #ifdef O_DELAY |
||
57 | const struct optdesc opt_o_delay = { "o-delay", "delay", OPT_O_DELAY, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_DELAY }; |
||
58 | #endif |
||
59 | #ifdef O_PRIV |
||
60 | const struct optdesc opt_o_priv = { "o-priv", "priv", OPT_O_PRIV, GROUP_OPEN, PH_OPEN, TYPE_BOOL, OFUNC_FLAG, O_PRIV }; |
||
61 | #endif |
||
62 | const struct optdesc opt_o_trunc = { "o-trunc", "trunc", OPT_O_TRUNC, GROUP_OPEN, PH_LATE, TYPE_BOOL, OFUNC_FLAG, O_TRUNC }; |
||
63 | |||
64 | #endif /* WITH_OPEN */ |
||
65 | |||
66 | |||
67 | #if _WITH_FILE /*! inconsistent name FILE vs. OPEN */ |
||
68 | |||
69 | static const struct xioaddr_endpoint_desc xioaddr_open1 = { XIOADDR_SYS, "open", 1, XIOBIT_ALL, GROUP_FD|GROUP_FIFO|GROUP_CHR|GROUP_BLK|GROUP_REG|GROUP_NAMED|GROUP_OPEN|GROUP_FILE|GROUP_TERMIOS, XIOSHUT_CLOSE, XIOCLOSE_CLOSE, xioopen_open1, 0, 0, 0 HELP(":<filename>") }; |
||
70 | const union xioaddr_desc *xioaddrs_open[] = { |
||
71 | (union xioaddr_desc *)&xioaddr_open1, |
||
72 | NULL |
||
73 | }; |
||
74 | |||
75 | /* open for writing: |
||
76 | if the filesystem entry already exists, the data is appended |
||
77 | if it does not exist, a file is created and the data is appended |
||
78 | */ |
||
79 | static int xioopen_open1(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xfd, unsigned groups, int dummy1, int dummy2, int dummy3) { |
||
80 | const char *filename = argv[1]; |
||
81 | int rw = (xioflags & XIO_ACCMODE); |
||
82 | int fd; |
||
83 | bool exists; |
||
84 | bool opt_unlink_close = false; |
||
85 | int result; |
||
86 | |||
87 | /* remove old file, or set user/permissions on old file; parse options */ |
||
88 | if ((result = _xioopen_named_early(argc, argv, xfd, groups, &exists, opts)) < 0) { |
||
89 | return result; |
||
90 | } |
||
91 | |||
92 | retropt_bool(opts, OPT_UNLINK_CLOSE, &opt_unlink_close); |
||
93 | if (opt_unlink_close) { |
||
94 | if ((xfd->stream.unlink_close = strdup(filename)) == NULL) { |
||
95 | Error1("strdup(\"%s\"): out of memory", filename); |
||
96 | } |
||
97 | xfd->stream.opt_unlink_close = true; |
||
98 | } |
||
99 | |||
100 | Notice3("opening %s \"%s\" for %s", |
||
101 | filetypenames[(result&S_IFMT)>>12], filename, ddirection[rw]); |
||
102 | if ((fd = _xioopen_open(filename, rw, opts)) < 0) |
||
103 | return fd; |
||
104 | if (XIOWITHRD(rw)) xfd->stream.rfd = fd; |
||
105 | if (XIOWITHWR(rw)) xfd->stream.wfd = fd; |
||
106 | |||
107 | #if WITH_TERMIOS |
||
108 | if (Isatty(fd)) { |
||
109 | if (Tcgetattr(fd, &xfd->stream.savetty) < 0) { |
||
110 | Warn2("cannot query current terminal settings on fd %d: %s", |
||
111 | fd, strerror(errno)); |
||
112 | } else { |
||
113 | xfd->stream.ttyvalid = true; |
||
114 | } |
||
115 | } |
||
116 | #endif /* WITH_TERMIOS */ |
||
117 | |||
118 | applyopts_named(filename, opts, PH_FD); |
||
119 | applyopts(fd, opts, PH_FD); |
||
120 | applyopts_cloexec(fd, opts); |
||
121 | |||
122 | applyopts_fchown(fd, opts); |
||
123 | |||
124 | if ((result = _xio_openlate(&xfd->stream, opts)) < 0) |
||
125 | return result; |
||
126 | |||
127 | return 0; |
||
128 | } |
||
129 | |||
130 | #endif /* _WITH_FILE */ |