Skip to main content
Aatif Shaikh1
Associate III
November 21, 2019
Question

How to use the "errno" in STM32F103CBT6?

  • November 21, 2019
  • 1 reply
  • 2152 views

Hello!

I'm using some of the string conversion functions, who's declarations are present in the "stdint.h" file. at present I'm using "strtol" and "strtod". According to the library "the value of the macro ERANGE is stored in errno, If the correct value would underflow, zero is returned". So, mainly I wanted to know if the "ERANGE" is set in he "errno" or not after performing sting conversions.

Hence, I wanted to know how do access the variable "errno"? also, what are the steps or things should I keep in mind while accessing this variable?

Regards,

Aatif Shaikh

This topic has been closed for replies.

1 reply

Ozone
Principal
November 21, 2019

In a POSIX/clib environment, errno is an integer variable with external linkage residing somewhere in clib.a.

It is a "side effect" interface used by clib functions.

> So, mainly I wanted to know if the "ERANGE" is set in he "errno" or not after performing sting conversions.

If it is not documented for you library, you need to look into the (library) source code that is supposed to set errno.

Aatif Shaikh1
Associate III
November 21, 2019

Thanks for your reply.

I'm using standard peripheral library. In the header file "errno.h" I found the reference of the "errno variable". Now, when I'm able to use it, but still how can differentiate between these operations, which are state in the code snippet.

CODE :
printf("1. -Return value = %d -Errno=%d\n\r",strtol("0",NULL,10),errno);
printf("2. -Return value = %d -Errno=%d\n\r",strtol("A",NULL,10),errno);
OUTPUT : 
1. -Return value = 0 -Errno=0
2. -Return value = 0 -Errno=0

In both above operation (1 and 2) i'm getting the same result , thus can anyone tell me how do I identify that the 2nd operation "strtol("A",NULL,10)" is giving a wrong value?

Ozone
Principal
November 21, 2019

Many clib function like fopen() return a specific error in 'errno' beside the normal return value (fopen returns NULL in case of error).

In your case, you would need to look into the implementation of the strtol() function.

> thus can anyone tell me how do I identify that the 2nd operation "strtol("A",NULL,10)" is giving ,e a wrong value?

Because "A" is not an element of the character set for decimal numbers (base 10).

Would be for hexadecimal, i.e. base = 16.

https://linux.die.net/man/3/strtol