xref: /titanic_52/usr/src/lib/libc/i386/gen/byteorder64.c (revision 3b4b8bda7949c2c1bf610c9f0413accc9d26119a)
14b56a003SDaniel Anderson /*
24b56a003SDaniel Anderson  * CDDL HEADER START
34b56a003SDaniel Anderson  *
44b56a003SDaniel Anderson  * The contents of this file are subject to the terms of the
54b56a003SDaniel Anderson  * Common Development and Distribution License (the "License").
64b56a003SDaniel Anderson  * You may not use this file except in compliance with the License.
74b56a003SDaniel Anderson  *
84b56a003SDaniel Anderson  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
94b56a003SDaniel Anderson  * or http://www.opensolaris.org/os/licensing.
104b56a003SDaniel Anderson  * See the License for the specific language governing permissions
114b56a003SDaniel Anderson  * and limitations under the License.
124b56a003SDaniel Anderson  *
134b56a003SDaniel Anderson  * When distributing Covered Code, include this CDDL HEADER in each
144b56a003SDaniel Anderson  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
154b56a003SDaniel Anderson  * If applicable, add the following below this CDDL HEADER, with the
164b56a003SDaniel Anderson  * fields enclosed by brackets "[]" replaced with your own identifying
174b56a003SDaniel Anderson  * information: Portions Copyright [yyyy] [name of copyright owner]
184b56a003SDaniel Anderson  *
194b56a003SDaniel Anderson  * CDDL HEADER END
204b56a003SDaniel Anderson  */
214b56a003SDaniel Anderson 
224b56a003SDaniel Anderson /*
234b56a003SDaniel Anderson  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
244b56a003SDaniel Anderson  * Use is subject to license terms.
25*3b4b8bdaSRobert Mustacchi  * Copyright (c) 2015, Joyent, Inc.
264b56a003SDaniel Anderson  */
274b56a003SDaniel Anderson 
284b56a003SDaniel Anderson #include <sys/isa_defs.h>
294b56a003SDaniel Anderson #include <sys/types.h>
304b56a003SDaniel Anderson #include <netinet/in.h>
314b56a003SDaniel Anderson #include <inttypes.h>
324b56a003SDaniel Anderson 
334b56a003SDaniel Anderson #if (defined(_BIG_ENDIAN) || defined(_LP64)) && !defined(__lint)
344b56a003SDaniel Anderson 
354b56a003SDaniel Anderson #error	Use ISA-dependent byteorder64.c only on a 32-bit little-endian machine.
364b56a003SDaniel Anderson 
374b56a003SDaniel Anderson #else
384b56a003SDaniel Anderson 
394b56a003SDaniel Anderson uint64_t
404b56a003SDaniel Anderson htonll(uint64_t in)
414b56a003SDaniel Anderson {
424b56a003SDaniel Anderson 	return (htonl(in >> 32) | ((uint64_t)htonl(in) << 32));
434b56a003SDaniel Anderson }
444b56a003SDaniel Anderson 
454b56a003SDaniel Anderson uint64_t
464b56a003SDaniel Anderson ntohll(uint64_t in)
474b56a003SDaniel Anderson {
484b56a003SDaniel Anderson 	return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32);
494b56a003SDaniel Anderson }
504b56a003SDaniel Anderson 
51*3b4b8bdaSRobert Mustacchi uint64_t
52*3b4b8bdaSRobert Mustacchi htobe64(uint64_t in)
53*3b4b8bdaSRobert Mustacchi {
54*3b4b8bdaSRobert Mustacchi 	return (htonl(in >> 32) | ((uint64_t)htonl(in) << 32));
55*3b4b8bdaSRobert Mustacchi }
56*3b4b8bdaSRobert Mustacchi 
57*3b4b8bdaSRobert Mustacchi uint64_t
58*3b4b8bdaSRobert Mustacchi htole64(uint64_t in)
59*3b4b8bdaSRobert Mustacchi {
60*3b4b8bdaSRobert Mustacchi 	return (in);
61*3b4b8bdaSRobert Mustacchi }
62*3b4b8bdaSRobert Mustacchi 
63*3b4b8bdaSRobert Mustacchi uint64_t
64*3b4b8bdaSRobert Mustacchi betoh64(uint64_t in)
65*3b4b8bdaSRobert Mustacchi {
66*3b4b8bdaSRobert Mustacchi 	return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32);
67*3b4b8bdaSRobert Mustacchi }
68*3b4b8bdaSRobert Mustacchi 
69*3b4b8bdaSRobert Mustacchi uint64_t
70*3b4b8bdaSRobert Mustacchi letoh64(uint64_t in)
71*3b4b8bdaSRobert Mustacchi {
72*3b4b8bdaSRobert Mustacchi 	return (in);
73*3b4b8bdaSRobert Mustacchi }
74*3b4b8bdaSRobert Mustacchi 
75*3b4b8bdaSRobert Mustacchi uint64_t
76*3b4b8bdaSRobert Mustacchi be64toh(uint64_t in)
77*3b4b8bdaSRobert Mustacchi {
78*3b4b8bdaSRobert Mustacchi 	return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32);
79*3b4b8bdaSRobert Mustacchi }
80*3b4b8bdaSRobert Mustacchi 
81*3b4b8bdaSRobert Mustacchi uint64_t
82*3b4b8bdaSRobert Mustacchi le64toh(uint64_t in)
83*3b4b8bdaSRobert Mustacchi {
84*3b4b8bdaSRobert Mustacchi 	return (in);
85*3b4b8bdaSRobert Mustacchi }
86*3b4b8bdaSRobert Mustacchi 
874b56a003SDaniel Anderson #endif	/* (_BIG_ENDIAN) || _LP64) && !__lint */
88