* Copy a filedesc structure. A NULL pointer in returns a NULL reference, * this is to ease callers, not catch errors. */
| 2327 | * this is to ease callers, not catch errors. |
| 2328 | */ |
| 2329 | struct filedesc * |
| 2330 | fdcopy(struct filedesc *fdp) |
| 2331 | { |
| 2332 | struct filedesc *newfdp; |
| 2333 | struct filedescent *nfde, *ofde; |
| 2334 | int i, lastfile; |
| 2335 | |
| 2336 | MPASS(fdp != NULL); |
| 2337 | |
| 2338 | newfdp = fdinit(fdp, true, &lastfile); |
| 2339 | /* copy all passable descriptors (i.e. not kqueue) */ |
| 2340 | newfdp->fd_freefile = -1; |
| 2341 | for (i = 0; i <= lastfile; ++i) { |
| 2342 | ofde = &fdp->fd_ofiles[i]; |
| 2343 | if (ofde->fde_file == NULL || |
| 2344 | (ofde->fde_file->f_ops->fo_flags & DFLAG_PASSABLE) == 0 || |
| 2345 | !fhold(ofde->fde_file)) { |
| 2346 | if (newfdp->fd_freefile == -1) |
| 2347 | newfdp->fd_freefile = i; |
| 2348 | continue; |
| 2349 | } |
| 2350 | nfde = &newfdp->fd_ofiles[i]; |
| 2351 | *nfde = *ofde; |
| 2352 | filecaps_copy(&ofde->fde_caps, &nfde->fde_caps, true); |
| 2353 | fdused_init(newfdp, i); |
| 2354 | } |
| 2355 | if (newfdp->fd_freefile == -1) |
| 2356 | newfdp->fd_freefile = i; |
| 2357 | FILEDESC_SUNLOCK(fdp); |
| 2358 | return (newfdp); |
| 2359 | } |
| 2360 | |
| 2361 | /* |
| 2362 | * Copy a pwddesc structure. |
no test coverage detected