Unix binary/text files: is there a difference?

jay dubb jdubb at bucsf.bu.edu
Thu Mar 21 03:24:03 AEST 1991


    I've looked in a bunch of C and Unix books, and can't seem to find
a good explanation of this - maybe someone can help... Is there a way
to tell (from a C program) whether a given file contains text or data?
The reason I'd like to know, is that I've noticed that if you have a
file into which you have done something like
write(fid,&an_int,sizeof(int)) and then you take this file to another
machine via FTP (in binary mode), and try to read() the int back, it
doesn't work (because of byte-order differences, I assume). So, what
I'd like to know is, is there a difference (in terms of something
stat() could tell me, for example) between straight text files and
files which contain raw numbers (without searching through the whole
file to check, hopefully)? the 'file' command seems to be able to do
this - I've tried it on a text file, and on a file with raw ints and
floats, and it says "text" and "data" respectively. Does it really
know, or is it making a guess (and if so, how good is its method of
guessing?)? Hoping for an explanation of Unix binary/text files...

P.S. If this is the wrong group for this type of question, or you know
of a good book that describes this in detail, please let me know.



More information about the Comp.unix.programmer mailing list