reading a few bytes into a file



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;
}
.



Relevant Pages

  • Re: How do you use FindFirstFile ?
    ... DWORD DoesFileExist(LPCSTR pszName) ... char szMsg; ... int main ... For my app it is correct and valid for the file not to exist. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Using sysarch specific syscalls in assembly?
    ... I tried to write a little C app that uses sysarch and i386_set_ioperm to gain ... int main { ... static inline void outb (unsigned short int port, ...
    (freebsd-hackers)
  • Re: C# messaging
    ... The string you specify here needs to be a unique string in the Windows ... will get an int returned to you so save it. ... use the same exact string as you did in your C app). ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Reading files >2GB
    ... 32-bit pointers? ... you need to rethink your app. ... int main ...
    (comp.os.linux.misc)
  • Odd select / read behavior
    ... My app has a separate thread for listening on incoming data. ... int r, ret; ...
    (comp.os.linux.development.apps)