srchcfile.c revision 5c51f1241dbbdf2656d0e10011981411ed0c9673
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER START
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The contents of this file are subject to the terms of the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Common Development and Distribution License (the "License").
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You may not use this file except in compliance with the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * or http://www.opensolaris.org/os/licensing.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * See the License for the specific language governing permissions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and limitations under the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If applicable, add the following below this CDDL HEADER, with the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER END
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Use is subject to license terms.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* All Rights Reserved */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Forward declarations
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int getstr(char **cp, int n, char *str, int separator[]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandint getnumvfp(char **cp, int base, long *d, long bad);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandint getlnumvfp(char **cp, int base, fsblkcnt_t *d, long bad);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Module globals
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char lpath[PATH_MAX]; /* for ept->path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char mylocal[PATH_MAX]; /* for ept->ainfo.local */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * These arrays must be indexable by an unsigned char.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: WRITEDATA
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: write out data to VFP_T given start and end pointers
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: VFP - (VFP_T *) - [RO, *RW]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Contents file VFP to narrow search on
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * FIRSTPOS - (char *) - [RO, *RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Pointer to first byte to write out
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * LASTPOS - (char *) - [RO, *RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Pointer to last byte to write out
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* compute number of bytes skipped */ \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland XXlenXX = (ptrdiff_t)(LASTPOS) - (ptrdiff_t)(FIRSTPOS); \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* write the bytes out */ \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: COPYPATH
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: copy path limiting size to destination capacity
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: DEST - (char []) - [RW]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * SRC - (char *) - [RO, *RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Pointer to first byte of path to copy
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * LEN - (int) - [RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Number of bytes to copy
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* assure return path does not overflow */ \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy return path to local storage */ \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: narrowSearch
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: narrow the search location for a specified path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The contents and package map files are always sorted by path.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function is given a target path to search for given the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * current location in a contents file. It is assured that the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * target path has not been searched for yet in the contents file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * so the current location in the contents file is guaranteed to
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * be less than the location of the target path (if present).
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Given this employ a binary search to speed up the search for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the path nearest to a specified target path.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: a_vfp - (VFP_T *) - [RO, *RW]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Contents file VFP to narrow search on
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_path - (char *) - [RO, *RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Pointer to path to search for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_pathLen - (size_t) - [RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Length of string (a_path)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: char * - pointer to first byte of entry in contents file that
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is guaranteed to be the closest match to the specified
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_path without being "greater than" the path.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == (char *)NULL if no entry found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandnarrowSearch(VFP_T *a_vfp, char *a_path, size_t a_pathLen)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if no path to compare, start at beginning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_path == (char *)NULL) || (*a_path == '\0')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return ((char *)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if the contents file is empty, resort to sequential search */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return ((char *)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * test against first path - if the path specified is less than the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * first path in the contents file, then the path can be inserted
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * before the first entry in the contents file.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* locate start of first line */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if first path not absolute, resort to sequential search */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return ((char *)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* find end of path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine length of path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* compare target path with current path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if lengths same exact match return position found */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not exact match - a_path > pm */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return if target is less than or equal to first entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n <= 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * test against last path - if the path specified is greater than the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * last path in the contents file, then the path can be appended after
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the last entry in the contents file.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* locate start of last line */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((pmid > plow) && (!((pmid[0] == '/') && (pmid[-1] == '\n')))) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if absolute path, do comparison */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* find end of path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine length of path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* compare target path with current path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if lengths same exact match return position found */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not exact match - a_path > pm */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return if target is greater than or equal to entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n >= 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * firstPath < targetpath < lastPath:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * binary search looking for closest "less than" match
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine number of bytes left in search area */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* calculate mid point between current low and high points */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* backup and find first "\n/" -or- start of buffer */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (!((pmid[0] == '/') && (pmid[-1] == '\n')))) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return lowest line found if current line not past that */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* remember start of this line */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* find end of path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine length of path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* compare target path with current path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if lengths same exact match return position found */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not exact match - a_path > pm */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not exact match - determine which watermark to split */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n > 0) { /* a_path > pm */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else { /* a_path < pm */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*NOTREACHED*/
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: srchcfile
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: search contents file looking for closest match to entry,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * creating a new contents file if output contents file specified
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: ept - (struct cfent *) - [RO, *RW]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - contents file entry, describing last item found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * path - (char *) - [RO, *RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - path to search for in contents file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - If path is "*", then the next entry is returned;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the next entry always matches this path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - If the path is (char *)NULL or "", then all remaining
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * entries are processed and copied out to the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file specified by cfTmpVFp
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * cfVfp - (VFP_T *) - [RO, *RW]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - VFP_T open on contents file to search
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * cfTmpVfp - (VFP_T *) - [RO, *RW]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - VFP_T open on temporary contents file to populate
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * < 0 - error occurred
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - Use getErrstr to retrieve character-string describing
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the reason for failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - no match found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - specified path not in the contents file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - all contents of cfVfp copied to cfTmpVfp
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - current character of cfVfp is at end of file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 1 - exact match found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - specified path found in contents file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - contents of cfVfp up to entry found copied to cfTmpVfp
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - current character of cfVfp is first character of
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * entry found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - this value is always returned if path is "*" and the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * next entry is returned - -1 is returned when no more
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * entries are left to process
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 2 - entry found which is GREATER than path specified
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - specified path would fit BEFORE entry found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - contents of cfVfp up to entry found copied to cfTmpVfp
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - current character of cfVfp is first character of
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * entry found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Side Effects:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - The ept structure supplied is filled in with a description of
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the item that caused the search to terminate, except in the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * case of '0' in which case the contents of 'ept' is undefined.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - NOTE: the ept->path item points to a path that is statically
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * allocated and will be overwritten on the next call.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - NOTE: the ept->ainfo.local item points to a path that is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * statically allocated and will be overwritten on the next call.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandsrchcfile(struct cfent *ept, char *path, VFP_T *cfVfp, VFP_T *cfTmpVfp)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this code does not use nested subroutines because execution time
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * of this routine is especially critical to installation and upgrade
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initialize local variables */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(NULL); /* no error message currently cached */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pathLength = (path == (char *)NULL ? 0 : strlen(path));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initialize ept structure values */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcpy(ept->ainfo.group, BADGROUP, sizeof (ept->ainfo.group));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcpy(ept->ainfo.owner, BADOWNER, sizeof (ept->ainfo.owner));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcpy(ept->pkg_class, BADCLASS, sizeof (ept->pkg_class));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * populate decision tables that implement fast character checking;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this is much faster than the equivalent strpbrk() call or a
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * while() loop checking for the characters. It is only faster if
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * there are at least 3 characters to scan for - when checking for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * one or two characters (such as '\n' or '\0') its faster to do
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a simple while() loop.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * any chars listed stop scan;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * scan stops on first byte found that is set to '1' below
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Separators for path names, normal space and =
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * for linked filenames
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland bzero(ISPKGPATHSEP, sizeof (ISPKGPATHSEP));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISPKGPATHSEP['\t'] = 1; /* horizontal-tab */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISPKGPATHSEP['\0'] = 1; /* NULL character */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Separators for normal words
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Separators for list of packages, includes \\ for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * alternate ftype and : for classname
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland bzero(ISPKGNAMESEP, sizeof (ISPKGNAMESEP));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if no bytes in contents file, return 0 */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if the path to scan for is empty, act like no path was specified */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((path != (char *)NULL) && (*path == '\0')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if path to search for is "*", then we will return the first path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * we encounter as a match, otherwise we return an error
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((path != (char *)NULL) && (path[0] != '/')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(pkg_gt(ERR_ILLEGAL_SEARCH_PATH));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* attempt to narrow down the search for the specified path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland np = narrowSearch(cfVfp, path, pathLength);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If the path to search for in the source contents file is NULL, then
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this is a request to scan to the end of the source contents file. If
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * there is a temporary contents file to copy entries to, all that needs
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to be done is to copy the data remaining from the current location in
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the source contents file to the end of the temporary contents file.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if there is no temporary contents file to copy to, then all that
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * needs to be done is to seek to the end of the source contents file.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((anypath == 0) && (path == (char *)NULL)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * main loop processing entries from the contents file looking for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the specified path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not reading old style entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine first character of the next entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* no bytes in contents file current char is NULL */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* grab path from first entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* save current position in file */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * =============================================================
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * at the first character of the next entry in the contents file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if not absolute path check for exceptions and old style entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * --> if end of contents file write out skipped data and return
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * --> if comment character skip to end of line and restart loop
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * --> else process "old style entry: ftype class path"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * =============================================================
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (c != '/') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if NULL character then end of contents file found */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (c == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* write out skipped data before returning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (0); /* no more entries */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* ignore lines that begin with #, : or a "space" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((isspace(c) != 0) || (c == '#') || (c == ':')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* line is a comment */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * old style entry - format is:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * ftype class path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set ept->ftype to the type
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set ept->class to the class
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set ept->path to point to lpath
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set cpath_start/cpath_len to point to the file name
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set rdpath to '1' to indicate old style entry parsed
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?': case 'f': case 'v': case 'e': case 'l':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case 's': case 'p': case 'c': case 'b': case 'd':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* save ftype */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* save class */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getstr(&vfpGetCurrCharPtr(cfVfp), CLSSIZ,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * locate file name up to "=", set cpath_start
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and cpath_len to point to the file name
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * skip past all bytes until first '= \t\n\0':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (ISPKGPATHSEP[(int)*p] == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if the path is zero bytes, line is corrupted
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set path to point to local path cache */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set flag indicating path already parsed */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* end of line before new-line seen */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '0': case '1': case '2': case '3': case '4':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '5': case '6': case '7': case '8': case '9':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* volume number seen */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* type i files are not cataloged */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* unknown ftype */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * current entry DOES start with absolute path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set ept->path to point to lpath
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set cpath_start/cpath_len to point to the file name
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy first token into path element of passed structure */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * skip past all bytes until first from '= \t\n\0':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (ISPKGPATHSEP[(int)*p] == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * =============================================================
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if absolute path then the path is collected and we are at the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * first byte following the absolute path name;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if not an absolute path then an old style entry, ept has been
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * filled with the type and class and path name.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * determine if we have read the pathname which identifies
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the entry we are searching for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * =============================================================
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = 0; /* next entry is "equal to" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((n == 0) && (cpath_len != pathLength)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get first character following the end of the path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if an exact match, always parse out the local path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * we want to return information about this path in
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the structure provided, so parse any local path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and jump to code which parses rest of the input line
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (c == '=') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* parse local path specification */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getstr(&vfpGetCurrCharPtr(cfVfp), PATH_MAX,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if an exact match and processing a new style entry, read the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * remaining information from the new style entry - if this is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * an old style entry (rdpath != 0) then the existing info has
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * already been processed as it exists before the pathname and
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * not after like a new style entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0 && rdpath == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?': case 'f': case 'v': case 'e': case 'l':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case 's': case 'p': case 'c': case 'b': case 'd':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* save ftype */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* save class */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getstr(&vfpGetCurrCharPtr(cfVfp), CLSSIZ,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break; /* we already read the pathname */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* end of line before new-line seen */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '0': case '1': case '2': case '3': case '4':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '5': case '6': case '7': case '8': case '9':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* unknown ftype */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if an exact match all processing is completed; break out of
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the main processing loop and finish processing this entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * prior to returning to the caller.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this entry is not an exact match for the path being searched
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * for - if this entry is GREATER THAN the path being searched
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * for then finish processing and return GREATER THAN result
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to the caller so the entry for the path being searched for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * can be added to the contents file.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the entry we want would fit BEFORE the one we just
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * read, so we need to unread what we've read by
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * seeking back to the start of this entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* write out any skipped data before returning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dataSkipped && (cfTmpVfp != (VFP_T *)NULL)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This entry is "LESS THAN" the specified path to search for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * need to process the next entry from the contents file. First,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if writing to new contents file, update new contents file if
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * processing old style entry; otherwise, update skipped data
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * information to remember current last byte of skipped data.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* modify record: write out any skipped data */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * copy what we've read and the rest of this
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * line onto the specified output stream
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpPutBytes(cfTmpVfp, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland px = strchr(vfpGetCurrCharPtr(cfVfp), '\n');
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* reset skiped bytes if any data skipped */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* skip data */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland px = strchr(vfpGetCurrCharPtr(cfVfp), '\n');
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * since this isn't the entry we want, just read the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * stream until we find the end of this entry and
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * then start this search loop again
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland px = strchr(vfpGetCurrCharPtr(cfVfp), '\n');
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * end of main loop processing entries from contents file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the loop is broken out of when an exact match for the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * path being searched for has been found and the type is one of:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - ?fvelspcbdx
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * at this point parsing is at the first character past the full path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * name on an exact match for the path being looked for - parse the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * remainder of the entries information into the ept structure.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* link/symbolic link must have link destination */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (((ept->ftype == 's') || (ept->ftype == 'l')) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* character/block devices have major/minor device numbers */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (((ept->ftype == 'c') || (ept->ftype == 'b'))) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getnumvfp(&vfpGetCurrCharPtr(cfVfp), 10,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(pkg_gt(ERR_CANNOT_READ_MM_NUMS));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* most types have mode, owner, group identification components */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((ept->ftype == 'd') || (ept->ftype == 'x') || (ept->ftype == 'c') ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (ept->ftype == 'b') || (ept->ftype == 'p') ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (ept->ftype == 'f') || (ept->ftype == 'v') ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* mode, owner, group should be here */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getnumvfp(&vfpGetCurrCharPtr(cfVfp), 8,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland getstr(&vfpGetCurrCharPtr(cfVfp), sizeof (ept->ainfo.owner),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland getstr(&vfpGetCurrCharPtr(cfVfp), sizeof (ept->ainfo.group),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* i/f/v/e have size, checksum, modification time components */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((ept->ftype == 'i') || (ept->ftype == 'f') ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (ept->ftype == 'v') || (ept->ftype == 'e')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* look for content description */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getlnumvfp(&vfpGetCurrCharPtr(cfVfp), 10,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (fsblkcnt_t *)&ept->cinfo.size, BADCONT) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* i files processing is completed - return 'exact match found' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* write out any skipped data before returning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dataSkipped && (cfTmpVfp != (VFP_T *)NULL)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * determine list of packages which reference this entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getstr(&vfpGetCurrCharPtr(cfVfp), sizeof (pkgname),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if c < 0 the string was too long to fix in the buffer */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* a package is present - create and populate pinfo structure */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pinfo = (struct pinfo *)calloc(1, sizeof (struct pinfo));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((pkgname[0] == '-') || (pkgname[0] == '+') ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (pkgname[0] == '*') || (pkgname[0] == '~') ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (pkgname[0] == '!') || (pkgname[0] == '%')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* pkg/[:[ftype][:class] */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (c == '\\') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get alternate ftype */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (c == ':') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get special classname */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* break out of while if at end of entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if package not separated by a space return an error */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * parsing of the entry is complete
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* write out any skipped data before returning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dataSkipped && (cfTmpVfp != (VFP_T *)NULL)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if not at the end of the entry, make it so */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getend(&vfpGetCurrCharPtr(cfVfp)) && ept->pinfo) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandgetstr(char **cp, int n, char *str, int separator[])
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*p == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* leading white space ignored */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (((c = *p) != '\0') && (isspace(*p++)))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* compute length based on delimiter found or not */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if string will fit in result buffer copy string and return success */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* result buffer too small; copy partial string, return error */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if at end of buffer return no more characters left */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*p == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if at end of buffer return no more characters left */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*p == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* find the end of the line */