2013-01-09 22:31:36 +01:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* libs/libc/spawn/lib_psfa_addopen.c
|
2013-01-09 22:31:36 +01:00
|
|
|
*
|
2021-04-02 09:22:52 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-01-09 22:31:36 +01:00
|
|
|
*
|
2021-04-02 09:22:52 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-01-09 22:31:36 +01:00
|
|
|
*
|
2021-04-02 09:22:52 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2013-01-09 22:31:36 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <spawn.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2013-01-18 02:52:42 +01:00
|
|
|
#include <nuttx/spawn.h>
|
2013-01-09 22:31:36 +01:00
|
|
|
|
2015-12-30 00:31:17 +01:00
|
|
|
#include "libc.h"
|
2013-03-09 22:12:20 +01:00
|
|
|
|
2013-01-09 22:31:36 +01:00
|
|
|
/****************************************************************************
|
2015-10-03 00:30:35 +02:00
|
|
|
* Public Functions
|
2013-01-09 22:31:36 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: posix_spawn_file_actions_addopen
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The posix_spawn_file_actions_addopen() function adds an open operation
|
|
|
|
* to the list of operations associated with the object referenced by
|
2013-01-11 22:51:54 +01:00
|
|
|
* file_actions, for subsequent use in a call to posix_spawn() or
|
|
|
|
* posix_spawnp(). The descriptor referred to by fd is opened using
|
2013-01-09 22:31:36 +01:00
|
|
|
* the path, oflag, and mode arguments as if open() had been called on it
|
|
|
|
* prior to the new child process starting execution. The string path is
|
|
|
|
* copied by the posix_spawn_file_actions_addopen() function during this
|
|
|
|
* process, so storage need not be persistent in the caller.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* file_actions - The posix_spawn_file_actions_t to append the action.
|
2013-01-11 22:51:54 +01:00
|
|
|
* fd - The file descriptor to be opened.
|
|
|
|
* path - The path to be opened.
|
2013-01-09 22:31:36 +01:00
|
|
|
* oflags - Open flags
|
|
|
|
* mode - File creation mode
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, these functions return 0; on failure they return an error
|
|
|
|
* number from <errno.h>.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-03-16 13:13:02 +01:00
|
|
|
int posix_spawn_file_actions_addopen(
|
|
|
|
FAR posix_spawn_file_actions_t *file_actions,
|
|
|
|
int fd, FAR const char *path, int oflags,
|
|
|
|
mode_t mode)
|
2013-01-09 22:31:36 +01:00
|
|
|
{
|
|
|
|
FAR struct spawn_open_file_action_s *entry;
|
|
|
|
size_t len;
|
|
|
|
size_t alloc;
|
|
|
|
|
2021-03-16 13:13:02 +01:00
|
|
|
DEBUGASSERT(file_actions && path && fd >= 0);
|
2013-01-09 22:31:36 +01:00
|
|
|
|
|
|
|
/* Get the size of the action including storage for the path plus its NUL
|
|
|
|
* terminating character.
|
|
|
|
*/
|
|
|
|
|
|
|
|
len = strlen(path);
|
|
|
|
alloc = SIZEOF_OPEN_FILE_ACTION_S(len);
|
|
|
|
|
|
|
|
/* Allocate the action list entry of this size */
|
|
|
|
|
2013-03-09 22:12:20 +01:00
|
|
|
entry = (FAR struct spawn_open_file_action_s *)lib_zalloc(alloc);
|
2013-01-09 22:31:36 +01:00
|
|
|
if (!entry)
|
|
|
|
{
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the file action entry */
|
|
|
|
|
|
|
|
entry->action = SPAWN_FILE_ACTION_OPEN;
|
|
|
|
entry->fd = fd;
|
|
|
|
entry->oflags = oflags;
|
|
|
|
entry->mode = mode;
|
2021-03-16 13:13:02 +01:00
|
|
|
strncpy(entry->path, path, len + 1);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2013-01-09 22:31:36 +01:00
|
|
|
/* And add it to the file action list */
|
|
|
|
|
2021-03-16 13:13:02 +01:00
|
|
|
add_file_action(file_actions,
|
|
|
|
(FAR struct spawn_general_file_action_s *)entry);
|
2013-01-09 22:31:36 +01:00
|
|
|
return OK;
|
|
|
|
}
|