krischan@strange.informatik.rwth-aachen.de (Christian Engel) (10/16/90)
In article <1069@bcs800.UUCP> jeffr@bcs800.UUCP (Jeff Riegel) writes: > printf("The file size is %ld \n",fdbuf.fd_fsize); > [...] >This does not return the proper file size, any suggestions Let's have a look at direct.h and struct fildes: struct fildes { /* file descriptor */ unsigned char fd_att, /* access permissions: d s pe pw pr e w r */ fd_own [2], /* owner's GID, owner's UID */ fd_date [5], /* date and time of last modification */ fd_link, /* link count */ fd_fsize [4], /* file size in bytes */ fd_dcr [3]; /* date of creation */ struct { /* list of segments (48 at most) */ char addr [3], /* lsn of segment */ size [2]; /* size of segment in sectors */ } fdseg [48]; }; There are two important observations: * fd_size is no long or unsigned long but a vector of four unsigned char * fd_size starts at an odd address The first means, that your call of printf("The file size is %ld \n",fdbuf.fd_fsize); takes the address of fdbuf.fd_size an passes it to printf. Thus the the numerical value of the address of fdbuf.fd_size is printed and not the file size. The second observation means you can't take a cast to convert fd_size to an unsigned long if you use no MPU >= 68020 . Try it in the following way, runs on both MPU <= 68010 and MPU >= 68020: ... unsigned long b4toulong (); main ... { ... printf("The file size is %lu \n", b4toulong (fdbuf.fd_fsize)); ... } unsigned long b4toulong (p) register unsigned char *p; { unsigned long result; register unsigned char *pres; pres = (unsigned char *) &result; *pres++ = *p++; *pres++ = *p++; *pres++ = *p++; *pres = *p; return (result); } Krischan -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- krischan@informatik.rwth-aachen.de *** mcvax!unido!rwthinf!strange!krischan Christian Engel, Lehrstuhl fuer Informatik I, RWTH Aachen Ahornstr. 55, D-5100 Aachen, W. Germany