summaryrefslogtreecommitdiffstats
path: root/src/H5Dconv.c
blob: 25ff7629a27298f23e56424006f810fc4e39c410 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/****************************************************************************
* NCSA HDF                                                                 *
* Software Development Group                                               *
* National Center for Supercomputing Applications                          *
* University of Illinois at Urbana-Champaign                               *
* 605 E. Springfield, Champaign IL 61820                                   *
*                                                                          *
* For conditions of distribution and use, see the accompanying             *
* hdf/COPYING file.                                                        *
*                                                                          *
****************************************************************************/

#ifdef RCSID
static char RcsId[] = "@(#)$Revision$";
#endif

/* $Id$ */

/*LINTLIBRARY */
/*+
   FILE
       H5Dconv.c
   HDF5 trivial datatype converion routines

   EXPORTED ROUTINES

   LIBRARY-SCOPED ROUTINES

   LOCAL ROUTINES
   + */

#include <H5private.h>  /* Generic Functions */
#include <H5Dprivate.h> /* Dataset functions */
#include <H5Eprivate.h> /* Error handling */

#define PABLO_MASK	H5D_mask

/*--------------------- Locally scoped variables -----------------------------*/

/* Interface initialization */
static intn interface_initialize_g = FALSE;
#define INTERFACE_INIT NULL

/*--------------------------------------------------------------------------
 NAME
    H5D_convert_buf
 PURPOSE
    Byte-Swap a buffer of data
 USAGE
    herr_t H5D_convert_buf(dst, src, len, size)
        VOIDP dst;         OUT: Buffer to fill with converted data
        VOIDP src;         IN: Buffer to converted data from
        uintn len;         IN: Number of bytes to convert
        uintn size;        IN: Size of quantity to byte-swap
 RETURNS
    SUCCEED/FAIL
 DESCRIPTION
        This function is a byte-swapping memcpy.
--------------------------------------------------------------------------*/
herr_t H5D_convert_buf(void *dst, const void *src, uintn len, uintn size)
{
    const char *s=(const char *)src;
    char *d=(char *)dst;
    herr_t        ret_value = SUCCEED;

    FUNC_ENTER(H5D_convert_buf, FAIL);

    /* Clear errors and check args and all the boring stuff. */
    H5ECLEAR;
    assert(dst);
    assert(src);
    assert(len>0);
    assert(size==8 || size==4 || size==2 || size==1);

    switch(size)
      {
          case 1:   /* straight memcpy() */
              HDmemcpy(d,s,len);
              break;

          case 2:   /* 2-byte swapping */
              while(len>0)
                {
                    *d++=*(s+1);
                    *d++=*s;
                    s+=2;
                    len-=2;
                } /* end while */
              break;

          case 4:   /* 4-byte swapping */
              while(len>0)
                {
                    *d++=*(s+3);
                    *d++=*(s+2);
                    *d++=*(s+1);
                    *d++=*s;
                    s+=4;
                    len-=4;
                } /* end while */
              break;

          case 8:   /* 8-byte swapping */
              while(len>0)
                {
                    *d++=*(s+7);
                    *d++=*(s+6);
                    *d++=*(s+5);
                    *d++=*(s+4);
                    *d++=*(s+3);
                    *d++=*(s+2);
                    *d++=*(s+1);
                    *d++=*s;
                    s+=8;
                    len-=8;
                } /* end while */
              break;

          default:
              HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL);
      } /* end switch */

done:
  if(ret_value == FAIL)   
    { /* Error condition cleanup */

    } /* end if */

    /* Normal function cleanup */

    FUNC_LEAVE(ret_value);
} /* end H5D_convert_buf() */