VAX C function help
Pat Rankin
rankin at eql.caltech.edu
Thu Dec 20 13:52:20 AEST 1990
In article <1990Dec19.133158.17879 at NCoast.ORG>, catfood at NCoast.ORG (Mark W. Schumann) writes...
>In article <25983 at uflorida.cis.ufl.EDU> jdb at reef.cis.ufl.edu (Brian K. W. Hook) writes:
[ note: original question was about determining new mail, then digressed
a bit into file manipulation. ]
>>The problem is I cannot determine the length of a file using VAX C...
>>how do I do this? Using DOS compilers I use filelength(), but that
>>does not seem to be available under VAX C...and I don't have a working
>>copy of GNU C.
>
>ANSI C solution:
>
>long filelength (FILE *f)
>{
>long m;
>
> fseek (f, 0L, SEEK_END);
> fgetpos (f, &m);
> return m;
> }
>...
>I think this should get you started. This will almost certainly
>work with VAX/VMS C and any Unix-compatible compiler.
This won't even come close to working. The file he's reading
(MAIL.MAI, which isn't mentioned in the extracted portion of his message)
is a key-indexed file. It has out-of-band overhead in it, and it also
might have [transparently] compressed data in the actual records. The
number of bytes allocated to the file will not even give a decent estimate
of the number of bytes he'll get from actually reading the file.
Even if the number of bytes was meaningful, fgetpos() provides its
result in an opaque structure, not a simple number. Unfortunately, the
size of a user's mailbox doesn't indicate in any way, shape, or form
whether that user has new mail waiting.
The _only_ reliable way to determine the size of a file is to
actually read it. On VMS, you can obtain the file type from RMS and
if it happens to be stream_lf or a couple of other variations then a
simple calculation [or fstat()] will be adequate. For most file types,
that isn't adequate.
>>If you know a simpler way to do this, please let me know. ...assume the
>>user does not have system priv, etc. please.
Use the VMS callable mail interface. It's been available since
version 5.0, and is finally documented and officially supported in version
5.4. A user doesn't need any privilege to manipulate his/her own mailbox.
Try asking in newsgroup comp.os.vms if you want details.
>>Second...strstr and strtok don't seem to be doing anything. I check
>>for a null return value and they don't work...e.g.
>>if (strstr(buffer,"NEWMAIL")==NULL)
>> [something] else [something-else]
You haven't given enough information. Both of those functions
certainly work. How did you load data into 'buffer'? The mailbox file
probably has some NUL bytes in it.
Pat Rankin, rankin at eql.caltech.edu
More information about the Comp.lang.c
mailing list