comparison usr/src/lib/libc/port/stdio/_endopen.c @ 14015:e5fc7d0d7c24

3687 fopen() O_CLOEXEC support via the "e" flag Reviewed by Robert Mustacchi <rm@joyent.com> Reviewed by Richard Lowe <richlowe@richlowe.net> Approved by Dan McDonald <danmcd@nexenta.com>
author Theo Schlossnagle <jesus@omniti.com>
date Wed, 17 Apr 2013 10:28:26 -0400
parents febeba71273d
children
comparison
equal deleted inserted replaced
14014:626936c65627 14015:e5fc7d0d7c24
25 */ 25 */
26 26
27 /* Copyright (c) 1988 AT&T */ 27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */ 28 /* All Rights Reserved */
29 29
30 #pragma ident "%Z%%M% %I% %E% SMI" 30 /* Copyright (c) 2013 OmniTI Computer Consulting, Inc. All rights reserved. */
31 31
32 /* 32 /*
33 * This routine is a special case, in that it is aware of 33 * This routine is a special case, in that it is aware of
34 * both small and large file interfaces. It must be built 34 * both small and large file interfaces. It must be built
35 * in the small compilation environment. 35 * in the small compilation environment.
53 */ 53 */
54 54
55 FILE * 55 FILE *
56 _endopen(const char *name, const char *type, FILE *iop, int largefile) 56 _endopen(const char *name, const char *type, FILE *iop, int largefile)
57 { 57 {
58 int oflag, fd, fflag; 58 int oflag, fd, fflag, eflag, plusflag;
59 char plus; 59 const char *echr;
60 60
61 if (iop == NULL) 61 if (iop == NULL)
62 return (NULL); 62 return (NULL);
63 switch (type[0]) { 63 switch (type[0]) {
64 default: 64 default:
75 case 'a': 75 case 'a':
76 oflag = O_WRONLY | O_APPEND | O_CREAT; 76 oflag = O_WRONLY | O_APPEND | O_CREAT;
77 fflag = _IOWRT; 77 fflag = _IOWRT;
78 break; 78 break;
79 } 79 }
80 /* UNIX ignores 'b' and treats text and binary the same */ 80
81 if ((plus = type[1]) == 'b') 81 plusflag = 0;
82 plus = type[2]; 82 eflag = 0;
83 if (plus == '+') { 83 for (echr = type + 1; *echr != '\0'; echr++) {
84 switch (*echr) {
85 /* UNIX ignores 'b' and treats text and binary the same */
86 default:
87 break;
88 case '+':
89 plusflag = 1;
90 break;
91 case 'e':
92 eflag = 1;
93 break;
94 }
95 }
96 if (eflag) {
97 /* Subsequent to a mode flag, 'e' indicates O_CLOEXEC */
98 oflag = oflag | O_CLOEXEC;
99 }
100 if (plusflag) {
84 oflag = (oflag & ~(O_RDONLY | O_WRONLY)) | O_RDWR; 101 oflag = (oflag & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
85 fflag = _IORW; 102 fflag = _IORW;
86 } 103 }
87 104
88 /* select small or large file open based on flag */ 105 /* select small or large file open based on flag */