help-gnutls
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gnutls] Re: Recognising error codes with an unsigned size_t


From: Simon Josefsson
Subject: [Help-gnutls] Re: Recognising error codes with an unsigned size_t
Date: Thu, 13 Nov 2008 09:33:48 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux)

Michael Weiser <address@hidden> writes:

> Hello,
>
> I'm writing a small program using gnutls and its gnutls_record_{recv,send}()
> interface. They return a size_t which holds either the number of bytes
> transferred or a negative error code.

No, they return a ssize_t.

> But on Mac OS X size_t is an unsigned long which gives me grief when
> trying to recognise an error code as such.
>
> For a simple read() call this is straightforward to fix: Instead of
>
>       if (bytes < 0)
>
> I now use
>
>       if (bytes == -1)
>
> Obviously this doesn't work for gnutls error codes which may range from
> -1 to -65500. Something like
>
>       if ((signed long)bytes < 0)
>
> seems just as wrong to me. Am I missing the obvious here?

I think you are using the wrong type for the 'bytes' variable, use
'ssize_t' which is guaranteed to be signed.  Then the '< 0' comparison
should work.

/Simon




reply via email to

[Prev in Thread] Current Thread [Next in Thread]