• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: fopen
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: fopen


  • Subject: RE: fopen
  • From: "Carl Smith" <email@hidden>
  • Date: Thu, 30 Jun 2005 19:28:13 -0400
  • Thread-topic: fopen

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.

 

FILE *fp;

char *filename = "xxxx";

 

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)

 

If you want more control, you can use x-man-page://strerror

 

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

 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Program crashes when executed normally, but runs w/o trouble in the Debugger
  • Next by Date: Re: Program crashes when executed normally, but runs w/o trouble in the Debugger
  • Previous by thread: Re: fopen
  • Next by thread: InfoPlist.strings
  • Index(es):
    • Date
    • Thread