home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / ansi / stdio / fopen.txh < prev    next >
Encoding:
Text File  |  1996-04-26  |  2.1 KB  |  81 lines

  1. @node fopen, stdio
  2. @subheading Syntax
  3.  
  4. @example
  5. #include <stdio.h>
  6. FILE *fopen(const char *filename, const char *mode);
  7. @end example
  8.  
  9. @subheading Description
  10.  
  11. This function opens a stream corresponding to the named @var{filename}
  12. with the given @var{mode}.  The mode can be one of the following:
  13.  
  14. @table @code
  15.  
  16. @item r
  17.  
  18. Open an existing file for reading.
  19.  
  20. @item w
  21.  
  22. Create a new file (or truncate an existing file) and open it for
  23. writing. 
  24.  
  25. @item a
  26.  
  27. Open an existing file (or create a new one) for writing.  The file
  28. pointer is positioned to the end of the file before every write. 
  29.  
  30. @end table
  31.  
  32. Followed by any of these characters:
  33.  
  34. @table @code
  35.  
  36. @item b
  37.  
  38. Force the file to be open in binary mode instead of the default mode.
  39.  
  40. When called to open the console in binary mode, @code{fopen} will
  41. disable the generation of @code{SIGINT} when you press @kbd{Ctrl-C}
  42. (@kbd{Ctrl-Break} will still cause @code{SIGINT}), because many programs
  43. that use binary reads from the console will also want to get the
  44. @samp{^C} characters.  You can use the @code{__djgpp_set_ctrl_c} library
  45. function (@pxref{__djgpp_set_ctrl_c}) if you want @kbd{Ctrl-C} to
  46. generate interrupts while console is read in binary mode.
  47.  
  48. @item t
  49.  
  50. Force the file to be open in text mode instead of the default mode.
  51.  
  52. @item +
  53.  
  54. Open the file as with @code{O_RDWR} so that both reads and writes
  55. can be done to the same file.
  56.  
  57. @end table
  58.  
  59. If the file is open for both reading and writing, you must call
  60. @code{fflush}, @code{fseek}, or @code{rewind} before switching from read
  61. to write or from write to read. 
  62.  
  63. The open file is set to line buffered if the underlying object is a
  64. device (stdin, stdout, etc), or is fully buffered if the underlying
  65. object is a disk file (data.c, etc).
  66.  
  67. If @code{b} or @code{t} is not specified in @var{mode}, the file type is
  68. chosen by the value of @code{fmode} (@pxref{_fmode}). 
  69.  
  70. @subheading Return Value
  71.  
  72. A pointer to the @code{FILE} object, or @code{NULL} if there was an
  73. error. 
  74.  
  75. @subheading Example
  76.  
  77. @example
  78. FILE *f = fopen("foo", "rb+"); /* open existing file for read/write, binary mode */
  79. @end example
  80.  
  81.