\0 char embedded in text file

\0 char embedded in text file

Post by Steffen Ullri » Fri, 26 May 1995 04:00:00



:      fgets( sin,...
: How can one read records with embedded null characters?

either you use fgetc or (much faster) the read(2) system call

 
 
 

\0 char embedded in text file

Post by d.. » Fri, 26 May 1995 04:00:00



: :      fgets( sin,...
: : How can one read records with embedded null characters?

: either you use fgetc or (much faster) the read(2) system call

Uh,  you got that backwards.  If you're talking about reading a
character at a time from a file (not a tty),  fgetc will be faster.
Fgetc will read in a block of data when necessary,  then all further
fgetc requests will be fetched from that block,  until it is
exhausted.  A read of 1 char will force I/O for every character.  Of
course,  if you read a large block and then process the block it might
be more efficient,  but then you are just duplicating what fgetc
already does.  Getc,  which is a mcro and thereby inlined,  is faster
than fgetc.

--
Dan Mercer                                            ClearSystems, Inc

======================================================================
All opinions expressed are my own and do not reflect the opinions of
my employer or my employer's clients,  in particular 3M Company.
All advice or software offered or presented is provided As Is with no
warranty either expressed or implied.  Follow at your own risk.
Objects in the mirror are closer than they appear.

 
 
 

\0 char embedded in text file

Post by Ken Shephe » Fri, 26 May 1995 04:00:00


I have a utility which reads the .lst file of the xlc compiler.
Sometimes, this file has \0 characters embedded in the middle
of records.  This causes fgets() not to get the entire record.
I have tried the following:

     fgets( sin,...
     sinlen = strlen(sin);
     if ( sin[sinlen-1] != '\n' )
         sin[sinlen] = ' ';  /* replace embedded null char with blank */

An printf of this result shows no characters after the replaced character
leading me to believe that fgets() only read up thru the null character
or did a strcpy out of the buffer.  The next fgets() does not return
the remainder of the record.


are nice enough to display a \000.

How can one read records with embedded null characters?

--
-------------------------------------------------------------------------------
Ken Shepherd                              __  __     ____  ___       ___ ____

                                        /   / \  / / / / /__ /  \/ /___  /
-------------------------------------------------------------------------------

 
 
 

1. How do I delete files w/control char embedded in file name?


This doesn't actually solve the problem, but it may help troubleshooting:

: letters (there are three named BQ, others are BQQBQ, CS, CSSPA,
                     ^^^^^^^^^^^^^^
filenames must be unique within a directory. Since you see three 'BQ's I
too am sure there are unprintable chars in the names.

: I'm sure there are control characters mixed in with the actual
: letters that appear on the screen, but I don't know how to get

I use this to tell if some unprintable chars are in a filename. Doesn't
tell you what unprintable chars, but at least I know they are there.

ls | sed -e 's/^/:/' -e 's/$/:/'

This delimits each filename with colons.

To find out the control chars you could ls >listing_file, and then do
'od' on listing_file.

--

---------------------------------------------------------------------
|
| Tad McClellan,      Logistics Specialist (IETMs and SGML guy)
|                     Lockheed Martin Tactical Aircraft Systems
|                     P.O. Box 748   MZ 1025
|                     Fort Worth, TX 76101
|
|                     voice: (817) 763-6314

|
---------------------------------------------------------------------
|
| Just be thankful we don't get all the government we pay for!
|
---------------------------------------------------------------------

2. Linux Bared - Project

3. Redirected text file has weird control chars.

4. Printserver for Mac AND PC - Ever used Netatalk ?

5. get rid of control char in text file

6. mod_cgi_redirect.c (New)

7. How do embed literal backslashes in a text file using vim?

8. installing a sb16

9. MS-window text file viewer to read a text file in SCO server.

10. Dos Text Files to Linux Text Files

11. tools to seperate one large text file into two small text files?

12. Extracting lines from a text file that match a certain criteria to another text file

13. conver dos text file to unix text file