Mercurial > cpython-lru_cache-weakref
annotate Python/dup2.c @ 63550:3068e00a3207 3.1
Merged revisions 83531 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r83531 | georg.brandl | 2010-08-02 19:24:49 +0200 (Mo, 02 Aug 2010) | 1 line
#7372: fix regression in pstats: a previous fix to handle cProfile data in add_callers broke handling of profile data.
........
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Mon, 02 Aug 2010 17:36:05 +0000 |
| parents | f79434ee41fa |
| children | cd73917f2478 |
| 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> | |
| 15 | |
| 16 #define BADEXIT -1 | |
| 17 | |
| 18 int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
1825
diff
changeset
|
19 dup2(int fd1, int fd2) |
| 1449 | 20 { |
| 21 if (fd1 != fd2) { | |
| 22 if (fcntl(fd1, F_GETFL) < 0) | |
| 23 return BADEXIT; | |
| 24 if (fcntl(fd2, F_GETFL) >= 0) | |
| 25 close(fd2); | |
| 26 if (fcntl(fd1, F_DUPFD, fd2) < 0) | |
| 27 return BADEXIT; | |
| 28 } | |
| 29 return fd2; | |
| 30 } |
