mirror of
https://github.com/ioacademy-jikim/debugging
synced 2025-06-08 08:26:14 +00:00
20 lines
375 B
C
20 lines
375 B
C
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include "fdleak.h"
|
|
|
|
int main (int argc, char **argv)
|
|
{
|
|
int s1;
|
|
int s2;
|
|
|
|
CLOSE_INHERITED_FDS;
|
|
|
|
s1 = DO( open("/dev/null", O_RDONLY) );
|
|
s2 = DO( open("/dev/null", O_RDONLY) );
|
|
|
|
(void) DO( dup2(s1, 20) ); // dup s1 as fd 20
|
|
(void) DO( dup2(s1, s2) ); // dup s1 as fd s2, which closes existing s2 fd
|
|
|
|
return 0;
|
|
}
|