please include the subject in the body of your post
Subject: "perror()4 says SUCCESS Options"
I don't understand what this means
On Nov 22, 10:39*am, arnuld <sunr...@invalid.address> wrote:
> OJECTIVE: Why does perror() says SUCESSS ?
there wasn't an error?
> This code converts a string like "1234" into an unsingned long integer. I
> wrote it following the discussion here on clc of which I have lost the
> url from google http interface to newsgroup.
>
> perror() reports error in else condition many times,
under what circumstances? I ran a slightly hacked version of your code
and there was no problem.
<snip your code>
<insert my code>
************************************************** ****************
/* arn.c */
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define __func__ "convert_string_to_ulongint"
#define VAL_ERR ERANGE
int convert_string_to_ulongint(const char* str, unsigned long* ulp)
{
int ret;
unsigned long int num;
char* p;
if(NULL == str || '\0' == *str || NULL == ulp)
{
printf("IN: %s @ %d: Invalid Args\n", __func__, __LINE__);
return VAL_ERR;
}
p = NULL;
errno = 0;
num = strtoul(str, &p, 10);
/* Error check */
if(ERANGE == errno)
{
if((0 == num) && (0 == strcmp(str, p)))
{
printf("IN: %s @%d: strtoul() could not perform conversion
\n", __func__, __LINE__);
}
else if(ULONG_MAX == num)
{
printf("IN: %s @%dp: strtoul() overflow error\n", __func__,
__LINE__);
}
else
{
printf("IN: %s @%d: strange output from strtoul()\n",
__func__, __LINE__);
}
perror("*ERROR ERANGE*");
ret = -1;
}
else if((0 == errno) && ('\0' == *p))
{
printf("IN: %s @%d: Successful Conversion by strtoul()\n",
__func__, __LINE__);
*ulp = num;
ret = 1;
}
else
{
printf("IN: %s @%d: strange conversions and errno values

\n",
__func__, __LINE__);
printf("num = %lu, ULONG_MAX = %lu\n", num, ULONG_MAX);
perror("*ERROR in ELSE");
ret = -1;
}
return ret;
}
int main (void)
{
unsigned long result;
int retval;
if ((retval = convert_string_to_ulongint("1234", &result)) == 1)
{
printf ("conversion succeeded result was %u\n", result);
return 0;
}
else
{
printf ("conversion FAILED error flag was %d\n", retval);
return EXIT_FAILURE;
}
return 0;
}
************************************************** ****************
</insert my code>
Output:-
> arn.exe
IN: convert_string_to_ulongint @52: Successful Conversion by strtoul()
conversion succeeded result was 1234