home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!mcsun!Germany.EU.net!news.Hamburg.Germany.EU.net!jwminhh!wieck
- From: wieck@jwminhh.hanse.de (Jan Wieck)
- Subject: Re: Fopening a text file
- Message-ID: <1993Jan6.234558.2044@jwminhh.hanse.de>
- Organization: Private Site under Mach386
- X-Newsreader: Tin 1.1 PL4
- References: <1993Jan5.015937.19270@vpnet.chi.il.us>
- Date: Wed, 6 Jan 1993 23:45:58 GMT
- Lines: 48
-
- mox@vpnet.chi.il.us (William Moxley) writes:
- : I'm having some problems with a program that I wrote for this computer
- : which is running a sys V unix operating system. My problem is with
- : fopen. When I try do a fopen("filename", "rt"); it opens the file as a
- : binary. If I drop the t, is still creates a binary file. So how do I
- : make fopen create a straight text file?
- :
- : As you can guess, I normally don't write programs for machines other
- : than dos. Thanks in advance...
-
- Files under UNIX are different from that under DOS in the
- case of holding ASCII-text. DOS (as a sibling of CP/M)
- encodes a new-line as CR, LF (or 0x0D, 0x0A in HEX). UNIX
- only says LF.
-
- This is one of the major reasons why C-programs cannot be
- 100% portable between UNIX, DOS and e.g. VMS (which also
- uses CR, LF).
-
- If your program uses fprintf(3S) and fgets(3S), it would
- get the same data back that it wrote. But if you use
- read(2) instead of fgets(3S), it possibly wouldn't. The
- standard I/O-functions library (where the f...()-
- functions reside) is implemented under each OS in that
- kind, that a normal cat- | type- | show-command would
- display a file, written with these functions, like a
- standard text-file under this OS.
-
- For this reason, the standard under DOS is to map '\n' to
- 0x0D,0x0A and vice versa. But they wouldn't create the
- same binary data as C under UNIX would do. To minimize
- port-overhead, binary modes are added to these functions
- under DOS. Borland's Turbo-C also makes the same in
- read(2) and write(2), so you have to use the (TC-
- specific) mode switch O_BINARY to suppress it (I don't
- know how other DOS compilers would do - I think similar).
-
- Back to you - what you read in your program is binary
- data as it is text. There's no difference under UNIX.
-
-
- Until later, Jan
-
- --
- # Any language keeps its own misunderstandings; #
- # why shouldn't programming languages do? #
- # #
- # wieck@jwminhh.hanse.de (Jan Wieck) #
-