DUP(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

πŸ’– DUP(3) β€” Library Functions Manual πŸ’–

🌸 NAME 🌸

dup β€” duplicate an open file descriptor. bestie, it’s literally giving β€œsame file, new descriptor” energy πŸ’…

✨ SYNOPSIS ✨

#include <u.h>
#include <libc.h>

int dup(int oldfd, int newfd)

πŸ’… DESCRIPTION πŸ’…

Okay so picture this: you give dup a file descriptor called oldfd, and that descriptor is referring to an open file. dup returns a new file descriptor that refers to the same file. iconic behavior, no cap 🫢

If newfd is -1, the system chooses the lowest available file descriptor. Otherwise, dup will use newfd for the new file descriptor β€” and yes, it closes any old file associated with newfd πŸ˜­πŸ’–

πŸ¦‹ SOURCE πŸ¦‹

/src/lib9/dup.c

πŸŽ€ DIAGNOSTICS πŸŽ€

Sets errstr. that’s the diagnostic moment, bestie ✨

πŸ’€ BUGS πŸ’€

To avoid name conflicts with the underlying system, dup is a preprocessor macro defined as p9dup; see intro(3). iykyk, the macro girlies know πŸ’…


Sign-off time: the bottom-of-page footer is literally just DUP(3) β€” that’s the cute footer energy, mwah πŸ’‹βœ¨