xref: /illumos-gate/usr/src/cmd/sendmail/libsm/flags.c (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
2*058561cbSjbeck  * Copyright (c) 2000-2001, 2004, 2006 Sendmail, Inc. and its suppliers.
37c478bd9Sstevel@tonic-gate  *      All rights reserved.
47c478bd9Sstevel@tonic-gate  * Copyright (c) 1990, 1993
57c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * This code is derived from software contributed to Berkeley by
87c478bd9Sstevel@tonic-gate  * Chris Torek.
97c478bd9Sstevel@tonic-gate  *
107c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
117c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
127c478bd9Sstevel@tonic-gate  * the sendmail distribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate #include <sm/gen.h>
16*058561cbSjbeck SM_RCSID("@(#)$Id: flags.c,v 1.23 2006/12/19 19:44:23 ca Exp $")
177c478bd9Sstevel@tonic-gate #include <sys/types.h>
187c478bd9Sstevel@tonic-gate #include <sys/file.h>
197c478bd9Sstevel@tonic-gate #include <errno.h>
207c478bd9Sstevel@tonic-gate #include <sm/io.h>
21*058561cbSjbeck #include "local.h"
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate /*
247c478bd9Sstevel@tonic-gate **  SM_FLAGS -- translate external (user) flags into internal flags
257c478bd9Sstevel@tonic-gate **
267c478bd9Sstevel@tonic-gate **	Paramters:
277c478bd9Sstevel@tonic-gate **		flags -- user select flags
287c478bd9Sstevel@tonic-gate **
297c478bd9Sstevel@tonic-gate **	Returns:
307c478bd9Sstevel@tonic-gate **		Internal flag value matching user selected flags
317c478bd9Sstevel@tonic-gate */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate int
347c478bd9Sstevel@tonic-gate sm_flags(flags)
35*058561cbSjbeck 	int flags;
367c478bd9Sstevel@tonic-gate {
37*058561cbSjbeck 	int ret;
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate 	switch(SM_IO_MODE(flags))
407c478bd9Sstevel@tonic-gate 	{
417c478bd9Sstevel@tonic-gate 	  case SM_IO_RDONLY:	/* open for reading */
427c478bd9Sstevel@tonic-gate 		ret = SMRD;
437c478bd9Sstevel@tonic-gate 		break;
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate 	  case SM_IO_WRONLY:	/* open for writing */
467c478bd9Sstevel@tonic-gate 		ret = SMWR;
477c478bd9Sstevel@tonic-gate 		break;
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate 	  case SM_IO_APPEND:	/* open for appending */
507c478bd9Sstevel@tonic-gate 		ret = SMWR;
517c478bd9Sstevel@tonic-gate 		break;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	  case SM_IO_RDWR:	/* open for read and write */
547c478bd9Sstevel@tonic-gate 		ret = SMRW;
557c478bd9Sstevel@tonic-gate 		break;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 	  default:
587c478bd9Sstevel@tonic-gate 		ret = 0;
597c478bd9Sstevel@tonic-gate 		break;
607c478bd9Sstevel@tonic-gate 	}
617c478bd9Sstevel@tonic-gate 	if (SM_IS_BINARY(flags))
627c478bd9Sstevel@tonic-gate 		ret |= SM_IO_BINARY;
637c478bd9Sstevel@tonic-gate 	return ret;
647c478bd9Sstevel@tonic-gate }
65