473,385 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

errno

I only read 2 c++ book and none explain errno because its a c "thing"

i dont know what is it and i dont know how to use it, but bsd socket use errno for connect() int reply

somebody could give me a little tutorial

thx
Feb 23 '07 #1
4 1238
DeMan
1,806 1GB
I'll admit I've not used it before, but there appear to be many references on the web that may be helpful.....
Feb 23 '07 #2
Banfa
9,065 Expert Mod 8TB
errno translates to an expression that has a type of int and is declared in errno.h along with #defines for common values.

It is used by some of the standard library functions and is set when an error occurs during the function call to provide extra information about what the error was (a bit like the Windows function GetLastError() if you are familiar with that).

An example of a function that uses it is strtoul which returns a fixed error value (MAX_ULONG) but sets errno to indicate exactly what error occured.

If you are going to use errno then it is important to set it's value to 0 before you call the function you may wish to test it after otherwise it could contain a value from a previous function call.
Feb 23 '07 #3
Thanks a lot !
Feb 24 '07 #4
horace1
1,510 Expert 1GB
as explained by Banfa when an error occurs many of functions set up an integer error number in errno which is declared in <errno.h> - a usful function is strerror in <string.h> which given errno as a parameter returns a pointer to a corresponding implementation defined string which can then be printed, e.g. the following calls strerror() if the fopen() fails
Expand|Select|Wrap|Line Numbers
  1.     if ((in_file = fopen(filename, "r")) == NULL)          /* open input file */
  2.         {
  3.         printf("\nUnable to open file '%s': %s", filename, strerror(errno));
  4.         return 1;                                              /* open failed */
  5.         }
  6.  
a run gave
Enter name of input file ? file1
Unable to open file 'file1': No such file or directory
Feb 24 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Richard Tobin | last post by:
In a library I am writing, I want to use an errno-like mechanism for error returns. The error would probably be represented as a struct rather than just an integer. I don't have any...
3
by: Mac | last post by:
Is it legal to declare errno after you've included errno.h? For example: #include<errno.h> .... int main (void) {
3
by: RoSsIaCrIiLoIA | last post by:
On Wed, 05 May 2004, CBFalconer <cbfalconer@yahoo.com> wrote: >Even if sscanf succeeds in inputting various fields, there are >probably range and other validity checks to be applied. The...
4
by: Paul Emmons | last post by:
If I am writing a function that sets errno according to a possible error condition, should it also set errno to 0 if it executes normally, or should it leave errno alone on success?
11
by: Vijay Kumar R Zanvar | last post by:
> In <pan.2004.04.22.04.06.05.969827@bar.net> "Mac" <foo@bar.net> writes: > > >Is it legal to declare errno after you've included errno.h? > > > >For example: > > > >#include<errno.h> > > >...
18
by: pete | last post by:
On my system, the following five expressions are true: (HUGE_VAL == HUGE_VAL / 2) (1 / HUGE_VAL == 0) (sqrt(HUGE_VAL) == HUGE_VAL) (sqrt(-1) == HUGE_VAL) (sqrt(-HUGE_VAL) == HUGE_VAL) and
5
by: Urs Beeli | last post by:
I have a question regarding errno. If I understand it correctly, including <errno.h> allows me to check "errno" for error values that some standard library functions may set. This brings up some...
3
by: eyalc1978 | last post by:
Hi Does someone knows what does errno 72 means I got this error when fwriting a structure and still the file is being created. I saw something on the net saying that this is caused when trying to...
13
by: Spiros Bousbouras | last post by:
Assume I'm writing a function which is going to set the value of errno if something went wrong but I also want to guarantee that errno will remain unchanged if the function completed its task...
22
by: viza | last post by:
Hi all, A quick one - since errno is a lvalue, can I do: fread( & errno, sizeof errno, 1, fp ) ? TIA viza
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.