17 #include <sys/types.h>
38 extern unsigned char dbl_cnvrt[
sizeof(double)];
39 extern unsigned char flt_cnvrt[
sizeof(float)];
41 extern unsigned char lng_cnvrt[
sizeof(long)];
42 extern unsigned char int_cnvrt[
sizeof(int)];
43 extern unsigned char shrt_cnvrt[
sizeof(short)];
47 static char *buffer =
NULL;
48 static int buf_alloced = 0;
50 static int buf_alloc(
int needed)
55 if (needed <= buf_alloced)
83 unsigned char *c1, *c2;
97 c1 = (
unsigned char *)buffer;
98 c2 = (
unsigned char *)buf;
99 for (i = 0; i < cnt; i++) {
104 c2 +=
sizeof(double);
127 unsigned char *c1, *c2;
141 c1 = (
unsigned char *)buffer;
142 c2 = (
unsigned char *)buf;
143 for (i = 0; i < cnt; i++) {
168 size_t port_off_t_size)
172 unsigned char *c1, *c2;
175 if ((
size_t)
nat_off_t == port_off_t_size) {
176 ret =
dig_fread(buf, port_off_t_size, cnt, fp);
180 else if ((
size_t)
nat_off_t > port_off_t_size) {
182 buf_alloc(cnt * port_off_t_size);
183 ret =
dig_fread(buffer, port_off_t_size, cnt, fp);
187 memset(buf, 0, cnt *
sizeof(off_t));
189 c1 = (
unsigned char *)buffer;
190 c2 = (
unsigned char *)buf;
191 for (i = 0; i < cnt; i++) {
194 if (c1[port_off_t_size - 1] & 0x80)
195 memset(c2, 0xff,
sizeof(off_t));
196 memcpy(c2, c1, port_off_t_size);
200 memset(c2, 0xff,
sizeof(off_t));
201 memcpy(c2 +
nat_off_t - port_off_t_size, c1,
204 c1 += port_off_t_size;
208 else if ((
size_t)
nat_off_t < port_off_t_size) {
214 if ((
size_t)
nat_off_t >= port_off_t_size) {
216 buf_alloc(cnt * port_off_t_size);
217 ret =
dig_fread(buffer, port_off_t_size, cnt, fp);
221 memset(buf, 0, cnt *
sizeof(off_t));
223 c1 = (
unsigned char *)buffer;
224 c2 = (
unsigned char *)buf;
225 for (i = 0; i < cnt; i++) {
228 if (c1[port_off_t_size - 1] & 0x80)
229 memset(c2, 0xff,
sizeof(off_t));
233 memset(c2, 0xff,
sizeof(off_t));
235 for (j = 0; j < port_off_t_size; j++)
237 c1 += port_off_t_size;
241 else if ((
size_t)
nat_off_t < port_off_t_size) {
266 unsigned char *c1, *c2;
281 memset(buf, 0, cnt *
sizeof(
long));
283 c1 = (
unsigned char *)buffer;
284 c2 = (
unsigned char *)buf;
285 for (i = 0; i < cnt; i++) {
289 memset(c2, 0xff,
sizeof(
long));
294 memset(c2, 0xff,
sizeof(
long));
309 memset(buf, 0, cnt *
sizeof(
long));
311 c1 = (
unsigned char *)buffer;
312 c2 = (
unsigned char *)buf;
313 for (i = 0; i < cnt; i++) {
317 memset(c2, 0xff,
sizeof(
long));
321 memset(c2, 0xff,
sizeof(
long));
349 unsigned char *c1, *c2;
364 memset(buf, 0, cnt *
sizeof(
int));
366 c1 = (
unsigned char *)buffer;
367 c2 = (
unsigned char *)buf;
368 for (i = 0; i < cnt; i++) {
372 memset(c2, 0xff,
sizeof(
int));
377 memset(c2, 0xff,
sizeof(
int));
392 memset(buf, 0, cnt *
sizeof(
int));
394 c1 = (
unsigned char *)buffer;
395 c2 = (
unsigned char *)buf;
396 for (i = 0; i < cnt; i++) {
400 memset(c2, 0xff,
sizeof(
int));
404 memset(c2, 0xff,
sizeof(
int));
432 unsigned char *c1, *c2;
447 memset(buf, 0, cnt *
sizeof(
short));
449 c1 = (
unsigned char *)buffer;
450 c2 = (
unsigned char *)buf;
451 for (i = 0; i < cnt; i++) {
455 memset(c2, 0xff,
sizeof(
short));
460 memset(c2, 0xff,
sizeof(
short));
475 memset(buf, 0, cnt *
sizeof(
short));
477 c1 = (
unsigned char *)buffer;
478 c2 = (
unsigned char *)buf;
479 for (i = 0; i < cnt; i++) {
483 memset(c2, 0xff,
sizeof(
short));
487 memset(c2, 0xff,
sizeof(
short));
562 unsigned char *c1, *c2;
570 c1 = (
unsigned char *)buf;
571 c2 = (
unsigned char *)buffer;
572 for (i = 0; i < cnt; i++) {
575 c1 +=
sizeof(
double);
600 unsigned char *c1, *c2;
608 c1 = (
unsigned char *)buf;
609 c2 = (
unsigned char *)buffer;
610 for (i = 0; i < cnt; i++) {
637 size_t port_off_t_size)
640 unsigned char *c1, *c2;
643 if ((
size_t)
nat_off_t == port_off_t_size) {
644 if (
dig_fwrite(buf, port_off_t_size, cnt, fp) == cnt)
647 else if ((
size_t)
nat_off_t > port_off_t_size) {
648 buf_alloc(cnt * port_off_t_size);
649 c1 = (
unsigned char *)buf;
650 c2 = (
unsigned char *)buffer;
651 for (i = 0; i < cnt; i++) {
653 memcpy(c2, c1, port_off_t_size);
655 memcpy(c2, c1 +
nat_off_t - port_off_t_size,
658 c2 += port_off_t_size;
660 if (
dig_fwrite(buffer, port_off_t_size, cnt, fp) == cnt)
663 else if ((
size_t)
nat_off_t < port_off_t_size) {
669 if ((
size_t)
nat_off_t >= port_off_t_size) {
670 buf_alloc(cnt * port_off_t_size);
671 c1 = (
unsigned char *)buf;
672 c2 = (
unsigned char *)buffer;
673 for (i = 0; i < cnt; i++) {
674 for (j = 0; j < port_off_t_size; j++)
677 c2 += port_off_t_size;
679 if (
dig_fwrite(buffer, port_off_t_size, cnt, fp) == cnt)
682 else if ((
size_t)
nat_off_t < port_off_t_size) {
706 unsigned char *c1, *c2;
715 c1 = (
unsigned char *)buf;
716 c2 = (
unsigned char *)buffer;
717 for (i = 0; i < cnt; i++) {
731 c1 = (
unsigned char *)buf;
732 c2 = (
unsigned char *)buffer;
733 for (i = 0; i < cnt; i++) {
761 unsigned char *c1, *c2;
770 c1 = (
unsigned char *)buf;
771 c2 = (
unsigned char *)buffer;
772 for (i = 0; i < cnt; i++) {
786 c1 = (
unsigned char *)buf;
787 c2 = (
unsigned char *)buffer;
788 for (i = 0; i < cnt; i++) {
816 unsigned char *c1, *c2;
825 c1 = (
unsigned char *)buf;
826 c2 = (
unsigned char *)buffer;
827 for (i = 0; i < cnt; i++) {
841 c1 = (
unsigned char *)buf;
842 c2 = (
unsigned char *)buffer;
843 for (i = 0; i < cnt; i++) {
979 for (i = 0; i < (size_t)
nat_off_t; i++) {
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
#define PORT_DOUBLE
Sizes of types used in portable format (different names used in Vlib/ and diglib/ for the same thing)
size_t dig_fwrite(const void *ptr, size_t size, size_t nmemb, struct gvfile *file)
Write struct gvfile.
size_t dig_fread(void *ptr, size_t size, size_t nmemb, struct gvfile *file)
Read struct gvfile.
void * dig__alloc_space(int, int *, int, void *, int)
int dig_out_of_memory(void)
For now just print message and return error code.
#define ENDIAN_LITTLE
Endian check.
int dig__fread_port_S(short *buf, size_t cnt, struct gvfile *fp)
Read shorts from the Portable Vector Format.
unsigned char flt_cnvrt[sizeof(float)]
int dig__fwrite_port_F(const float *buf, size_t cnt, struct gvfile *fp)
Write floats to the Portable Vector Format.
int dig__fread_port_O(off_t *buf, size_t cnt, struct gvfile *fp, size_t port_off_t_size)
Read off_ts from the Portable Vector Format.
int dig__fread_port_D(double *buf, size_t cnt, struct gvfile *fp)
Read doubles from the Portable Vector Format.
int dig__fread_port_C(char *buf, size_t cnt, struct gvfile *fp)
Read chars from the Portable Vector Format.
int dig__byte_order_out(void)
Get byte order.
int dig__fread_port_L(long *buf, size_t cnt, struct gvfile *fp)
Read longs from the Portable Vector Format.
unsigned char dbl_cnvrt[sizeof(double)]
int dig__fread_port_P(plus_t *buf, size_t cnt, struct gvfile *fp)
Read plus_t from the Portable Vector Format.
unsigned char lng_cnvrt[sizeof(long)]
int dig__fwrite_port_S(const short *buf, size_t cnt, struct gvfile *fp)
Write shorts to the Portable Vector Format.
int dig__fwrite_port_I(const int *buf, size_t cnt, struct gvfile *fp)
Write integers to the Portable Vector Format.
int dig__fwrite_port_D(const double *buf, size_t cnt, struct gvfile *fp)
Write doubles to the Portable Vector Format.
unsigned char off_t_cnvrt[sizeof(off_t)]
struct Port_info * Cur_Head
int dig__fread_port_I(int *buf, size_t cnt, struct gvfile *fp)
Read integers from the Portable Vector Format.
void dig_init_portable(struct Port_info *port, int byte_order)
Set Port_info structure to byte order of file.
unsigned char shrt_cnvrt[sizeof(short)]
int dig_set_cur_port(struct Port_info *port)
Set current Port_info structure.
int dig__fwrite_port_C(const char *buf, size_t cnt, struct gvfile *fp)
Write chars to the Portable Vector Format.
void port_init(void)
Initialize Port_info structures.
int dig__fwrite_port_O(const off_t *buf, size_t cnt, struct gvfile *fp, size_t port_off_t_size)
Write off_ts to the Portable Vector Format.
int dig__fwrite_port_L(const long *buf, size_t cnt, struct gvfile *fp)
Write longs to the Portable Vector Format.
unsigned char int_cnvrt[sizeof(int)]
int dig__fread_port_F(float *buf, size_t cnt, struct gvfile *fp)
Read floats from the Portable Vector Format.
int dig__fwrite_port_P(const plus_t *buf, size_t cnt, struct gvfile *fp)
Write plus_t to the Portable Vector Format.
unsigned char flt_cnvrt[PORT_FLOAT]
Conversion matrices between file and native byte order (float)
int flt_quick
Quick reading flag for float.
unsigned char lng_cnvrt[PORT_LONG]
Conversion matrices between file and native byte order (long)
int dbl_quick
Quick reading flag for double.
unsigned char off_t_cnvrt[PORT_OFF_T]
Conversion matrices between file and native byte order (off_t)
unsigned char int_cnvrt[PORT_INT]
Conversion matrices between file and native byte order (int)
int off_t_quick
Quick reading flag for off_t.
int lng_quick
Quick reading flag for long.
int int_quick
Quick reading flag for int.
unsigned char shrt_cnvrt[PORT_SHORT]
Conversion matrices between file and native byte order (short)
unsigned char dbl_cnvrt[PORT_DOUBLE]
Conversion matrices between file and native byte order (double)
int shrt_quick
Quick reading flag for short.
int byte_order
File byte order.