2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
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 *
2N/A * CDDL HEADER END
2N/A */
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A
2N/A/*
2N/A * Copyright (c) 1997, by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.4 */
2N/A
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <sys/types.h>
2N/A#include "utility.h"
2N/A
2N/Aint
2N/Aset_field_buffer(FIELD *f, int n, char *v)
2N/A{
2N/A char *p;
2N/A char *x;
2N/A size_t s;
2N/A int err = 0;
2N/A int len;
2N/A int size;
2N/A
2N/A if (!f || !v || n < 0 || n > f->nbuf)
2N/A return (E_BAD_ARGUMENT);
2N/A
2N/A len = (int) strlen(v);
2N/A size = BufSize(f);
2N/A
2N/A if (Status(f, GROWABLE) && len > size)
2N/A if (!_grow_field(f, (len - size - 1)/GrowSize(f) + 1))
2N/A return (E_SYSTEM_ERROR);
2N/A
2N/A x = Buffer(f, n);
2N/A s = BufSize(f);
2N/A p = memccpy(x, v, '\0', s);
2N/A
2N/A if (p)
2N/A (void) memset(p - 1, ' ', (size_t) (s - (p - x) + 1));
2N/A
2N/A if (n == 0) {
2N/A if (_sync_field(f) != E_OK)
2N/A ++err;
2N/A if (_sync_linked(f) != E_OK)
2N/A ++err;
2N/A }
2N/A return (err ? E_SYSTEM_ERROR : E_OK);
2N/A}
2N/A
2N/Achar *
2N/Afield_buffer(FIELD *f, int n)
2N/A{
2N/A/*
2N/A * field_buffer may not be accurate on the current field unless
2N/A * called from within the check validation function or the
2N/A * form/field init/term functions.
2N/A * field_buffer is always accurate on validated fields.
2N/A */
2N/A
2N/A if (f && n >= 0 && n <= f -> nbuf)
2N/A return (Buffer(f, n));
2N/A else
2N/A return ((char *) 0);
2N/A}