in reply to Truncate a mailbox in place

I think the truncate function meets all your needs, including preserving the lock.

Replies are listed 'Best First'.
Re: Re: Truncate a mailbox in place
by setantae (Scribe) on Jan 13, 2001 at 03:51 UTC
    It looks like it should, but if i add the line
    (truncate (MAILBOX, 0)) or print "ACK!: truncate didn't work : $!\n";
    I get : ACK!: truncate didn't work : Permission denied
    Permissions on /var/spool/mail are
    drwxrwxr-x   2 root     mail         1024 Jan 12 22:43 /var/spool/mail/
    and permissions on the mailbox file in that directory are 0660, so it looks like truncate is trying to unlink the file and recreate it (or something - it does the same with a non-zero LENGTH).

    setantae@eidosnet.co.uk|setantae|www.setantae.uklinux.net

      You can't truncate a mailbox that you have open to only read from. Use "+<" isntead of "<" as your open mode if you want to use the MAILBOX handle to truncate the file.

              - tye (but my friends call me "Tye")