usr/src/lib/libc/port/gen/deflt.c
author Jon Tibble <meths@btinternet.com>
Thu, 09 Dec 2010 22:32:39 +0100
changeset 13255 4afa820d78b9
parent 8563 3cefe121bbd2
permissions -rw-r--r--
298 SPARC build fails in smt_pause.o 478 Build needs fixing for pkgdepend flag day Reviewed by: [email protected] Reviewed by: [email protected] Reviewed by: [email protected] Approved by: [email protected]
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     1
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     2
 * CDDL HEADER START
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     3
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1914
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 1219
diff changeset
     5
 * Common Development and Distribution License (the "License").
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 1219
diff changeset
     6
 * You may not use this file except in compliance with the License.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     7
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    11
 * and limitations under the License.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    12
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    18
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    19
 * CDDL HEADER END
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    20
 */
1219
f89f56c2d9ac 6362982 namespace pollution/protection in libc
raf
parents: 0
diff changeset
    21
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    22
/*
8563
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
    23
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    24
 * Use is subject to license terms.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    25
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    26
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    27
/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    28
/*	  All Rights Reserved  	*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    29
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    30
/*	Copyright (c) 1987, 1988 Microsoft Corporation	*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    31
/*	  All Rights Reserved	*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    32
6812
febeba71273d PSARC 2008/309 expunge synonyms.h
raf
parents: 2923
diff changeset
    33
#include "lint.h"
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    34
#include "libc.h"
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    35
#include <stdio.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    36
#include <stdlib.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    37
#include <deflt.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    38
#include <sys/types.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    39
#include <string.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    40
#include <ctype.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    41
#include <unistd.h>
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    42
#include "tsd.h"
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    43
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    44
#define	TSTBITS(flags, mask)	(((flags) & (mask)) == (mask))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    45
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    46
struct thr_data {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    47
	int  Dcflags;	/* [re-]initialized on each call to defopen() */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    48
	FILE *fp;
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    49
	char *buf;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    50
};
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    51
8563
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
    52
static int	defopen_common(const char *, struct thr_data *);
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
    53
static void strip_quotes(char *);
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
    54
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    55
#define	BUFFERSIZE	1024
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    56
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    57
/*
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    58
 * destructor for per-thread data, registered with tsdalloc()
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    59
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    60
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    61
free_thr_data(void *arg)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    62
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    63
	struct thr_data *thr_data = (struct thr_data *)arg;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    64
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    65
	if (thr_data->fp) {
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    66
		(void) fclose(thr_data->fp);
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    67
		thr_data->fp = NULL;
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    68
	}
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    69
	if (thr_data->buf) {
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    70
		lfree(thr_data->buf, BUFFERSIZE);
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    71
		thr_data->buf = NULL;
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    72
	}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    73
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    74
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    75
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    76
 * get the per-thread-data-item for the calling thread
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    77
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    78
static struct thr_data *
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    79
get_thr_data(void)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    80
{
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    81
	struct thr_data *thr_data =
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
    82
	    tsdalloc(_T_DEFREAD, sizeof (*thr_data), free_thr_data);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    83
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    84
	return (thr_data);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    85
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    86
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    87
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    88
 *	defopen() - declare defopen filename
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    89
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    90
 *	defopen(fn)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    91
 *		char *fn
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    92
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    93
 *	If 'fn' is non-null; it is a full pathname of a file
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    94
 *	which becomes the one read by subsequent defread() calls.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    95
 *	If 'fn' is null the defopen file is closed.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    96
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    97
 *	see defread() for more details.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    98
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    99
 *	EXIT    returns 0 if ok
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   100
 *		returns -1 if error
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   101
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   102
int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   103
defopen(char *fn)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   104
{
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   105
	struct thr_data *thr_data = get_thr_data();
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   106
8563
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   107
	return (defopen_common(fn, thr_data));
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   108
}
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   109
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   110
/*
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   111
 *	defopen_r() - declare defopen filename (reentrant)
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   112
 *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   113
 *	defopen_r(const char *fn)
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   114
 *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   115
 *	'fn' is a full pathname of a file which becomes the one read
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   116
 *	by subsequent defread_r() calls.  defopen_r returns a pointer
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   117
 *	to the internally allocated buffer containing the file descriptor.
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   118
 *	The pointer should be specified to the following defread_r and
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   119
 *	defcntl_r functions.  As the pointer to be returned points to
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   120
 *	the libc lmalloc'd memory, defclose_r must be used to close
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   121
 *	the defopen file and to release the allocated memory.  Caller
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   122
 *	must not try to release the memory by free().
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   123
 *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   124
 *	see defread_r() for more details.
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   125
 *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   126
 *	EXIT    returns non-NULL pointer if success
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   127
 *		returns NULL if error
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   128
 */
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   129
void *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   130
defopen_r(const char *fn)
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   131
{
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   132
	/* memory allocated by lmalloc gets initialized to zeros */
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   133
	struct thr_data	*thr_data = lmalloc(sizeof (struct thr_data));
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   134
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   135
	if (defopen_common(fn, thr_data) < 0) {
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   136
		if (thr_data != NULL)
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   137
			lfree(thr_data, sizeof (struct thr_data));
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   138
		return (NULL);
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   139
	}
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   140
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   141
	return ((void *)thr_data);
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   142
}
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   143
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   144
static int
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   145
defopen_common(const char *fn, struct thr_data *thr_data)
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   146
{
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   147
	if (thr_data == NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   148
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   149
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   150
	if (thr_data->fp != NULL) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   151
		(void) fclose(thr_data->fp);
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   152
		thr_data->fp = NULL;
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   153
	}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   154
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   155
	if (fn == NULL)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   156
		return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   157
1914
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 1219
diff changeset
   158
	if ((thr_data->fp = fopen(fn, "rF")) == NULL)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   159
		return (-1);
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   160
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   161
	/*
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   162
	 * We allocate the big buffer only if the fopen() succeeds.
8563
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   163
	 * Notice that we deallocate the buffer only when the thread exits
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   164
	 * for defopen().
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   165
	 * There are misguided applications that assume that data returned
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   166
	 * by defread() continues to exist after defopen(NULL) is called.
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   167
	 */
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   168
	if (thr_data->buf == NULL &&
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   169
	    (thr_data->buf = lmalloc(BUFFERSIZE)) == NULL) {
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   170
		(void) fclose(thr_data->fp);
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   171
		thr_data->fp = NULL;
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   172
		return (-1);
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   173
	}
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   174
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   175
	thr_data->Dcflags = DC_STD;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   176
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   177
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   178
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   179
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   180
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   181
 *	defread() - read an entry from the defopen file
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   182
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   183
 *	defread(cp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   184
 *		char *cp
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   185
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   186
 *	The defopen data file must have been previously opened by
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   187
 *	defopen().  defread scans the data file looking for a line
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   188
 *	which begins with the string '*cp'.  If such a line is found,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   189
 *	defread returns a pointer to the first character following
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   190
 *	the matched string (*cp).  If no line is found or no file
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   191
 *	is open, defread() returns NULL.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   192
 *
8563
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   193
 *	Note that there is no way to simultaneously peruse multiple
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   194
 *	defopen files; since there is no way of indicating 'which one'
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   195
 *	to defread().  If you want to peruse a secondary file you must
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   196
 *	recall defopen().  If you need to go back to the first file,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   197
 *	you must call defopen() again.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   198
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   199
char *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   200
defread(char *cp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   201
{
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   202
	struct thr_data *thr_data = get_thr_data();
8563
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   203
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   204
	return (defread_r(cp, thr_data));
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   205
}
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   206
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   207
/*
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   208
 *	defread_r() - read an entry from the defopen file
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   209
 *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   210
 *	defread_r(const char *cp, void *defp)
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   211
 *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   212
 *	defread_r scans the data file associated with the pointer
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   213
 *	specified by 'defp' that was returned by defopen_r(), and
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   214
 *	looks for a line which begins with the string '*cp'.
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   215
 *	If such a line is found, defread_r returns a pointer to
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   216
 *	the first character following the matched string (*cp).
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   217
 *	If no line is found or no file is open, defread_r() returns NULL.
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   218
 */
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   219
char *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   220
defread_r(const char *cp, void *ptr)
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   221
{
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   222
	struct thr_data *thr_data = (struct thr_data *)ptr;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   223
	int (*compare)(const char *, const char *, size_t);
8563
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   224
	char *buf_tmp;
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   225
	char *ret_ptr = NULL;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   226
	size_t off, patlen;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   227
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   228
	if (thr_data == NULL || thr_data->fp == NULL)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   229
		return (NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   230
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   231
	compare = TSTBITS(thr_data->Dcflags, DC_CASE) ? strncmp : strncasecmp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   232
	patlen = strlen(cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   233
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   234
	if (!TSTBITS(thr_data->Dcflags, DC_NOREWIND))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   235
		rewind(thr_data->fp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   236
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   237
	while (fgets(thr_data->buf, BUFFERSIZE, thr_data->fp)) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   238
		for (buf_tmp = thr_data->buf; *buf_tmp == ' '; buf_tmp++)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   239
			;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   240
		off = strlen(buf_tmp) - 1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   241
		if (buf_tmp[off] == '\n')
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   242
			buf_tmp[off] = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   243
		else
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   244
			break;	/* line too long */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   245
		if ((*compare)(cp, buf_tmp, patlen) == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   246
			/* found it */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   247
			/* strip quotes if requested */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   248
			if (TSTBITS(thr_data->Dcflags, DC_STRIP_QUOTES)) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   249
				strip_quotes(buf_tmp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   250
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   251
			ret_ptr = &buf_tmp[patlen];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   252
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   253
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   254
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   255
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   256
	return (ret_ptr);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   257
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   258
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   259
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   260
 *	defcntl -- default control
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   261
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   262
 *	SYNOPSIS
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   263
 *	  oldflags = defcntl(cmd, arg);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   264
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   265
 *	ENTRY
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   266
 *	  cmd		Command.  One of DC_GET, DC_SET.
8563
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   267
 *	  arg		Depends on command.  If DC_GET, ignored.
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   268
 *			If DC_SET, new flags value, created by ORing
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   269
 *			the DC_* bits.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   270
 *	RETURN
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   271
 *	  oldflags	Old value of flags.  -1 on error.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   272
 *	NOTES
8563
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   273
 *	  The following commands are implemented:
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   274
 *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   275
 *	  DC_CASE:		respect(on)/ignore(off) case
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   276
 *	  DC_NOREWIND:		don't(on)/do(off) reqind in defread
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   277
 *	  DC_STRIP_QUOTES:	strip(on)/leave(off) qoates
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   278
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   279
int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   280
defcntl(int cmd, int newflags)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   281
{
2923
da82ab368162 PSARC 2006/561 libcmd must die
raf
parents: 1914
diff changeset
   282
	struct thr_data *thr_data = get_thr_data();
8563
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   283
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   284
	return (defcntl_r(cmd, newflags, thr_data));
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   285
}
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   286
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   287
/*
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   288
 *	defcntl_r -- default control
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   289
 *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   290
 *	SYNOPSIS
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   291
 *	  oldflags = defcntl_r(int cmd, int arg, void *defp);
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   292
 *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   293
 *	ENTRY
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   294
 *	  cmd		Command.  One of DC_GET, DC_SET.
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   295
 *	  arg		Depends on command.  If DC_GET, ignored.
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   296
 *			If DC_SET, new flags value, created by ORing
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   297
 *			the DC_* bits.
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   298
 *	  defp		pointer to the defopen'd descriptor
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   299
 *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   300
 *	RETURN
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   301
 *	  oldflags	Old value of flags.  -1 on error.
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   302
 *	NOTES
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   303
 *	  The following commands are implemented:
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   304
 *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   305
 *	  DC_CASE:		respect(on)/ignore(off) case
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   306
 *	  DC_NOREWIND:		don't(on)/do(off) reqind in defread
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   307
 *	  DC_STRIP_QUOTES:	strip(on)/leave(off) qoates
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   308
 */
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   309
int
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   310
defcntl_r(int cmd, int newflags, void *ptr)
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   311
{
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   312
	struct thr_data *thr_data = (struct thr_data *)ptr;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   313
	int  oldflags;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   314
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   315
	if (thr_data == NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   316
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   317
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   318
	switch (cmd) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   319
	case DC_GETFLAGS:		/* query */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   320
		oldflags = thr_data->Dcflags;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   321
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   322
	case DC_SETFLAGS:		/* set */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   323
		oldflags = thr_data->Dcflags;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   324
		thr_data->Dcflags = newflags;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   325
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   326
	default:			/* error */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   327
		oldflags = -1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   328
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   329
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   330
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   331
	return (oldflags);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   332
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   333
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   334
/*
8563
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   335
 *	defclose_r() - close defopen file
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   336
 *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   337
 *	defclose_r(void *defp)
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   338
 *
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   339
 *	defclose_r closes the defopen file associated with the specified
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   340
 *	pointer and releases the allocated resources.
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   341
 */
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   342
void
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   343
defclose_r(void *ptr)
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   344
{
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   345
	struct thr_data *thr_data = (struct thr_data *)ptr;
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   346
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   347
	(void) fclose(thr_data->fp);
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   348
	lfree(thr_data->buf, BUFFERSIZE);
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   349
	lfree(thr_data, sizeof (struct thr_data));
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   350
}
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   351
3cefe121bbd2 6783069 libc must not use defread internally
Kenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>
parents: 6812
diff changeset
   352
/*
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   353
 *	strip_quotes -- strip double (") or single (') quotes from a buffer
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   354
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   355
 *	ENTRY
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   356
 *	  ptr		initial string
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   357
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   358
 *	EXIT
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   359
 *	  ptr		string with quotes (if any) removed
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   360
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   361
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   362
strip_quotes(char *ptr)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   363
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   364
	char *strip_ptr = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   365
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   366
	while (*ptr != '\0') {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   367
		if ((*ptr == '"') || (*ptr == '\'')) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   368
			if (strip_ptr == NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   369
				strip_ptr = ptr;	/* skip over quote */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   370
		} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   371
			if (strip_ptr != NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   372
				*strip_ptr = *ptr;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   373
				strip_ptr++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   374
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   375
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   376
		ptr++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   377
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   378
	if (strip_ptr != NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   379
		*strip_ptr = '\0';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   380
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   381
}