Skip to content

Instantly share code, notes, and snippets.

@jduck
Last active August 29, 2015 14:17
Show Gist options
  • Save jduck/d7d52fac7f61cbd3dc2a to your computer and use it in GitHub Desktop.
Save jduck/d7d52fac7f61cbd3dc2a to your computer and use it in GitHub Desktop.
Script started on Mon 16 Mar 2015 10:42:04 PM CDT
duoct:0:~$ cd work
duoct:0:~/work$ ls -l fread-intof.c
-rw------- 1 jdrake jdrake 500 Jun 13 2013 fread-intof.c
duoct:0:~/work$ cat fread-intof.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
FILE *fp;
int ints[1024];
unsigned long nelem = strtoul(argv[2], NULL, 0);
printf("total: %lu * %d = %lu (0x%lx)\n", nelem, 4, nelem*4, nelem*4);
fp = fopen(argv[1], "rb");
if (fp) {
size_t nr;
nr = fread(ints, 4, nelem, fp);
printf("nr: %lu\n", (unsigned long)nr);
write(2, ints, sizeof(ints));
fclose(fp);
}
return 0;
}
duoct:0:~/work$ gcc -m32 -Wall -ggdb -o fio fread-intof.c
duoct:0:~/work$ ./fio /dev/zero $((0x40000001)) 2> err
total: 1073741825 * 4 = 4 (0x4)
nr: 1073741825
duoct:0:~/work$ tr -d '\0' < err | hexdump -vC | head -2
00000000 a9 41 74 f7 58 18 73 f7 f0 ff ff 40 75 f7 78 7d |[email protected]}|
00000010 9c ff 63 98 73 f7 c0 71 f7 7c 2a 03 32 ff ff ff |..c.s..q.|*.2...|
duoct:0:~/work$ exit
Script done on Mon 16 Mar 2015 10:42:38 PM CDT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment