2

I have one question,studying standard I/O.

    #include <stdio.h>
    int main(){
    void *mem = malloc(0x80);
    close(0)
     /*
      something code (solution)
   */
    read(0,mem,0x80);
    }

with above code, Is possible opening stdin ? before ask question on stackoverflow, i thought that open('/dev/tty'); . but it not seem to completely open stdin. i hope that do not use dup()

오우진
  • 29
  • 4

1 Answers1

1

In my view, the ideal way to achieve this would be

  • use dup() to create a backup fd.
  • close() the stdin.
  • perform the operations
  • restore stdin using the dup2() and passing the previous backup fd.
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261