ยปCore Development>Code coverage>Python/dup2.c

Python code coverage for Python/dup2.c

#countcontent
1n/a/*
2n/a * Public domain dup2() lookalike
3n/a * by Curtis Jackson @ AT&T Technologies, Burlington, NC
4n/a * electronic address: burl!rcj
5n/a *
6n/a * dup2 performs the following functions:
7n/a *
8n/a * Check to make sure that fd1 is a valid open file descriptor.
9n/a * Check to see if fd2 is already open; if so, close it.
10n/a * Duplicate fd1 onto fd2; checking to make sure fd2 is a valid fd.
11n/a * Return fd2 if all went well; return BADEXIT otherwise.
12n/a */
13n/a
14n/a#include <fcntl.h>
15n/a#include <unistd.h>
16n/a
17n/a#define BADEXIT -1
18n/a
19n/aint
20n/adup2(int fd1, int fd2)
21n/a{
22n/a if (fd1 != fd2) {
23n/a if (fcntl(fd1, F_GETFL) < 0)
24n/a return BADEXIT;
25n/a if (fcntl(fd2, F_GETFL) >= 0)
26n/a close(fd2);
27n/a if (fcntl(fd1, F_DUPFD, fd2) < 0)
28n/a return BADEXIT;
29n/a }
30n/a return fd2;
31n/a}