5762868 [rkeene@sledge /home/rkeene/devel/backuppcd/all/backuppcd-200601171056]$ cat -n htonll.c
 1 /*
 2  * Copyright (C) 2005  Roy Keene
 3  *
 4  * This program is free software; you can redistribute it and/or
 5  * modify it under the terms of the GNU General Public License
 6  * as published by the Free Software Foundation; either version 2
 7  * of the License, or (at your option) any later version.
 8  *
 9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  *
18  * Author Information
19  *      Roy Keene
20  *      Planning Systems Inc
21  *      Slidell, LA
22  *      backuppcd-bugs@psislidell.com
23  */
24 
25 #include "compat.h"
26 
27 #ifndef HAVE_HTONLL
28 
29 #ifdef HAVE_NETINET_IN_H
30 #include <netinet/in.h>
31 #endif
32 #ifdef HAVE_STDINT_H
33 #include <stdint.h>
34 #endif
35 #ifdef HAVE_INTTYPES_H
36 #include <inttypes.h>
37 #endif
38 #ifdef HAVE_ENDIAN_H
39 #include <endian.h>
40 #endif
41 
42 #ifndef __BIG_ENDIAN
43 #define __BIG_ENDIAN 4321
44 #endif
45 #ifndef __LITTLE_ENDIAN
46 #define __LITTLE_ENDIAN 1234
47 #endif
48 
49 #ifndef __BYTE_ORDER
50 #ifdef WORDS_BIGENDIAN
51 #define __BYTE_ORDER __BIG_ENDIAN
52 #else
53 #define __BYTE_ORDER __LITTLE_ENDIAN
54 #endif
55 #endif
56 
57 #include "htonll.h"
58 
59 uint64_t htonll(uint64_t n) {
60     uint64_t retval;
61 
62 #if __BYTE_ORDER == __BIG_ENDIAN
63     retval = n;
64 #else
65     retval = ((uint64_t) htonl(n & 0xFFFFFFFFLLU)) << 32;
66     retval |= htonl((n & 0xFFFFFFFF00000000LLU) >> 32);
67 #endif
68     return(retval);
69 }
70 
71 #endif
5762869 [rkeene@sledge /home/rkeene/devel/backuppcd/all/backuppcd-200601171056]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2005-07-22 14:41:22