Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: newlib/libc/posix/posix_spawn_file_actions.c

Issue 650343002: Split posix_spawn.c into 3 different files (Closed) Base URL: http://git.chromium.org/native_client/nacl-newlib.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « newlib/libc/posix/posix_spawn.c ('k') | newlib/libc/posix/posix_spawnattr.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*-
2 * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
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 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27 #ifndef _NO_POSIX_SPAWN
28
29 #include <sys/cdefs.h>
30
31 #include <errno.h>
32 #include <spawn.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 /*
37 * File descriptor actions
38 */
39
40 int
41 _DEFUN(posix_spawn_file_actions_init, (ret),
42 posix_spawn_file_actions_t *ret)
43 {
44 posix_spawn_file_actions_t* fa;
45
46 fa = malloc(sizeof(posix_spawn_file_actions_t));
47 if (fa == NULL)
48 return (-1);
49
50 STAILQ_INIT(&fa->fa_list);
51 ret = fa;
52 return (0);
53 }
54
55 int
56 _DEFUN(posix_spawn_file_actions_destroy, (fa),
57 posix_spawn_file_actions_t *fa)
58 {
59 posix_spawn_file_actions_entry_t *fae;
60
61 while ((fae = STAILQ_FIRST(&fa->fa_list)) != NULL) {
62 /* Remove file action entry from the queue */
63 STAILQ_REMOVE_HEAD(&fa->fa_list, fae_list);
64
65 /* Deallocate file action entry */
66 if (fae->fae_action == FAE_OPEN)
67 free(fae->fae_path);
68 free(fae);
69 }
70
71 free(fa);
72 return (0);
73 }
74
75 int
76 _DEFUN(posix_spawn_file_actions_addopen, (fa, fildes, path, oflag, mode),
77 posix_spawn_file_actions_t * __restrict fa _AND
78 int fildes _AND
79 _CONST char * __restrict path _AND
80 int oflag _AND
81 mode_t mode)
82 {
83 posix_spawn_file_actions_entry_t *fae;
84 int error;
85
86 if (fildes < 0)
87 return (EBADF);
88
89 /* Allocate object */
90 fae = malloc(sizeof(posix_spawn_file_actions_entry_t));
91 if (fae == NULL)
92 return (errno);
93
94 /* Set values and store in queue */
95 fae->fae_action = FAE_OPEN;
96 fae->fae_path = strdup(path);
97 if (fae->fae_path == NULL) {
98 error = errno;
99 free(fae);
100 return (error);
101 }
102 fae->fae_fildes = fildes;
103 fae->fae_oflag = oflag;
104 fae->fae_mode = mode;
105
106 STAILQ_INSERT_TAIL(&fa->fa_list, fae, fae_list);
107 return (0);
108 }
109
110 int
111 _DEFUN(posix_spawn_file_actions_adddup2, (fa, fildes, newfildes),
112 posix_spawn_file_actions_t *fa _AND
113 int fildes _AND
114 int newfildes)
115 {
116 posix_spawn_file_actions_entry_t *fae;
117
118 if (fildes < 0 || newfildes < 0)
119 return (EBADF);
120
121 /* Allocate object */
122 fae = malloc(sizeof(posix_spawn_file_actions_entry_t));
123 if (fae == NULL)
124 return (errno);
125
126 /* Set values and store in queue */
127 fae->fae_action = FAE_DUP2;
128 fae->fae_fildes = fildes;
129 fae->fae_newfildes = newfildes;
130
131 STAILQ_INSERT_TAIL(&fa->fa_list, fae, fae_list);
132 return (0);
133 }
134
135 int
136 _DEFUN(posix_spawn_file_actions_addclose, (fa, fildes),
137 posix_spawn_file_actions_t *fa _AND
138 int fildes)
139 {
140 posix_spawn_file_actions_entry_t *fae;
141
142 if (fildes < 0)
143 return (EBADF);
144
145 /* Allocate object */
146 fae = malloc(sizeof(posix_spawn_file_actions_entry_t));
147 if (fae == NULL)
148 return (errno);
149
150 /* Set values and store in queue */
151 fae->fae_action = FAE_CLOSE;
152 fae->fae_fildes = fildes;
153
154 STAILQ_INSERT_TAIL(&fa->fa_list, fae, fae_list);
155 return (0);
156 }
157
158 #endif /* !_NO_POSIX_SPAWN */
OLDNEW
« no previous file with comments | « newlib/libc/posix/posix_spawn.c ('k') | newlib/libc/posix/posix_spawnattr.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698