Thread: Implementation of dup2

  1. #1
    Registered User rpbear's Avatar
    Join Date
    Nov 2009
    Posts
    18

    Implementation of dup2

    Hi all,I'm reading <Advanced programming in the UNIX environment>,that book asked the reader to implement a function which has same functions with dup2 without calling fcntl.Could anyone give me a tip?Any help will be appreciated.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Read what dup2 does, compared to dup (perhaps?)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User rpbear's Avatar
    Join Date
    Nov 2009
    Posts
    18
    Quote Originally Posted by Salem View Post
    Read what dup2 does, compared to dup (perhaps?)
    The problem is that dup will use the minimum unused file descriptor as the newly open file descriptor.However,without using dup2,how can I make sure that my function will use the specified file descriptor?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Re-read the previous chapter of the book then for more clues, then try the exercise again?

    Personally, I fail to see the point of "Do x without using the obvious y to achieve the result" type exercises.
    It's like being told how to do a magic trick. The only real fun is figuring it out.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User rpbear's Avatar
    Join Date
    Nov 2009
    Posts
    18
    Quote Originally Posted by Salem View Post
    Personally, I fail to see the point of "Do x without using the obvious y to achieve the result" type exercises.
    It's like being told how to do a magic trick. The only real fun is figuring it out.
    I do agree with u ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memchr implementation
    By roaan in forum C Programming
    Replies: 4
    Last Post: 09-07-2009, 10:34 PM
  2. rand() implementation
    By habert79 in forum C Programming
    Replies: 4
    Last Post: 02-07-2009, 01:18 PM
  3. implementation file
    By bejiz in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2005, 01:59 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Pure virtual implementation, or not.
    By Eibro in forum C++ Programming
    Replies: 2
    Last Post: 03-19-2003, 08:05 PM