MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / _fdt_slot_alloc

Function _fdt_slot_alloc

components/dfs/dfs_v2/src/dfs.c:105–130  ·  view source on GitHub ↗

* @brief Allocate an available file descriptor slot in the file descriptor table * * @param[in,out] fdt Pointer to the file descriptor table to allocate from * @param[in] startfd The starting file descriptor index to begin searching * * @return int The allocated file descriptor index if successful (>= 0), * -1 if allocation failed (table expansion failed) * * @note If no empty slot

Source from the content-addressed store, hash-verified

103 * @note If no empty slot found, expand the table and return the new index.
104 */
105static int _fdt_slot_alloc(struct dfs_fdtable *fdt, int startfd)
106{
107 int idx;
108
109 /* find an empty fd slot */
110 for (idx = startfd; idx < (int)fdt->maxfd; idx++)
111 {
112 if (fdt->fds[idx] == RT_NULL)
113 {
114 return idx;
115 }
116 }
117
118 idx = fdt->maxfd;
119 if (idx < startfd)
120 {
121 idx = startfd;
122 }
123
124 if (_fdt_slot_expand(fdt, idx) < 0)
125 {
126 return -1;
127 }
128
129 return idx;
130}
131
132/**
133 * @brief Allocate a file descriptor from the file descriptor table

Callers 3

_fdt_fd_allocFunction · 0.85
dfs_dupFunction · 0.85
dfs_dup_toFunction · 0.85

Calls 1

_fdt_slot_expandFunction · 0.85

Tested by

no test coverage detected