[BACK]Return to htonl.c CVS log [TXT][DIR] Up to [local] / sys / lib / libkern

Annotation of sys/lib/libkern/htonl.c, Revision 1.1.1.1

1.1       nbrk        1: /*
                      2:  * Written by J.T. Conklin <jtc@netbsd.org>.
                      3:  * Public domain.
                      4:  */
                      5:
                      6: #if defined(LIBC_SCCS) && !defined(lint)
                      7: static char *rcsid = "$OpenBSD: htonl.c,v 1.5 2004/11/28 07:23:41 mickey Exp $";
                      8: #endif /* LIBC_SCCS and not lint */
                      9:
                     10: #include <sys/types.h>
                     11: #include <machine/endian.h>
                     12:
                     13: #undef htonl
                     14:
                     15: u_int32_t
                     16: htonl(x)
                     17:        u_int32_t x;
                     18: {
                     19: #if BYTE_ORDER == LITTLE_ENDIAN
                     20:        u_char *s = (u_char *)&x;
                     21:        return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
                     22: #else
                     23:        return x;
                     24: #endif
                     25: }

CVSweb