version 1.2, 2012/04/08 11:27:44 |
version 1.2.2.3, 2014/05/22 11:36:52 |
|
|
posix_spawn_file_actions_init(posix_spawn_file_actions_t *fa) |
posix_spawn_file_actions_init(posix_spawn_file_actions_t *fa) |
{ |
{ |
if (fa == NULL) |
if (fa == NULL) |
return (-1); |
return EINVAL; |
|
|
fa->fae = malloc(MIN_SIZE * sizeof(struct posix_spawn_file_actions_entry)); |
fa->fae = malloc(MIN_SIZE * sizeof(struct posix_spawn_file_actions_entry)); |
if (fa->fae == NULL) |
if (fa->fae == NULL) |
return (-1); |
return ENOMEM; |
fa->size = MIN_SIZE; |
fa->size = MIN_SIZE; |
fa->len = 0; |
fa->len = 0; |
|
|
return (0); |
return 0; |
} |
} |
|
|
int |
int |
Line 65 posix_spawn_file_actions_destroy(posix_s |
|
Line 65 posix_spawn_file_actions_destroy(posix_s |
|
unsigned int i; |
unsigned int i; |
|
|
if (fa == NULL) |
if (fa == NULL) |
return (-1); |
return EINVAL; |
|
|
for (i = 0; i < fa->len; i++) { |
for (i = 0; i < fa->len; i++) { |
if (fa->fae[i].fae_action == FAE_OPEN) |
if (fa->fae[i].fae_action == FAE_OPEN) |
Line 73 posix_spawn_file_actions_destroy(posix_s |
|
Line 73 posix_spawn_file_actions_destroy(posix_s |
|
} |
} |
|
|
free(fa->fae); |
free(fa->fae); |
return (0); |
return 0; |
} |
} |
|
|
static int |
static int |
posix_spawn_file_actions_getentry(posix_spawn_file_actions_t *fa) |
posix_spawn_file_actions_getentry(posix_spawn_file_actions_t *fa, |
|
unsigned int *i) |
{ |
{ |
|
posix_spawn_file_actions_entry_t *fae; |
|
|
if (fa == NULL) |
if (fa == NULL) |
return -1; |
return EINVAL; |
|
|
if (fa->len < fa->size) |
if (fa->len < fa->size) |
return fa->len; |
goto out; |
|
|
fa->fae = realloc(fa->fae, (fa->size + MIN_SIZE) * |
|
sizeof(struct posix_spawn_file_actions_entry)); |
|
|
|
if (fa->fae == NULL) |
fae = realloc(fa->fae, (fa->size + MIN_SIZE) * sizeof(*fa->fae)); |
return -1; |
if (fae == NULL) |
|
return ENOMEM; |
|
|
|
fa->fae = fae; |
fa->size += MIN_SIZE; |
fa->size += MIN_SIZE; |
|
|
return fa->len; |
out: |
|
*i = fa->len; |
|
return 0; |
} |
} |
|
|
int |
int |
posix_spawn_file_actions_addopen(posix_spawn_file_actions_t * __restrict fa, |
posix_spawn_file_actions_addopen(posix_spawn_file_actions_t * __restrict fa, |
int fildes, const char * __restrict path, int oflag, mode_t mode) |
int fildes, const char * __restrict path, int oflag, mode_t mode) |
{ |
{ |
int i, error; |
char *faepath; |
|
unsigned int i; |
|
int error; |
|
|
if (fildes < 0) |
if (fildes < 0) |
return (EBADF); |
return EBADF; |
|
|
i = posix_spawn_file_actions_getentry(fa); |
error = posix_spawn_file_actions_getentry(fa, &i); |
if (i < 0) |
if (error) |
return (ENOMEM); |
return error; |
|
|
|
faepath = strdup(path); |
|
if (faepath == NULL) |
|
return ENOMEM; |
|
|
fa->fae[i].fae_action = FAE_OPEN; |
fa->fae[i].fae_action = FAE_OPEN; |
fa->fae[i].fae_path = strdup(path); |
fa->fae[i].fae_path = faepath; |
if (fa->fae[i].fae_path == NULL) { |
|
error = errno; |
|
return (error); |
|
} |
|
fa->fae[i].fae_fildes = fildes; |
fa->fae[i].fae_fildes = fildes; |
fa->fae[i].fae_oflag = oflag; |
fa->fae[i].fae_oflag = oflag; |
fa->fae[i].fae_mode = mode; |
fa->fae[i].fae_mode = mode; |
|
|
fa->len++; |
fa->len++; |
|
|
return (0); |
return 0; |
} |
} |
|
|
int |
int |
posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fa, |
posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fa, |
int fildes, int newfildes) |
int fildes, int newfildes) |
{ |
{ |
int i; |
unsigned int i; |
|
int error; |
|
|
if (fildes < 0 || newfildes < 0) |
if (fildes < 0 || newfildes < 0) |
return (EBADF); |
return EBADF; |
|
|
i = posix_spawn_file_actions_getentry(fa); |
error = posix_spawn_file_actions_getentry(fa, &i); |
if (i < 0) |
if (error) |
return (ENOMEM); |
return error; |
|
|
fa->fae[i].fae_action = FAE_DUP2; |
fa->fae[i].fae_action = FAE_DUP2; |
fa->fae[i].fae_fildes = fildes; |
fa->fae[i].fae_fildes = fildes; |
fa->fae[i].fae_newfildes = newfildes; |
fa->fae[i].fae_newfildes = newfildes; |
fa->len++; |
fa->len++; |
|
|
return (0); |
return 0; |
} |
} |
|
|
int |
int |
posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *fa, |
posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *fa, |
int fildes) |
int fildes) |
{ |
{ |
int i; |
unsigned int i; |
|
int error; |
|
|
if (fildes < 0) |
if (fildes < 0) |
return (EBADF); |
return EBADF; |
|
|
i = posix_spawn_file_actions_getentry(fa); |
error = posix_spawn_file_actions_getentry(fa, &i); |
if (i < 0) |
if (error) |
return (ENOMEM); |
return error; |
|
|
fa->fae[i].fae_action = FAE_CLOSE; |
fa->fae[i].fae_action = FAE_CLOSE; |
fa->fae[i].fae_fildes = fildes; |
fa->fae[i].fae_fildes = fildes; |
fa->len++; |
fa->len++; |
|
|
return (0); |
return 0; |
} |
} |