imapext-2007
diff src/osdep/unix/flocksim.h @ 0:ada5e610ab86
imap-2007e
author | yuuji@gentei.org |
---|---|
date | Mon, 14 Sep 2009 15:17:45 +0900 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/osdep/unix/flocksim.h Mon Sep 14 15:17:45 2009 +0900 1.3 @@ -0,0 +1,117 @@ 1.4 +/* ======================================================================== 1.5 + * Copyright 1988-2006 University of Washington 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * 1.14 + * ======================================================================== 1.15 + */ 1.16 + 1.17 +/* 1.18 + * Program: flock() emulation via fcntl() locking 1.19 + * 1.20 + * Author: Mark Crispin 1.21 + * Networks and Distributed Computing 1.22 + * Computing & Communications 1.23 + * University of Washington 1.24 + * Administration Building, AG-44 1.25 + * Seattle, WA 98195 1.26 + * Internet: MRC@CAC.Washington.EDU 1.27 + * 1.28 + * Date: 10 April 2001 1.29 + * Last Edited: 20 December 2006 1.30 + */ 1.31 + 1.32 + 1.33 +#include "dummy.h" /* get scan_contents() prototype */ 1.34 + 1.35 +#define flock flocksim /* use ours instead of theirs */ 1.36 + 1.37 +#undef LOCK_SH 1.38 +#define LOCK_SH 1 /* shared lock */ 1.39 +#undef LOCK_EX 1.40 +#define LOCK_EX 2 /* exclusive lock */ 1.41 +#undef LOCK_NB 1.42 +#define LOCK_NB 4 /* no blocking */ 1.43 +#undef LOCK_UN 1.44 +#define LOCK_UN 8 /* unlock */ 1.45 + 1.46 +/* Safe locking definitions */ 1.47 + 1.48 +extern int lockslavep; /* non-zero means slave process */ 1.49 + 1.50 +#undef SAFE_DELETE 1.51 +#define SAFE_DELETE(dtb,stream,mbx) (dtb->flags & DR_LOCKING) ? \ 1.52 + safe_delete (dtb,stream,mbx) : (*dtb->mbxdel) (stream,mbx) 1.53 +#undef SAFE_RENAME 1.54 +#define SAFE_RENAME(dtb,stream,old,newname) (dtb->flags & DR_LOCKING) ? \ 1.55 + safe_rename (dtb,stream,old,newname) : (*dtb->mbxren) (stream,old,newname) 1.56 +#undef SAFE_STATUS 1.57 +#define SAFE_STATUS(dtb,stream,mbx,bits) (dtb->flags & DR_LOCKING) ? \ 1.58 + safe_status (dtb,stream,mbx,bits) : (*dtb->status) (stream,mbx,bits) 1.59 +#undef SAFE_SCAN_CONTENTS 1.60 +#define SAFE_SCAN_CONTENTS(dtb,name,contents,csiz,fsiz) \ 1.61 + (!dtb || (dtb->flags & DR_LOCKING)) ? \ 1.62 + safe_scan_contents (dtb,name,contents,csiz,fsiz) : \ 1.63 + scan_contents (dtb,name,contents,csiz,fsiz) 1.64 +#undef SAFE_COPY 1.65 +#define SAFE_COPY(dtb,stream,seq,mbx,bits) (dtb->flags & DR_LOCKING) ? \ 1.66 + safe_copy (dtb,stream,seq,mbx,bits) : (*dtb->copy) (stream,seq,mbx,bits) 1.67 +#undef SAFE_APPEND 1.68 +#define SAFE_APPEND(dtb,stream,mbx,af,data) (dtb->flags & DR_LOCKING) ? \ 1.69 + safe_append (dtb,stream,mbx,af,data) : (*dtb->append) (stream,mbx,af,data) 1.70 + 1.71 +#undef MM_EXISTS 1.72 +#define MM_EXISTS (lockslavep ? slave_exists : mm_exists) 1.73 +#undef MM_EXPUNGED 1.74 +#define MM_EXPUNGED (lockslavep ? slave_expunged : mm_expunged) 1.75 +#undef MM_FLAGS 1.76 +#define MM_FLAGS (lockslavep ? slave_flags : mm_flags) 1.77 +#undef MM_NOTIFY 1.78 +#define MM_NOTIFY (lockslavep ? slave_notify : mm_notify) 1.79 +#undef MM_STATUS 1.80 +#define MM_STATUS (lockslavep ? slave_status : mm_status) 1.81 +#undef MM_LOG 1.82 +#define MM_LOG (lockslavep ? slave_log : mm_log) 1.83 +#undef MM_CRITICAL 1.84 +#define MM_CRITICAL (lockslavep ? slave_critical : mm_critical) 1.85 +#undef MM_NOCRITICAL 1.86 +#define MM_NOCRITICAL (lockslavep ? slave_nocritical : mm_nocritical) 1.87 +#undef MM_DISKERROR 1.88 +#define MM_DISKERROR (lockslavep ? slave_diskerror : mm_diskerror) 1.89 +#undef MM_FATAL 1.90 +#define MM_FATAL (lockslavep ? slave_fatal : mm_fatal) 1.91 +#undef MM_APPEND 1.92 +#define MM_APPEND(af) (lockslavep ? slave_append : (*af)) 1.93 + 1.94 +/* Function prototypes */ 1.95 + 1.96 +int flocksim (int fd,int operation); 1.97 + 1.98 +long safe_delete (DRIVER *dtb,MAILSTREAM *stream,char *mbx); 1.99 +long safe_rename (DRIVER *dtb,MAILSTREAM *stream,char *old,char *newname); 1.100 +long safe_status (DRIVER *dtb,MAILSTREAM *stream,char *mbx,long flags); 1.101 +long safe_scan_contents (DRIVER *dtb,char *name,char *contents, 1.102 + unsigned long csiz,unsigned long fsiz); 1.103 +long safe_copy (DRIVER *dtb,MAILSTREAM *stream,char *seq,char *mbx,long flags); 1.104 +long safe_append (DRIVER *dtb,MAILSTREAM *stream,char *mbx,append_t af, 1.105 + void *data); 1.106 + 1.107 +void slave_exists (MAILSTREAM *stream,unsigned long number); 1.108 +void slave_expunged (MAILSTREAM *stream,unsigned long number); 1.109 +void slave_flags (MAILSTREAM *stream,unsigned long number); 1.110 +void slave_notify (MAILSTREAM *stream,char *string,long errflg); 1.111 +void slave_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status); 1.112 +void slave_log (char *string,long errflg); 1.113 +void slave_critical (MAILSTREAM *stream); 1.114 +void slave_nocritical (MAILSTREAM *stream); 1.115 +long slave_diskerror (MAILSTREAM *stream,long errcode,long serious); 1.116 +void slave_fatal (char *string); 1.117 +long slave_append (MAILSTREAM *stream,void *data,char **flags,char **date, 1.118 + STRING **message); 1.119 +long slaveproxycopy (MAILSTREAM *stream,char *sequence,char *mailbox, 1.120 + long options);