>-- snip
>#include <err.h>
>#include <errno.h>
>#include <stdlib.h>
>
>int main(void)
>{
> int *i;
> warn("errno: %d", errno);
> i = malloc(sizeof(int));
> warn("errno: %d", errno);
> free(i);
> return (errno);
>}
>-- snip
Your code is wrong. There's only a useful value in errno after
something fails. This would be more reasonable:
int main(void)
{
int *i;
/* warn("errno: %d", errno); -- no error, nothing to check */
i = malloc(sizeof(int));
if(!i)warn("errno: %d", errno); /* only warn on failure */
free(i); /* -- free ignores NULL argument */
return (0); /* -- free cannot fail, no meaningful errno */
}
This isn't specific to FreeBSD, by the way. It's ANSI C.
Regards,
John Levine, [email protected], Primary Perpetrator of "The Internet for Dummies",
Please consider the environment before reading this e-mail. http://jl.ly
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[email protected]"