2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 2N/A/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2N/A/* All Rights Reserved */ 2N/A/* Copyright (c) 1987, 1988 Microsoft Corporation */ 2N/A/* All Rights Reserved */ 2N/A int Dcflags;
/* [re-]initialized on each call to defopen() */ 2N/A * destructor for per-thread data, registered with tsdalloc() 2N/A * get the per-thread-data-item for the calling thread 2N/A * defopen() - declare defopen filename 2N/A * If 'fn' is non-null; it is a full pathname of a file 2N/A * which becomes the one read by subsequent defread() calls. 2N/A * If 'fn' is null the defopen file is closed. 2N/A * see defread() for more details. 2N/A * EXIT returns 0 if ok 2N/A * returns -1 if error 2N/A * defopen_r() - declare defopen filename (reentrant) 2N/A * defopen_r(const char *fn) 2N/A * 'fn' is a full pathname of a file which becomes the one read 2N/A * by subsequent defread_r() calls. defopen_r returns a pointer 2N/A * to the internally allocated buffer containing the file descriptor. 2N/A * The pointer should be specified to the following defread_r and 2N/A * defcntl_r functions. As the pointer to be returned points to 2N/A * the libc lmalloc'd memory, defclose_r must be used to close 2N/A * the defopen file and to release the allocated memory. Caller 2N/A * must not try to release the memory by free(). 2N/A * see defread_r() for more details. 2N/A * EXIT returns non-NULL pointer if success 2N/A * returns NULL if error 2N/A /* memory allocated by lmalloc gets initialized to zeros */ 2N/A * We allocate the big buffer only if the fopen() succeeds. 2N/A * Notice that we deallocate the buffer only when the thread exits 2N/A * There are misguided applications that assume that data returned 2N/A * by defread() continues to exist after defopen(NULL) is called. 2N/A * defread() - read an entry from the defopen file 2N/A * The defopen data file must have been previously opened by 2N/A * defopen(). defread scans the data file looking for a line 2N/A * which begins with the string '*cp'. If such a line is found, 2N/A * defread returns a pointer to the first character following 2N/A * the matched string (*cp). If no line is found or no file 2N/A * is open, defread() returns NULL. 2N/A * Note that there is no way to simultaneously peruse multiple 2N/A * defopen files; since there is no way of indicating 'which one' 2N/A * to defread(). If you want to peruse a secondary file you must 2N/A * recall defopen(). If you need to go back to the first file, 2N/A * you must call defopen() again. 2N/A * defread_r() - read an entry from the defopen file 2N/A * defread_r(const char *cp, void *ptr) 2N/A * defread_r scans the data file associated with the pointer 2N/A * specified by 'ptr' that was returned by defopen_r(), and 2N/A * looks for a line which begins with the string '*cp'. 2N/A * If such a line is found, defread_r returns a pointer to 2N/A * the first character following the matched string (*cp). 2N/A * If no line is found or no file is open, defread_r() returns NULL. 2N/A break;
/* line too long */ 2N/A /* strip quotes if requested */ 2N/A * defcntl -- default control 2N/A * oldflags = defcntl(cmd, arg); 2N/A * cmd Command. One of DC_GET, DC_SET. 2N/A * arg Depends on command. If DC_GET, ignored. 2N/A * If DC_SET, new flags value, created by ORing 2N/A * oldflags Old value of flags. -1 on error. 2N/A * The following commands are implemented: 2N/A * DC_CASE: respect(on)/ignore(off) case 2N/A * DC_NOREWIND: don't(on)/do(off) reqind in defread 2N/A * DC_STRIP_QUOTES: strip(on)/leave(off) qoates 2N/A * defcntl_r -- default control 2N/A * oldflags = defcntl_r(int cmd, int arg, void *defp); 2N/A * cmd Command. One of DC_GET, DC_SET. 2N/A * arg Depends on command. If DC_GET, ignored. 2N/A * If DC_SET, new flags value, created by ORing 2N/A * defp pointer to the defopen'd descriptor 2N/A * oldflags Old value of flags. -1 on error. 2N/A * The following commands are implemented: 2N/A * DC_CASE: respect(on)/ignore(off) case 2N/A * DC_NOREWIND: don't(on)/do(off) reqind in defread 2N/A * DC_STRIP_QUOTES: strip(on)/leave(off) qoates 2N/A default:
/* error */ 2N/A * defclose_r() - close defopen file 2N/A * defclose_r(void *defp) 2N/A * defclose_r closes the defopen file associated with the specified 2N/A * pointer and releases the allocated resources. 2N/A * strip_quotes -- strip double (") or single (') quotes from a buffer 2N/A * ptr initial string 2N/A * ptr string with quotes (if any) removed