Cross Reference: field_buf.c
xref
: /
osnet-11
/
usr
/
src
/
lib
/
libeti
/
form
/
common
/
field_buf.c
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
2
N/A
/*
2
N/A
* CDDL HEADER START
2
N/A
*
2
N/A
* The contents of this file are subject to the terms of the
2
N/A
* Common Development and Distribution License, Version 1.0 only
2
N/A
* (the "License"). You may not use this file except in compliance
2
N/A
* with the License.
2
N/A
*
2
N/A
* You can obtain a copy of the license at
usr
/
src
/
OPENSOLARIS.LICENSE
2
N/A
* or
http://www.opensolaris.org/os/licensing
.
2
N/A
* See the License for the specific language governing permissions
2
N/A
* and limitations under the License.
2
N/A
*
2
N/A
* When distributing Covered Code, include this CDDL HEADER in each
2
N/A
* file and include the License file at
usr
/
src
/
OPENSOLARIS.LICENSE
.
2
N/A
* If applicable, add the following below this CDDL HEADER, with the
2
N/A
* fields enclosed by brackets "[]" replaced with your own identifying
2
N/A
* information: Portions Copyright [yyyy] [name of copyright owner]
2
N/A
*
2
N/A
* CDDL HEADER END
2
N/A
*/
2
N/A
/* Copyright (c) 1988 AT&T */
2
N/A
/* All Rights Reserved */
2
N/A
2
N/A
2
N/A
/*
2
N/A
* Copyright (c) 1997, by Sun Microsystems, Inc.
2
N/A
* All rights reserved.
2
N/A
*/
2
N/A
2
N/A
#
pragma
ident
"%Z%%M% %I% %E% SMI"
/* SVr4.0 1.4 */
2
N/A
2
N/A
/*LINTLIBRARY*/
2
N/A
2
N/A
#
include
<
sys
/
types.h
>
2
N/A
#
include
"
utility.h
"
2
N/A
2
N/A
int
2
N/A
set_field_buffer
(
FIELD
*f,
int
n,
char
*v)
2
N/A
{
2
N/A
char
*p;
2
N/A
char
*x;
2
N/A
size_t
s;
2
N/A
int
err
= 0;
2
N/A
int
len
;
2
N/A
int
size
;
2
N/A
2
N/A
if
(!f || !v || n < 0 || n > f->
nbuf
)
2
N/A
return
(
E_BAD_ARGUMENT
);
2
N/A
2
N/A
len
= (
int
)
strlen
(v);
2
N/A
size
=
BufSize
(f);
2
N/A
2
N/A
if
(
Status
(f,
GROWABLE
) &&
len
>
size
)
2
N/A
if
(!
_grow_field
(f, (
len
-
size
-
1
)/
GrowSize
(f) +
1
))
2
N/A
return
(
E_SYSTEM_ERROR
);
2
N/A
2
N/A
x =
Buffer
(f, n);
2
N/A
s =
BufSize
(f);
2
N/A
p =
memccpy
(x, v,
'\0'
, s);
2
N/A
2
N/A
if
(p)
2
N/A
(
void
)
memset
(p -
1
,
' '
, (
size_t
) (s - (p - x) +
1
));
2
N/A
2
N/A
if
(n == 0) {
2
N/A
if
(
_sync_field
(f) !=
E_OK
)
2
N/A
++
err
;
2
N/A
if
(
_sync_linked
(f) !=
E_OK
)
2
N/A
++
err
;
2
N/A
}
2
N/A
return
(
err
?
E_SYSTEM_ERROR
:
E_OK
);
2
N/A
}
2
N/A
2
N/A
char
*
2
N/A
field_buffer
(
FIELD
*f,
int
n)
2
N/A
{
2
N/A
/*
2
N/A
* field_buffer may not be accurate on the current field unless
2
N/A
* called from within the check validation function or the
2
N/A
*
form
/
field
init
/
term
functions.
2
N/A
* field_buffer is always accurate on validated fields.
2
N/A
*/
2
N/A
2
N/A
if
(f && n >= 0 && n <= f ->
nbuf
)
2
N/A
return
(
Buffer
(f, n));
2
N/A
else
2
N/A
return
((
char
*) 0);
2
N/A
}