xref: /titanic_53/usr/src/cmd/sendmail/libsm/flags.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000-2001, 2003 Sendmail, Inc. and its suppliers.
3*7c478bd9Sstevel@tonic-gate  *      All rights reserved.
4*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1990, 1993
5*7c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
6*7c478bd9Sstevel@tonic-gate  *
7*7c478bd9Sstevel@tonic-gate  * This code is derived from software contributed to Berkeley by
8*7c478bd9Sstevel@tonic-gate  * Chris Torek.
9*7c478bd9Sstevel@tonic-gate  *
10*7c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
11*7c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
12*7c478bd9Sstevel@tonic-gate  * the sendmail distribution.
13*7c478bd9Sstevel@tonic-gate  */
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate #include <sm/gen.h>
18*7c478bd9Sstevel@tonic-gate SM_RCSID("@(#)$Id: flags.c,v 1.20.2.1 2003/09/03 18:51:56 ca Exp $")
19*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
20*7c478bd9Sstevel@tonic-gate #include <sys/file.h>
21*7c478bd9Sstevel@tonic-gate #include <errno.h>
22*7c478bd9Sstevel@tonic-gate #include <sm/io.h>
23*7c478bd9Sstevel@tonic-gate 
24*7c478bd9Sstevel@tonic-gate /*
25*7c478bd9Sstevel@tonic-gate **  SM_FLAGS -- translate external (user) flags into internal flags
26*7c478bd9Sstevel@tonic-gate **
27*7c478bd9Sstevel@tonic-gate **	Paramters:
28*7c478bd9Sstevel@tonic-gate **		flags -- user select flags
29*7c478bd9Sstevel@tonic-gate **
30*7c478bd9Sstevel@tonic-gate **	Returns:
31*7c478bd9Sstevel@tonic-gate **		Internal flag value matching user selected flags
32*7c478bd9Sstevel@tonic-gate */
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate int
35*7c478bd9Sstevel@tonic-gate sm_flags(flags)
36*7c478bd9Sstevel@tonic-gate 	register int flags;
37*7c478bd9Sstevel@tonic-gate {
38*7c478bd9Sstevel@tonic-gate 	register int ret;
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate 	switch(SM_IO_MODE(flags))
41*7c478bd9Sstevel@tonic-gate 	{
42*7c478bd9Sstevel@tonic-gate 	  case SM_IO_RDONLY:	/* open for reading */
43*7c478bd9Sstevel@tonic-gate 		ret = SMRD;
44*7c478bd9Sstevel@tonic-gate 		break;
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate 	  case SM_IO_WRONLY:	/* open for writing */
47*7c478bd9Sstevel@tonic-gate 		ret = SMWR;
48*7c478bd9Sstevel@tonic-gate 		break;
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate 	  case SM_IO_APPEND:	/* open for appending */
51*7c478bd9Sstevel@tonic-gate 		ret = SMWR;
52*7c478bd9Sstevel@tonic-gate 		break;
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate 	  case SM_IO_RDWR:	/* open for read and write */
55*7c478bd9Sstevel@tonic-gate 		ret = SMRW;
56*7c478bd9Sstevel@tonic-gate 		break;
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate 	  default:
59*7c478bd9Sstevel@tonic-gate 		ret = 0;
60*7c478bd9Sstevel@tonic-gate 		break;
61*7c478bd9Sstevel@tonic-gate 	}
62*7c478bd9Sstevel@tonic-gate 	if (SM_IS_BINARY(flags))
63*7c478bd9Sstevel@tonic-gate 		ret |= SM_IO_BINARY;
64*7c478bd9Sstevel@tonic-gate 	return ret;
65*7c478bd9Sstevel@tonic-gate }
66