OiO.lk Blog C# Understanding errno Codes: Need Assistance
C#

Understanding errno Codes: Need Assistance


I was looking at errno.h source code, to find how the variable errno is implemented, I was expected it to be int or something like that, but when I look into glibc errno.h file, I found this line:

/* The error code set by various library functions.  */
extern int *__errno_location (void) __THROW __attribute_const__;
# define errno (*__errno_location ())

which means to me errno is not int, it is int function, but then when I looked into glibc strtol function, to understand how it interact with errno, and I found this:

if (any < 0) {
  acc = neg ? LONG_MIN : LONG_MAX;
  errno = ERANGE;
}

based on my C understanding, errno will be replaced to be like:

if (any < 0) {
  acc = neg ? LONG_MIN : LONG_MAX;
  (*__errno_location ()) = ERANGE;
}

which is illogical to me, because we cannot assign value to function
then I found this line in strtol which confused me more

extern int errno;

now errno will be used as what, as int, or as function?

then I go to Unix implementation:

https://opensource.apple.com/

I found something similar, but without extern int errno;

so basically there is no variable called errno



You need to sign in to view this answers

Exit mobile version