1*433d6423SLionel Sambuc #include <sys/types.h> 2*433d6423SLionel Sambuc #include <sys/wait.h> 3*433d6423SLionel Sambuc #include <fcntl.h> 4*433d6423SLionel Sambuc #include <stdio.h> 5*433d6423SLionel Sambuc #include <stdlib.h> 6*433d6423SLionel Sambuc #include <unistd.h> 7*433d6423SLionel Sambuc 8*433d6423SLionel Sambuc int main(int argc,char * argv[])9*433d6423SLionel Sambucmain(int argc, char *argv[]) 10*433d6423SLionel Sambuc { 11*433d6423SLionel Sambuc int fd, fd_parent; 12*433d6423SLionel Sambuc char buf[1]; 13*433d6423SLionel Sambuc 14*433d6423SLionel Sambuc if (argc != 2) { 15*433d6423SLionel Sambuc return 1; 16*433d6423SLionel Sambuc } 17*433d6423SLionel Sambuc 18*433d6423SLionel Sambuc fd_parent = atoi(argv[1]); 19*433d6423SLionel Sambuc 20*433d6423SLionel Sambuc /* If we open a new file, the fd we obtain should be fd_parent + 1 */ 21*433d6423SLionel Sambuc fd = open("open_plusplus_fd", O_CREAT|O_RDWR, 0660); 22*433d6423SLionel Sambuc if (fd != fd_parent + 1) { 23*433d6423SLionel Sambuc return 2; 24*433d6423SLionel Sambuc } 25*433d6423SLionel Sambuc 26*433d6423SLionel Sambuc /* Also, writing to fd_parent should succeed */ 27*433d6423SLionel Sambuc if (write(fd_parent, buf, sizeof(buf)) <= 0) { 28*433d6423SLionel Sambuc return 3; 29*433d6423SLionel Sambuc } 30*433d6423SLionel Sambuc 31*433d6423SLionel Sambuc return 0; 32*433d6423SLionel Sambuc } 33*433d6423SLionel Sambuc 34