Thanks! Oddly enough, the directory tip worked. I originally tried a nonexistent file, and that was caught before fold ran. But, the directory run works.
However, everything inside of an if(STREQ...) statement is still not covered. I do not understand this 'if' statement. I tried creating a directory named "-" to get past the ferror 'if' statement and evaulate to true on the STREQ(filename, "-") statement, but it did not work. Any ideas?
Last edited by Jakeman1086; 11-19-2009 at 05:10 PM..
STREQ is usually defined something like this
The idea is to improve string comparison speed that is highly likely to fail on the first character. In the case above, filenames do almost never start with a '-' character.
And it is faster than strcmp() all by itself in this application.
This could be supporting the case:
if your fold implementation allows - as meaning read from stdin.
I didn't completely understand what you were getting at, but if its just an efficient comparison and - is the beginning of stdin, anything that is not stdin will pass this line?
Focusing on this line:
if (!STREQ (filename, "-") && fclose (istream) == EOF)
I'll still have to deal with fclose(istream) == EOF. To me, this line means once a file has come to its end. So, it would evaluate to true at the end of every file.
So, does this mean to get into this code segment, I just need input from non-standard input into fold? If I'm right, how do I do this? I have limited experience with unix.
No. fclose() == EOF means there was an error closing the file. EOF is defined as -1, and is also what fgetc() returns on EOF. The coder chose EOF which is unfortunate if you are not familiar with libc stdio functions. fclose calls close(), cleans up buffers, etc.
If you want to continue with your project you need to understand:
what each function returns on error, and what system call(s) the stdc function uses underneath.
what/how to cause the error
For example, in this case
This could happen when a file descriptor cannot be closed when the filesystem becomes dismounted or corrupted, as can happen with an NSF mount.
If you read the close 2 man page, and can 'create' any of the errors you see there and then fclose will barf.
Quote:
EBADF
fd isn't a valid open file descriptor.
EINTR
The close() call was interrupted by a signal.
EIO
An I/O error occurred.
You could corrupt the FILE * struct,
but this means you would have to add your code to the original.
Dear All,
Please help me in finding solution for below problem.
I need a command or script to get code or path(from which location code is being executed), which is executing under a process ID.
I dont have google access here,Please help me in finding solution.
Thank you. (3 Replies)
hi
can anyone suggest how to check the code coverage of the shell script (ksh). also i do not see any man page for shcov. what does shcov do.?
please help. (1 Reply)
This is the code:
while test 1 -eq 1
do
read a
$a
if test $a = stop
then
break
fi
done
I read a command on every loop an execute it.
I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test.
For example echo hello.
Now the... (1 Reply)
Say i have 2 files in the giving format:
file1
1 2 3 4
1 2 3 4
1 2 3 4
file2
1 2 3 4
1 2 3 4
1 2 3 4
I have a PERL code (loaned by one of u -i forgot who - thanks!) that extracts the 2nd column from each file and append horizontally to a new file:
perl -ane 'push @{$L->}, $F; close... (1 Reply)