xref: /third_party/musl/src/unistd/dup2.c
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/musl/src/unistd/
1570af302Sopenharmony_ci#include <unistd.h>
2570af302Sopenharmony_ci#include <errno.h>
3570af302Sopenharmony_ci#include <fcntl.h>
4570af302Sopenharmony_ci#include "syscall.h"
5570af302Sopenharmony_ci
6570af302Sopenharmony_ciint dup2(int old, int new)
7570af302Sopenharmony_ci{
8570af302Sopenharmony_ci	int r;
9570af302Sopenharmony_ci#ifdef SYS_dup2
10570af302Sopenharmony_ci	while ((r=__syscall(SYS_dup2, old, new))==-EBUSY);
11570af302Sopenharmony_ci#else
12570af302Sopenharmony_ci	if (old==new) {
13570af302Sopenharmony_ci		r = __syscall(SYS_fcntl, old, F_GETFD);
14570af302Sopenharmony_ci		if (r >= 0) return old;
15570af302Sopenharmony_ci	} else {
16570af302Sopenharmony_ci		while ((r=__syscall(SYS_dup3, old, new, 0))==-EBUSY);
17570af302Sopenharmony_ci	}
18570af302Sopenharmony_ci#endif
19570af302Sopenharmony_ci	return __syscall_ret(r);
20570af302Sopenharmony_ci}
21

Indexes created Thu Nov 07 10:32:03 CST 2024