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