TIOCGPGRP copies an int out of the kernel
[unix-history] / usr / src / lib / libc / stdio / flags.c
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* %sccs.include.redist.c%
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)flags.c 5.1 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/file.h>
#include <stdio.h>
#include <errno.h>
/*
* Return the (stdio) flags for a given mode. Store the flags
* to be passed to an open() syscall through *optr.
* Return 0 on error.
*/
__sflags(mode, optr)
register char *mode;
int *optr;
{
register int ret, m, o;
switch (*mode++) {
case 'r': /* open for reading */
ret = __SRD;
m = O_RDONLY;
o = 0;
break;
case 'w': /* open for writing */
ret = __SWR;
m = O_WRONLY;
o = O_CREAT | O_TRUNC;
break;
case 'a': /* open for appending */
ret = __SWR;
m = O_WRONLY;
o = O_CREAT | O_APPEND;
break;
default: /* illegal mode */
errno = EINVAL;
return (0);
}
/* [rwa]\+ or [rwa]b\+ means read and write */
if (*mode == '+' || (*mode == 'b' && mode[1] == '+')) {
ret = __SRW;
m = O_RDWR;
}
*optr = m | o;
return (ret);
}