int print_sndlist( int /*argc*/, char** /*argv*/ ) { unsigned int offset; unsigned int length; unsigned int serial; char filename[15]; std::string soundidxname = Plib::systemstate.config.uo_datafile_root + "soundidx.mul"; std::string soundname = Plib::systemstate.config.uo_datafile_root + "sound.mul"; std::ifstream soundidx(soundidxname.c_str(), std::ios::in | std::ios::binary); std::ifstream sound(soundname.c_str(), std::ios::in | std::ios::binary); int i; i = 0; while ( soundidx.good() ) { ++i; offset = read_ulong( soundidx ); length = read_ulong( soundidx ); serial = read_ulong( soundidx ); if ( !soundidx.good() ) break; if ( offset == 0xFFffFFffLu ) continue; sound.seekg(offset, std::ios::beg); if ( !sound.good() ) break; sound.read( filename, sizeof filename ); INFO_PRINT << "0x" << fmt::hexu( i ) << ", 0x" << fmt::hexu( serial ) << ": " << filename << "\n" << "len " << length << "\n"; } return 0; }
int print_sndlist( int argc, char **argv ) { unsigned long offset; unsigned long length; unsigned long serial; char filename[ 15 ]; string soundidxname = config.uo_datafile_root + "soundidx.mul"; string soundname = config.uo_datafile_root + "sound.mul"; ifstream soundidx( soundidxname.c_str(), ios::in | ios::binary ); ifstream sound( soundname.c_str(), ios::in | ios::binary ); int i; i = 0; while (soundidx.good()) { ++i; offset = read_ulong( soundidx ); length = read_ulong( soundidx ); serial = read_ulong( soundidx ); if (!soundidx.good()) break; if (offset == 0xFFffFFffLu) continue; sound.seekg( offset, ios::beg ); if (!sound.good()) break; sound.read( filename, sizeof filename ); cout << hex << i << ", " << hex << serial << dec << ": " << filename << endl; } return 0; }
/* BUNZIP2(cStr) --> cResult */ int clip_BUNZIP2(ClipMachine * mp) { int l, r; unsigned int rl; char *s, *rp; s = _clip_parcl(mp, 1, &l); if (!s || l < 4) return EG_ARG; rl = read_ulong(s); rp = (char *) malloc(rl + 1); r = BZPREF(bzBuffToBuffDecompress) (rp, &rl, s + 4, l - 4, 0, 0); if (r != BZ_OK) { free(rp); if (r == BZ_DATA_ERROR) return EG_ARG; else return EG_MEM; } _clip_retcn_m(mp, rp, rl); return 0; }
/* Test writing single values of various types to board's global memory. * The test passes if we read back what we wrote. */ void test_small_writes (ssize_t f) { unsigned char uc; unsigned short us; unsigned int ui; unsigned long int uli; write_uchar (f, 0, 0, 19); uc = read_uchar (f, 0, 0); assert (uc == 19); write_ushort (f, 0, 0, 13); us = read_ushort(f, 0, 0); assert (us == 13); write_ulong (f, 0, 0, 0x3037383633352030); uli = read_ulong (f, 0, 0); assert (uli == 0x3037383633352030); write_uint (f, 0, 0, 18987983); ui = read_uint (f, 0, 0); assert (ui == 18987983); printf ("test_small_writes PASSED\n"); }
void agfa1_interpret_offset_makervalue(FILE *inptr,unsigned short byteorder, struct ifd_entry *entry_ptr,unsigned long fileoffset_base) { unsigned long offset,value; int chpr = 0; if(entry_ptr && (PRINT_VALUE)) { offset = entry_ptr->value + fileoffset_base; switch(entry_ptr->tag) { case 0x0200: /* SpecialMode */ value = read_ulong(inptr,byteorder,offset); print_startvalue(); switch(value) { case 0: chpr += printf("Normal"); break; case 1: chpr += printf("Unknown"); break; case 2: chpr += printf("Fast"); break; case 3: chpr += printf("Panorama,"); value = read_ulong(inptr,byteorder,HERE); chpr += printf("#%lu,",value); value = read_ulong(inptr,byteorder,HERE); switch(value) { case 1: chpr += printf(" Left to Right"); break; case 2: chpr += printf(" Right to Left"); break; case 3: chpr += printf(" Bottom to Top"); break; case 4: chpr += printf(" Top to Bottom"); break; default: printred(" undefined"); break; } break; default: printred("undefined"); break; } print_endvalue(); break; default: break; } } setcharsprinted(chpr); }
static SAMPLE_VGM *load_ev(SAMPLE_VGM *ev, const char *fname) { char *s = NULL, *tok; int i, size = 0, incr = 100; unsigned long l; FILE *f; f = efopen(fname, "r"); if (ev == NULL) ev = init_ev(); ev->evt = SEMIVARIOGRAM; for (i = 1; i <= 8; i++) { get_line(&s, &size, f); if (i == 6) { tok = strtok(s, " "); /* word */ tok = strtok(NULL, " "); /* cutoff */ if (read_double(tok, &(ev->cutoff))) { fclose(f); efree(s); pr_warning("file: %s, line: %d, token: %s", fname, i, tok); return NULL; } tok = strtok(NULL, " "); /* word */ tok = strtok(NULL, " "); /* word */ tok = strtok(NULL, " \n"); /* iwidth */ if (tok != NULL) { if (read_double(tok, &(ev->iwidth))) { fclose(f); efree(s); pr_warning("file: %s, line: %d, token: %s", fname, i, tok); return NULL; } } /* else part: what to do with ev->iwidth? */ } } while (get_line(&s, &size, f) != NULL) { ev->n_est++; if (ev->n_est >= ev->n_max) { ev->n_max += incr; ev->gamma = (double *) erealloc (ev->gamma, sizeof(double) * ev->n_max); ev->dist = (double *) erealloc (ev->dist, sizeof(double) * ev->n_max); ev->nh = (unsigned long *) erealloc (ev->nh, sizeof(long) * ev->n_max); } tok = strtok(s, " "); /* from */ tok = strtok(NULL, " "); /* to */ tok = strtok(NULL, " "); /* nh */ if (read_ulong(tok, &l)) { fclose(f); efree(s); pr_warning("file: %s, line: %d, token: %s", fname, ev->n_est+8, tok); return NULL; } ev->nh[ev->n_est-1] = l; tok = strtok(NULL, " "); /* dist */ if (read_double(tok, &(ev->dist[ev->n_est-1]))) { fclose(f); efree(s); pr_warning("file: %s, line: %d, token: %s", fname, ev->n_est+8, tok); return NULL; } tok = strtok(NULL, " \n"); /* semivariance or whatever */ if (read_double(tok, &(ev->gamma[ev->n_est-1]))) { fclose(f); efree(s); pr_warning("file: %s, line: %d, token: %s", fname, ev->n_est+8, tok); return NULL; } } efree(s); efclose(f); return ev; }
unsigned long process_raf(FILE *inptr,unsigned long offset, struct image_summary *summary_entry, char *parent_name,int indent) { unsigned long start_of_jpeg,jpeg_length,max_offset; unsigned long table1_offset,table2_offset; unsigned long table1_length,table2_length; unsigned long CFA_offset,CFA_length; unsigned long unknown2,CFA_primaryarraywidth,CFA_fullarraywidth; unsigned long Secondary_offset,Secondary_length; unsigned long unknown3,Secondary_arraywidth,Secondary_fullarraywidth; unsigned long unused_value; struct image_summary *tmp_summary_entry; int unused; char *fullname = CNULL; int chpr = 0; unsigned short tag; CFA_primaryarraywidth = Secondary_offset = table1_offset = table2_offset = 0UL; /* Record the primary for the image summary */ if(((summary_entry == NULL) || summary_entry->entry_lock) || (summary_entry->imageformat != IMGFMT_NOIMAGE)) { summary_entry = new_summary_entry(summary_entry,FILEFMT_RAF,IMGFMT_RAF); } if(summary_entry) { summary_entry->imageformat = IMGFMT_RAF; summary_entry->imagesubformat = IMGSUBFMT_CFA; summary_entry->entry_lock = lock_number(summary_entry); } chpr = newline(chpr); /* A short section of zeros; why? */ if((PRINT_SECTION)) { print_tag_address(SECTION,offset,indent,"@"); chpr += printf("<Offset Directory>"); chpr = newline(chpr); } /* Some sort of ID or version? */ print_tag_address(ENTRY,offset,indent + SMALLINDENT,"@"); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"HeaderVersion"); } if((PRINT_VALUE)) { chpr += printf(" = "); print_ascii(inptr,4,offset); } chpr = newline(chpr); offset += 4; /* A 20 bytes section of zeros. Unknown */ if((PRINT_SECTION)) { print_tag_address(ENTRY,offset,indent + SMALLINDENT,"@"); if((PRINT_VALUE)) print_ubytes(inptr,20,offset); chpr = newline(chpr); } /* A jpeg reduced resolution image, complete with EXIF */ start_of_jpeg = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC); print_tag_address(ENTRY,RAF_JPEGLOC,indent + SMALLINDENT,"@"); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"JpegImageOffset"); } if((PRINT_VALUE)) chpr += printf(" = @%lu",start_of_jpeg); chpr = newline(chpr); print_tag_address(ENTRY,RAF_JPEGLOC + 4,indent + SMALLINDENT,"@"); jpeg_length = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 4); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"JpegImageLength"); } if((PRINT_VALUE)) chpr += printf(" = %lu",jpeg_length); chpr = newline(chpr); /* An offset to what may be a white balance table */ print_tag_address(ENTRY,RAF_JPEGLOC + 8,indent + SMALLINDENT,"@"); table1_offset = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 8); table1_length = read_ulong(inptr,TIFF_MOTOROLA,HERE); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"Table1Offset"); } if((PRINT_VALUE)) chpr += printf(" = @%lu",table1_offset); chpr = newline(chpr); /* The length of the table; probably also the number of rows in */ /* the CFA array */ print_tag_address(ENTRY,RAF_JPEGLOC + 12,indent + SMALLINDENT,"@"); table1_length = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 12); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"Table1Length"); } if((PRINT_VALUE)) chpr += printf(" = %lu",table1_length); chpr = newline(chpr); /* If there is a second table, this must be an SR Super CCD with */ /* a secondary CFA table containing the data for the secondary */ /* photodiodes. The start offset for the secondary data is offset */ /* one row (2944 bytes) from the start of the primary data, */ /* suggesting that the primary and secondary CFA arrays are */ /* interleaved by rows (of 1472 unsigned shorts) */ table2_offset = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 36); table2_length = read_ulong(inptr,TIFF_MOTOROLA,HERE); if(table2_offset == 0) { print_tag_address(ENTRY,RAF_JPEGLOC + 16,indent + SMALLINDENT,"@"); CFA_offset = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 16); CFA_length = read_ulong(inptr,TIFF_MOTOROLA,HERE); Secondary_length = 0; if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"CFAOffset"); } if((PRINT_VALUE)) chpr += printf(" = @%lu",CFA_offset); chpr = newline(chpr); print_tag_address(ENTRY,RAF_JPEGLOC + 20,indent + SMALLINDENT,"@"); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"CFALength"); } if((PRINT_VALUE)) chpr += printf(" = %lu",CFA_length); chpr = newline(chpr); for(unused = 24; unused < 64; unused += 4) { print_tag_address(ENTRY,RAF_JPEGLOC + unused,indent + SMALLINDENT,"@"); unused_value = read_ulong(inptr,TIFF_MOTOROLA,(unsigned long)(RAF_JPEGLOC + unused)); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%s%-2d%*.*s","unused",(unused - 24)/4 + 1,TAGWIDTH-8,TAGWIDTH-8," "); } if((PRINT_VALUE)) chpr += printf(" = %lu",unused_value); chpr = newline(chpr); } } else { /* No secondary; easy. */ CFA_offset = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 16); CFA_length = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 20); print_tag_address(ENTRY,RAF_JPEGLOC + 16,indent + SMALLINDENT,"@"); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"CFA_Offset"); } if((PRINT_VALUE)) chpr += printf(" = @%lu",CFA_offset); chpr = newline(chpr); print_tag_address(ENTRY,RAF_JPEGLOC + 20,indent + SMALLINDENT,"@"); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"CFA_length"); } if((PRINT_VALUE)) chpr += printf(" = @%lu",CFA_length); chpr = newline(chpr); print_tag_address(ENTRY,RAF_JPEGLOC + 24,indent + SMALLINDENT,"@"); unknown2 = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 24); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"unknown2"); } if((PRINT_VALUE)) chpr += printf(" = %lu",unknown2); chpr = newline(chpr); CFA_primaryarraywidth = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 28); print_tag_address(ENTRY,RAF_JPEGLOC + 28,indent + SMALLINDENT,"@"); if((PRINT_TAGINFO)) { /* Array width in 16 bit unsigned shorts */ if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"CFAPrimaryArrayWidth"); } if((PRINT_VALUE)) chpr += printf(" = %lu",CFA_primaryarraywidth); chpr = newline(chpr); print_tag_address(ENTRY,RAF_JPEGLOC + 32,indent + SMALLINDENT,"@"); CFA_fullarraywidth = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 32); if((PRINT_TAGINFO)) { /* Array width in bytes */ if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"CFAFullArrayWidth"); } if((PRINT_VALUE)) chpr += printf(" = %lu",CFA_fullarraywidth); chpr = newline(chpr); print_tag_address(ENTRY,RAF_JPEGLOC + 36,indent + SMALLINDENT,"@"); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"Table2Offset"); } if((PRINT_VALUE)) chpr += printf(" = @%lu",table2_offset); chpr = newline(chpr); print_tag_address(ENTRY,RAF_JPEGLOC + 40,indent + SMALLINDENT,"@"); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"Table2Length"); } if((PRINT_VALUE)) chpr += printf(" = %lu",table2_length); chpr = newline(chpr); /* It appears that the secondary CFA data is interlaced by */ /* row with the primary data. */ Secondary_offset = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 44); Secondary_length = read_ulong(inptr,TIFF_MOTOROLA,HERE); print_tag_address(ENTRY,RAF_JPEGLOC + 44,indent + SMALLINDENT,"@"); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"CFASecondaryOffset**"); } if((PRINT_VALUE)) chpr += printf(" = @%lu",Secondary_offset); chpr = newline(chpr); print_tag_address(ENTRY,RAF_JPEGLOC + 48,indent + SMALLINDENT,"@"); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"CFASecondaryLength**"); } if((PRINT_VALUE)) chpr += printf(" = %lu",Secondary_length); chpr = newline(chpr); unknown3 = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 52); Secondary_arraywidth = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 56); Secondary_fullarraywidth = read_ulong(inptr,TIFF_MOTOROLA,RAF_JPEGLOC + 60); print_tag_address(ENTRY,RAF_JPEGLOC + 52,indent + SMALLINDENT,"@"); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"unknown3"); } if((PRINT_VALUE)) chpr += printf(" = %lu",unknown3); chpr = newline(chpr); print_tag_address(ENTRY,RAF_JPEGLOC + 56,indent + SMALLINDENT,"@"); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"CFASecondaryArrayWidth"); } if((PRINT_VALUE)) chpr += printf(" = %lu",Secondary_arraywidth); chpr = newline(chpr); print_tag_address(ENTRY,RAF_JPEGLOC + 60,indent + SMALLINDENT,"@"); if((PRINT_TAGINFO)) { if((PRINT_LONGNAMES)) chpr += printf("%s.",parent_name); /* I dunno what to call this... */ chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,"CFASecondaryFullArrayWidth"); } if((PRINT_VALUE)) chpr += printf(" = %lu",Secondary_fullarraywidth); chpr = newline(chpr); } if((PRINT_SECTION)) { print_tag_address(SECTION,RAF_JPEGLOC + 63,indent,"@"); chpr += printf("</Offset Directory>"); chpr = newline(chpr); } /* Finish the summary entry */ if(summary_entry) { if(summary_entry->length <= 0) summary_entry->length = CFA_length + Secondary_length; if(summary_entry->offset <= 0) summary_entry->offset = CFA_offset; /* Not really compression; just record the presence of the */ /* secondary */ if(Secondary_offset) summary_entry->compression = 1; else summary_entry->compression = 0; /* These aren't really pixel sizes, since the actual number */ /* of columns is half the arraywidth, and the array will have */ /* to be rotated 45 degrees. And then there is the secondary */ /* pixel data... */ /* It's what we know, and post-processing can do what it */ /* wants. */ if(CFA_primaryarraywidth) { summary_entry->pixel_width = CFA_primaryarraywidth; summary_entry->pixel_height = table1_length; summary_entry->primary_width = CFA_primaryarraywidth; summary_entry->primary_height = table1_length; } else { /* No size provided; this is the best we can do. */ summary_entry->pixel_width = (CFA_length + Secondary_length)/table1_length; summary_entry->pixel_height = table1_length; summary_entry->primary_width = summary_entry->pixel_width; summary_entry->primary_height = table1_length; } summary_entry->subfiletype = PRIMARY_TYPE; } /* Now display the offset sections, starting with the jpeg image */ /* (but only if showing sections) */ if((PRINT_SECTION)) { print_tag_address(SECTION,start_of_jpeg,indent,"@"); chpr += printf("#### Start of Jpeg Image, length %lu",jpeg_length); chpr = newline(chpr); } /* Is this really a jpeg section? */ tag = read_ushort(inptr,TIFF_MOTOROLA,start_of_jpeg); if(tag == JPEG_SOI) { /* If so, process it regardless of output options, to pick up */ /* information for the image summary */ fullname = splice(parent_name,".","JPEG"); max_offset = process_jpeg_segments(inptr,start_of_jpeg,JPEG_SOI,jpeg_length, summary_entry,fullname,"@",SMALLINDENT); print_jpeg_status(); if(summary_entry) { /* The jpeg summary entry should be next in the chain; */ /* there may be others following; mark the jpeg entry so */ /* that it will show up in the format summary. */ if((tmp_summary_entry = summary_entry->next_entry)) tmp_summary_entry->filesubformat |= FILESUBFMT_JPEG; } } else dumpsection(inptr,start_of_jpeg,jpeg_length,indent + SMALLINDENT); if((PRINT_SECTION)) { print_tag_address(SECTION,start_of_jpeg + jpeg_length - 1,indent,"@"); chpr += printf("#### End of Jpeg Image, length %lu",jpeg_length); chpr = newline(chpr); print_tag_address(SECTION,table1_offset,indent,"@"); chpr += printf("<Table 1> length %lu",table1_length); chpr = newline(chpr); if((PRINT_VALUE)) dumpsection(inptr,table1_offset,table1_length,indent + SMALLINDENT); print_tag_address(SECTION,table1_offset + table1_length - 1,indent,"@"); chpr += printf("</Table 1>"); chpr = newline(chpr); if(table2_offset) { print_tag_address(SECTION,table2_offset,indent,"@"); chpr += printf("<Table 2> length %lu",table2_length); chpr = newline(chpr); if((PRINT_VALUE)) dumpsection(inptr,table2_offset,table2_length,indent + SMALLINDENT); print_tag_address(SECTION,table2_offset + table2_length - 1,indent,"@"); chpr += printf("</Table 2>"); chpr = newline(chpr); } /* The full CFA, with secondary if present */ print_tag_address(SECTION,CFA_offset,indent,"@"); chpr += printf("<CFA Image> length %lu",CFA_length + Secondary_length); chpr = newline(chpr); if((PRINT_VALUE)) dumpsection(inptr,CFA_offset,CFA_length + Secondary_length,indent + SMALLINDENT); print_tag_address(SECTION,CFA_offset + CFA_length + Secondary_length - 1,indent,"@"); chpr += printf("</CFA Image>"); chpr = newline(chpr); } setcharsprinted(chpr); return(get_filesize(inptr)); }
void serialize_ulong_basic_test(void) { int char_count = 20; size_t size = sizeof(char) * char_count; char *data = g_malloc(size); char *cur = data; // 0 memset(data, 0, size); cur = data; write_ulong(0, &cur); g_assert_cmpint(cur - data, ==, 1); g_assert_cmpstr(to_hex_str(data, 2), ==, "00 00"); memset(data, 0, size); cur = data; write_ulong(0, &cur); cur = data; g_assert_cmpint(read_ulong(&cur), ==, 0); // 1 memset(data, 0, size); cur = data; write_ulong(1, &cur); g_assert_cmpint(cur - data, ==, 1); g_assert_cmpstr(to_hex_str(data, 2), ==, "01 00"); memset(data, 0, size); cur = data; write_ulong(1, &cur); cur = data; g_assert_cmpint(read_ulong(&cur), ==, 1); // 300 memset(data, 0, size); cur = data; write_ulong(300, &cur); g_assert_cmpint(cur - data, ==, 2); g_assert_cmpstr(to_hex_str(data, 3), ==, "AC 02 00"); memset(data, 0, size); cur = data; write_ulong(300, &cur); cur = data; g_assert_cmpint(read_ulong(&cur), ==, 300); unsigned long n; unsigned long x; // > int n = UINT_MAX; memset(data, 0, size); cur = data; write_ulong(n, &cur); cur = data; g_assert_cmpint(read_ulong(&cur), ==, n); n = UINT_MAX + 1; memset(data, 0, size); cur = data; write_ulong(n, &cur); cur = data; g_assert_cmpint(read_ulong(&cur), ==, n); n = UINT_MAX * 2; memset(data, 0, size); cur = data; write_ulong(n, &cur); cur = data; g_assert_cmpint(read_ulong(&cur), ==, n); n = ULONG_MAX; memset(data, 0, size); cur = data; write_ulong(n, &cur); g_assert_cmpint(cur - data, ==, 10); cur = data; g_assert_cmpint(read_ulong(&cur), ==, n); n = 75794252602; memset(data, 0, size); cur = data; write_ulong(n, &cur); cur = data; x = read_ulong(&cur); if (x != n) { printf("FAILED expected %lu, got %lu\n", n, x); g_assert_cmpint(x, ==, n); }
memset(data, 0, size); cur = data; write_ulong(n, &cur); cur = data; x = read_ulong(&cur); if (x != n) { printf("FAILED expected %lu, got %lu\n", n, x); g_assert_cmpint(x, ==, n); } n = 4850832165; memset(data, 0, size); cur = data; write_ulong(n, &cur); cur = data; x = read_ulong(&cur); if (x != n) { printf("FAILED expected %lu, got %lu\n", n, x); g_assert_cmpint(x, ==, n); } } void serialize_ulong_test(void) { int char_count = 20; size_t size = sizeof(char) * char_count; char *data = g_malloc(size); char *cur = data; cur = data; memset(data, 0, size);