File: umfile.c

package info (click to toggle)
cf-python 1.3.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,996 kB
  • sloc: python: 51,733; ansic: 2,736; makefile: 78; sh: 2
file content (165 lines) | stat: -rw-r--r-- 3,549 bytes parent folder | download
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <stdio.h>
#include <unistd.h>

#include "umfileint.h"

int get_type_and_num_words(int word_size,
			   const void *int_hdr,
			   Data_type *type_rtn,
			   size_t *num_words_rtn)
{
  errorhandle_init();
  switch (word_size)
    {
    case 4:
      return get_type_and_num_words_core_sgl(int_hdr, type_rtn, num_words_rtn);
    case 8:
      return get_type_and_num_words_core_dbl(int_hdr, type_rtn, num_words_rtn);
    default:
      return -1;
    }
}

int get_extra_data_offset_and_length(int word_size, 
				     const void *int_hdr,
				     size_t data_offset,
				     size_t disk_length,
				     size_t *extra_data_offset_rtn,
				     size_t *extra_data_length_rtn)
{
  errorhandle_init();
  switch (word_size)
    {
    case 4:
      return get_extra_data_offset_and_length_core_sgl(int_hdr,
						       data_offset,
						       disk_length,
						       extra_data_offset_rtn,
						       extra_data_length_rtn);
    case 8:
      return get_extra_data_offset_and_length_core_dbl(int_hdr,
						       data_offset,
						       disk_length,
						       extra_data_offset_rtn,
						       extra_data_length_rtn);
    default:
      return -1;
    }  
}

int detect_file_type(int fd, File_type *file_type)
{
  errorhandle_init();
  return detect_file_type_(fd, file_type);
}

int read_extra_data(int fd,
		    size_t extra_data_offset,
		    size_t extra_data_length,
		    Byte_ordering byte_ordering,
		    int word_size,
		    void *extra_data_return)
{
  errorhandle_init();
  switch (word_size)
    {
    case 4:
      return read_extra_data_core_sgl(fd,
				      extra_data_offset,
				      extra_data_length,
				      byte_ordering,
				      extra_data_return);
    case 8:
      return read_extra_data_core_dbl(fd,
				      extra_data_offset,
				      extra_data_length,
				      byte_ordering,
				      extra_data_return);
    default:
      return -1;
    }
}

int read_header(int fd,
		size_t header_offset,
		Byte_ordering byte_ordering, 
		int word_size, 
		void *int_hdr_rtn,
		void *real_hdr_rtn)
{
  errorhandle_init();
  switch (word_size)
    {
    case 4:
      return read_hdr_at_offset_sgl(fd, header_offset, byte_ordering, 
				    int_hdr_rtn, real_hdr_rtn);
    case 8:
      return read_hdr_at_offset_dbl(fd, header_offset, byte_ordering, 
				    int_hdr_rtn, real_hdr_rtn);
    default:
      return -1;
    }
}


File *file_parse(int fd,
		 File_type file_type)
{
  File *file;

  errorhandle_init();

  switch (file_type.word_size)
    {
    case 4:
      CKP(  file = file_parse_core_sgl(fd, file_type)  );
      break;
    case 8:
      CKP(  file = file_parse_core_dbl(fd, file_type)  );
      break;
    default:
      ERR;
    }
  return file;
  ERRBLKP;
}


void file_free(File *file)
{
  errorhandle_init();

  CKI(   free_file(file)   );
  return;

 err:
  GRIPE;
}


int read_record_data(int fd, 
		     size_t data_offset, 
		     size_t disk_length, 
		     Byte_ordering byte_ordering, 
		     int word_size, 
		     const void *int_hdr,
		     const void *real_hdr,
		     size_t nwords, 
		     void *data_return)
{
  errorhandle_init();
  
  switch(word_size) 
    {
    case 4:
      CKI(  read_record_data_core_sgl(fd, data_offset, disk_length, byte_ordering, 
				      int_hdr, real_hdr, nwords, data_return)  );
      return 0;
    case 8:
      CKI(  read_record_data_core_dbl(fd, data_offset, disk_length, byte_ordering, 
				      int_hdr, real_hdr, nwords, data_return)  );
      return 0;
    }
  /* invalid word size falls through to error return */
  ERRBLKI;
}