Mercurial > cpython-lru_cache-weakref
annotate Python/dup2.c @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | cd73917f2478 |
| children |
| rev | line source |
|---|---|
| 1449 | 1 /* |
| 2 * Public domain dup2() lookalike | |
| 3 * by Curtis Jackson @ AT&T Technologies, Burlington, NC | |
| 4 * electronic address: burl!rcj | |
| 5 * | |
| 6 * dup2 performs the following functions: | |
| 7 * | |
| 8 * Check to make sure that fd1 is a valid open file descriptor. | |
| 9 * Check to see if fd2 is already open; if so, close it. | |
| 10 * Duplicate fd1 onto fd2; checking to make sure fd2 is a valid fd. | |
| 11 * Return fd2 if all went well; return BADEXIT otherwise. | |
| 12 */ | |
| 13 | |
| 14 #include <fcntl.h> | |
|
65103
cd73917f2478
Merged revisions 85236 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
13658
diff
changeset
|
15 #include <unistd.h> |
| 1449 | 16 |
| 17 #define BADEXIT -1 | |
| 18 | |
| 19 int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
1825
diff
changeset
|
20 dup2(int fd1, int fd2) |
| 1449 | 21 { |
| 22 if (fd1 != fd2) { | |
| 23 if (fcntl(fd1, F_GETFL) < 0) | |
| 24 return BADEXIT; | |
| 25 if (fcntl(fd2, F_GETFL) >= 0) | |
| 26 close(fd2); | |
| 27 if (fcntl(fd1, F_DUPFD, fd2) < 0) | |
| 28 return BADEXIT; | |
| 29 } | |
| 30 return fd2; | |
| 31 } |
