1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1 /* convert.c - functions to convert little-endian data to endian of host
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
2 * Copyright (C) 2000-2007 Jason Jordan <shnutils@freeshell.org>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
3 *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
7 * (at your option) any later version.
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
8 *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
9 * This program is distributed in the hope that it will be useful,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
12 * GNU General Public License for more details.
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
13 *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
14 * You should have received a copy of the GNU General Public License
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
15 * along with this program; if not, write to the Free Software
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
17 */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
18
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
19 /*
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
20 * $Id: convert.c,v 1.9 2007/03/23 05:49:48 jason Exp $
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
21 */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
22
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
23 #include <stdlib.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
24 #include "shorten.h"
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
25
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
26 ulong shn_uchar_to_ulong_le(uchar *buf)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
27 /* converts 4 bytes stored in little-endian format to a ulong */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
28 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
29 return (ulong)((buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0]);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
30 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
31
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
32 slong shn_uchar_to_slong_le(uchar *buf)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
33 /* converts 4 bytes stored in little-endian format to an slong */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
34 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
35 return (slong)shn_uchar_to_ulong_le(buf);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
36 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
37
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
38 ushort shn_uchar_to_ushort_le(uchar *buf)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
39 /* converts 4 bytes stored in little-endian format to a ushort */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
40 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
41 return (ushort)((buf[1] << 8) + buf[0]);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
42 }
|