Ah, great stuff Cameron, I really like the
way you showed the ability to put the errors in Human readable form, thanks
Yes I must be losing my mind, because I
could have sworn, previously, my code was creating the new directory, but I
might have just added manually at the beginning of this project and assumed it
was created each time when it was not. As you might tell I am new to the Unix environment.
J
Two questions is
you do not mind.
1.) Does mkdir allow be to specify a multiple directory path to be
installed, or do I have to do some kind of loop to install it. i.e. mkdir(“/otr/mydir”,
0755)?
2.) What is x-man-page that everyone is referring to? I know about man
in a terminal but I am not familiar with the ‘x-man-page’ notation.
Thanks so much
Carl
-----Original Message-----
From: Cameron Kerr
[mailto:email@hidden]
Sent: Thursday, June 30, 2005 7:12
PM
To: Carl Smith
Cc: email@hidden
Subject: Re: fopen
First of all, one of the main problems you have is
that you aren't checking your errors. UNIX, unlike Mac OS, has had, for many
many years, a simple way of printing out the actual error, in a way a human can
easily understand. None of the "error -12345" business.
The correct way to check the return code from fopen
(check the Return section of the manual-page to see how best to check for
errors) is as follows.
if( (fp = fopen( filename, "w" )) == NULL )
{
perror("Could not open
filename");
// either return with an error
code, or exit(EXIT_FAILURE)
x-man-page://perror,
which is part of the stdio library, will output to stderr, the string
given, followed by a colon and space, and the human-readable string that
relates to errno, such as "No such file or directory" (which is what
you would get if errno == ENOENT)
You should always check your return codes.
One other problem you have is that you're assuming a
folder will be created for you, which fopen will not do.
--
Cameron Kerr
Telecommunications Teaching Fellow & SysAdmin
email@hidden