Hello, I have this small C app that someone wrote for me ages ago, and am tired of it breaking every time I move it around to various systems, I will include it below.

I am hoping I can do this in perl, as a one liner, were it will read a the first 4 bytes of a file, grab 4 bytes out of the file, which is a big endian value, and return that as an int to me.

Here is the basic C app I have been using:

#include <stdio.h>
#include <libkern/OSByteOrder.h>

int main (int argc, char *argv[]) {
    FILE* fd;
    char buffer[8];
    unsigned long int dv;

    //open the file
    fd = fopen(argv[1], "r");
    printf("Filename: %-50s", argv[1]);

    fread(buffer, 1, sizeof(buffer), fd);
    dv = OSReadBigInt32(buffer, 4);

    // print the decimal value
    printf(" Value: %ld\n", dv);

    return 0;
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to