packages feed

byteorder (empty) → 1.0.0

raw patch · 4 files changed

+108/−0 lines, 4 filesdep +basesetup-changed

Dependencies added: base

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright 2009, Antoine Latter++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of the author nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ System/ByteOrder.hs view
@@ -0,0 +1,56 @@+{-++Module : System.ByteOrder+Copyright : (c) Antoine Latter 2009+License : BSD3++Maintainer : Antoine Latter <aslatter@gmail.com>+Stability: unstable+Portability: requires FFI++-}+module System.ByteOrder(byteOrder, ByteOrder(..)) where++import Foreign.Marshal.Array+import Foreign.Marshal.Alloc+import Foreign.Storable+import Foreign.Ptr+import Foreign++import Data.Word++-- |Indicates the byte-ordering for a 4-byte value, where '1'+-- indicates the most-significant byte and '4' indicates the+-- least significant byte.+--+-- In this format, big endian byte order would be represented as:+-- (1,2,3,4).+--+-- For convinience, the most common cases (BigEndian and LittleEndian)+-- are provided their own constructors.+data ByteOrder+    = BigEndian+    | LittleEndian+    | Mixed (Word8, Word8, Word8, Word8)+ deriving (Eq, Show, Read, Ord)++input :: Word32+input = 0x01020304++-- |Returns the native byte ordering of the system.+byteOrder :: ByteOrder+byteOrder = unsafePerformIO $ byteOrderIO++byteOrderIO :: IO ByteOrder+byteOrderIO = byteListToByteOrder `fmap` wordToByteList input++wordToByteList :: Word32 -> IO [Word8]+wordToByteList word = alloca $ \wordPtr -> do+         poke wordPtr input+         peekArray 4 (castPtr wordPtr)++byteListToByteOrder :: [Word8] -> ByteOrder+byteListToByteOrder [1, 2, 3, 4] = BigEndian+byteListToByteOrder [4, 3, 2, 1] = LittleEndian+byteListToByteOrder xs@[x1, x2, x3, x4] = Mixed (x1,x2,x3,x4)+
+ byteorder.cabal view
@@ -0,0 +1,20 @@+Name:         byteorder+Version:      1.0.0+Cabal-Version:  >= 1.2+Synopsis:      native byte-ordering of the system+Description:   This package is for working with the native byte-ordering of+  the system.++License:      BSD3+License-file: LICENSE+Author:       Antoine Latter+Maintainer:   Antoine Latter <aslatter@gmail.com>+Homepage: http://community.haskell.org/~aslatter/code/byteorder+Build-type: Simple++Category: System++Library++ Build-depends: base+ Exposed-modules: System.ByteOrder