17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57010c12aSrie * Common Development and Distribution License (the "License").
67010c12aSrie * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217010c12aSrie
227c478bd9Sstevel@tonic-gate /*
239dc42874SAlek Pinchuk * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
249dc42874SAlek Pinchuk *
257c478bd9Sstevel@tonic-gate * Copyright (c) 1988 AT&T
267c478bd9Sstevel@tonic-gate * All Rights Reserved
277c478bd9Sstevel@tonic-gate *
287c478bd9Sstevel@tonic-gate *
29d1477c77SAli Bahrami * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
307010c12aSrie * Use is subject to license terms.
317c478bd9Sstevel@tonic-gate */
32*56b75c05SAndy Fiddaman /*
33*56b75c05SAndy Fiddaman * Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
34*56b75c05SAndy Fiddaman */
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate #include "stdlib.h"
377c478bd9Sstevel@tonic-gate #include "conv.h"
387c478bd9Sstevel@tonic-gate #include "mcs.h"
397c478bd9Sstevel@tonic-gate #include "extern.h"
407c478bd9Sstevel@tonic-gate #define OPTUNIT 100
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate static size_t optcnt = 0;
437c478bd9Sstevel@tonic-gate static size_t optbufsz = OPTUNIT;
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate * Function prototypes.
477c478bd9Sstevel@tonic-gate */
487c478bd9Sstevel@tonic-gate static void usage(int);
497c478bd9Sstevel@tonic-gate static void sigexit(int);
507c478bd9Sstevel@tonic-gate static int setup_sectname(char *, int);
517c478bd9Sstevel@tonic-gate static void queue(int, char *);
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate int
main(int argc,char ** argv,char ** envp)547c478bd9Sstevel@tonic-gate main(int argc, char ** argv, char ** envp)
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate const char *opt;
577c478bd9Sstevel@tonic-gate char *str;
589dc42874SAlek Pinchuk int error_count = 0, num_sect = 0, errflag = 0;
597c478bd9Sstevel@tonic-gate int c, i, my_prog;
607c478bd9Sstevel@tonic-gate Cmd_Info *cmd_info;
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate * Check for a binary that better fits this architecture.
647c478bd9Sstevel@tonic-gate */
657010c12aSrie (void) conv_check_native(argv, envp);
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate * mcs(1) and strip() are hard linked together, determine which command
697c478bd9Sstevel@tonic-gate * was invoked.
707c478bd9Sstevel@tonic-gate */
717c478bd9Sstevel@tonic-gate prog = argv[0];
727c478bd9Sstevel@tonic-gate if ((str = strrchr(prog, '/')) != NULL)
737c478bd9Sstevel@tonic-gate str++;
747c478bd9Sstevel@tonic-gate else
757c478bd9Sstevel@tonic-gate str = prog;
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate if (strcmp(str, "mcs") == 0) {
787c478bd9Sstevel@tonic-gate my_prog = MCS;
799dc42874SAlek Pinchuk opt = "a:cdn:pVz?";
807c478bd9Sstevel@tonic-gate } else if (strcmp(str, "strip") == 0) {
817c478bd9Sstevel@tonic-gate my_prog = STRIP;
829dc42874SAlek Pinchuk opt = "lxV?";
837c478bd9Sstevel@tonic-gate } else
84d1477c77SAli Bahrami exit(FAILURE);
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
877c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
887c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
897c478bd9Sstevel@tonic-gate #endif
907c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate for (i = 0; signum[i]; i++)
937c478bd9Sstevel@tonic-gate if (signal(signum[i], SIG_IGN) != SIG_IGN)
947c478bd9Sstevel@tonic-gate (void) signal(signum[i], sigexit);
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate if ((Action =
977c478bd9Sstevel@tonic-gate malloc(optbufsz * sizeof (struct action))) == NULL) {
987c478bd9Sstevel@tonic-gate error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog);
997c478bd9Sstevel@tonic-gate exit(FAILURE);
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate * Allocate command info structure
1047c478bd9Sstevel@tonic-gate */
1057c478bd9Sstevel@tonic-gate cmd_info = (Cmd_Info *) calloc(1, sizeof (Cmd_Info));
1067c478bd9Sstevel@tonic-gate if (cmd_info == NULL) {
1077c478bd9Sstevel@tonic-gate error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog);
1087c478bd9Sstevel@tonic-gate exit(FAILURE);
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate if (my_prog == STRIP)
111*56b75c05SAndy Fiddaman SET_OPT(cmd_info, I_AM_STRIP);
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, (char *)opt)) != EOF) {
1147c478bd9Sstevel@tonic-gate switch (c) {
1157c478bd9Sstevel@tonic-gate case 'a':
1167c478bd9Sstevel@tonic-gate optcnt++;
1177c478bd9Sstevel@tonic-gate queue(ACT_APPEND, optarg);
118*56b75c05SAndy Fiddaman SET_OPT(cmd_info, MIGHT_CHG | aFLAG);
1197c478bd9Sstevel@tonic-gate cmd_info->str_size += strlen(optarg) + 1;
1207c478bd9Sstevel@tonic-gate break;
1217c478bd9Sstevel@tonic-gate case 'c':
1227c478bd9Sstevel@tonic-gate optcnt++;
1237c478bd9Sstevel@tonic-gate queue(ACT_COMPRESS, NULL);
124*56b75c05SAndy Fiddaman SET_OPT(cmd_info, MIGHT_CHG | cFLAG);
1257c478bd9Sstevel@tonic-gate break;
1267c478bd9Sstevel@tonic-gate case 'd':
1277c478bd9Sstevel@tonic-gate optcnt++;
128*56b75c05SAndy Fiddaman if (!CHK_OPT(cmd_info, dFLAG))
1297c478bd9Sstevel@tonic-gate queue(ACT_DELETE, NULL);
130*56b75c05SAndy Fiddaman SET_OPT(cmd_info, MIGHT_CHG | dFLAG);
1317c478bd9Sstevel@tonic-gate break;
1327c478bd9Sstevel@tonic-gate case 'z':
1337c478bd9Sstevel@tonic-gate optcnt++;
1347c478bd9Sstevel@tonic-gate queue(ACT_ZAP, NULL);
135*56b75c05SAndy Fiddaman SET_OPT(cmd_info, MIGHT_CHG | zFLAG);
1367c478bd9Sstevel@tonic-gate break;
1377c478bd9Sstevel@tonic-gate case 'n':
1387c478bd9Sstevel@tonic-gate (void) setup_sectname(optarg, my_prog);
1397c478bd9Sstevel@tonic-gate num_sect++;
1407c478bd9Sstevel@tonic-gate break;
1417c478bd9Sstevel@tonic-gate case 'l':
1427c478bd9Sstevel@tonic-gate optcnt++;
143*56b75c05SAndy Fiddaman SET_OPT(cmd_info, lFLAG);
1447c478bd9Sstevel@tonic-gate break;
1457c478bd9Sstevel@tonic-gate case 'p':
1467c478bd9Sstevel@tonic-gate optcnt++;
1477c478bd9Sstevel@tonic-gate queue(ACT_PRINT, NULL);
148*56b75c05SAndy Fiddaman SET_OPT(cmd_info, pFLAG);
1497c478bd9Sstevel@tonic-gate break;
1507c478bd9Sstevel@tonic-gate case 'x':
1517c478bd9Sstevel@tonic-gate optcnt++;
152*56b75c05SAndy Fiddaman SET_OPT(cmd_info, xFLAG);
1537c478bd9Sstevel@tonic-gate break;
1547c478bd9Sstevel@tonic-gate case 'V':
155*56b75c05SAndy Fiddaman SET_OPT(cmd_info, VFLAG);
1567c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: %s %s\n", prog,
1577c478bd9Sstevel@tonic-gate (const char *)SGU_PKG, (const char *)SGU_REL);
1587c478bd9Sstevel@tonic-gate break;
1597c478bd9Sstevel@tonic-gate case '?':
1607c478bd9Sstevel@tonic-gate errflag++;
1617c478bd9Sstevel@tonic-gate break;
1627c478bd9Sstevel@tonic-gate default:
1637c478bd9Sstevel@tonic-gate break;
1647c478bd9Sstevel@tonic-gate }
1657c478bd9Sstevel@tonic-gate }
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate if (errflag) {
1687c478bd9Sstevel@tonic-gate usage(my_prog);
1697c478bd9Sstevel@tonic-gate exit(FAILURE);
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate /*
1737c478bd9Sstevel@tonic-gate * strip command may not take any options.
1747c478bd9Sstevel@tonic-gate */
1757c478bd9Sstevel@tonic-gate if (my_prog != STRIP) {
1767c478bd9Sstevel@tonic-gate if (argc == optind &&
1777c478bd9Sstevel@tonic-gate (CHK_OPT(cmd_info, MIGHT_CHG) || CHK_OPT(cmd_info, pFLAG) ||
1787c478bd9Sstevel@tonic-gate argc == 1))
1797c478bd9Sstevel@tonic-gate usage(my_prog);
1807c478bd9Sstevel@tonic-gate else if (!CHK_OPT(cmd_info, MIGHT_CHG) &&
1817c478bd9Sstevel@tonic-gate !CHK_OPT(cmd_info, pFLAG) && !CHK_OPT(cmd_info, VFLAG))
1827c478bd9Sstevel@tonic-gate usage(my_prog);
1837c478bd9Sstevel@tonic-gate }
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate /*
1867c478bd9Sstevel@tonic-gate * This version only allows multiple section names
1877c478bd9Sstevel@tonic-gate * only for -d option.
1887c478bd9Sstevel@tonic-gate */
1897c478bd9Sstevel@tonic-gate if ((num_sect >= 2) && (CHK_OPT(cmd_info, pFLAG) ||
1907c478bd9Sstevel@tonic-gate CHK_OPT(cmd_info, aFLAG) ||
1917c478bd9Sstevel@tonic-gate CHK_OPT(cmd_info, cFLAG))) {
1927c478bd9Sstevel@tonic-gate error_message(USAGE_ERROR, PLAIN_ERROR, (char *)0, prog);
193d1477c77SAli Bahrami exit(FAILURE);
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate /*
1977c478bd9Sstevel@tonic-gate * If no -n was specified,
1987c478bd9Sstevel@tonic-gate * set the default, ".comment".
1997c478bd9Sstevel@tonic-gate * This is for mcs only.
2007c478bd9Sstevel@tonic-gate */
2017c478bd9Sstevel@tonic-gate if (num_sect == 0 && my_prog == MCS) {
2027c478bd9Sstevel@tonic-gate (void) setup_sectname(".comment", MCS);
2037c478bd9Sstevel@tonic-gate }
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate /*
2067c478bd9Sstevel@tonic-gate * If I am strip command, then add needed
2077c478bd9Sstevel@tonic-gate * section names.
2087c478bd9Sstevel@tonic-gate */
2097c478bd9Sstevel@tonic-gate if (my_prog == STRIP) {
2107c478bd9Sstevel@tonic-gate (void) setup_sectname(".line", MCS);
2117c478bd9Sstevel@tonic-gate if (CHK_OPT(cmd_info, lFLAG) == 0) {
2127c478bd9Sstevel@tonic-gate (void) setup_sectname(".debug", STRIP);
2137c478bd9Sstevel@tonic-gate (void) setup_sectname(".stab", STRIP);
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate if (CHK_OPT(cmd_info, dFLAG) == 0) {
2167c478bd9Sstevel@tonic-gate queue(ACT_DELETE, NULL);
217*56b75c05SAndy Fiddaman SET_OPT(cmd_info, MIGHT_CHG | dFLAG);
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate (void) elf_version(EV_NONE);
2227c478bd9Sstevel@tonic-gate if (elf_version(EV_CURRENT) == EV_NONE) {
2237c478bd9Sstevel@tonic-gate error_message(ELFVER_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog);
2247c478bd9Sstevel@tonic-gate exit(FAILURE);
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate if (CHK_OPT(cmd_info, pFLAG) || CHK_OPT(cmd_info, MIGHT_CHG)) {
2287c478bd9Sstevel@tonic-gate for (; optind < argc; optind++) {
2297c478bd9Sstevel@tonic-gate error_count = error_count +
2307c478bd9Sstevel@tonic-gate (each_file(argv[optind], cmd_info));
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate mcs_exit(error_count);
2357c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2367c478bd9Sstevel@tonic-gate return (0);
2377c478bd9Sstevel@tonic-gate }
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate * Supplementary functions
2417c478bd9Sstevel@tonic-gate */
2427c478bd9Sstevel@tonic-gate static void
queue(int activity,char * string)2437c478bd9Sstevel@tonic-gate queue(int activity, char *string)
2447c478bd9Sstevel@tonic-gate {
2457c478bd9Sstevel@tonic-gate if (optcnt > optbufsz) {
2467c478bd9Sstevel@tonic-gate optbufsz = optbufsz * 2;
2477c478bd9Sstevel@tonic-gate if ((Action = realloc((struct action *)Action,
2487c478bd9Sstevel@tonic-gate optbufsz * sizeof (struct action))) == NULL) {
2497c478bd9Sstevel@tonic-gate error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog);
2507c478bd9Sstevel@tonic-gate mcs_exit(FAILURE);
2517c478bd9Sstevel@tonic-gate }
2527c478bd9Sstevel@tonic-gate }
2537c478bd9Sstevel@tonic-gate Action[actmax].a_action = activity;
2547c478bd9Sstevel@tonic-gate Action[actmax].a_cnt = 0;
2557c478bd9Sstevel@tonic-gate Action[actmax].a_string = string;
2567c478bd9Sstevel@tonic-gate actmax++;
2577c478bd9Sstevel@tonic-gate }
2587c478bd9Sstevel@tonic-gate
259d1477c77SAli Bahrami /*
260d1477c77SAli Bahrami * Reset a temporary file descriptor for reuse.
261d1477c77SAli Bahrami * If the file requires unlinking, that is done first.
262d1477c77SAli Bahrami */
263d1477c77SAli Bahrami void
free_tempfile(Tmp_File * temp_file)264d1477c77SAli Bahrami free_tempfile(Tmp_File *temp_file)
265d1477c77SAli Bahrami {
266d1477c77SAli Bahrami if ((temp_file->tmp_name != NULL) && (temp_file->tmp_unlink))
267d1477c77SAli Bahrami (void) unlink(temp_file->tmp_name);
268d1477c77SAli Bahrami (void) memset(temp_file, 0, sizeof (*temp_file));
269d1477c77SAli Bahrami }
270d1477c77SAli Bahrami
2717c478bd9Sstevel@tonic-gate /*ARGSUSED0*/
2727c478bd9Sstevel@tonic-gate static void
sigexit(int i)2737c478bd9Sstevel@tonic-gate sigexit(int i)
2747c478bd9Sstevel@tonic-gate {
275d1477c77SAli Bahrami free_tempfile(&artmpfile);
276d1477c77SAli Bahrami free_tempfile(&elftmpfile);
2777c478bd9Sstevel@tonic-gate exit(100);
2787c478bd9Sstevel@tonic-gate }
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate static void
usage(int me)2817c478bd9Sstevel@tonic-gate usage(int me)
2827c478bd9Sstevel@tonic-gate {
2837c478bd9Sstevel@tonic-gate if (me == MCS)
2847c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
2857c478bd9Sstevel@tonic-gate "usage: %s [-cdpVz] [-a string] [-n name] file ...\n"), prog);
2867c478bd9Sstevel@tonic-gate else
2877c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
2887c478bd9Sstevel@tonic-gate "usage: %s [-lVx] file ...\n"), prog);
2897c478bd9Sstevel@tonic-gate mcs_exit(FAILURE);
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate void
mcs_exit(int val)2937c478bd9Sstevel@tonic-gate mcs_exit(int val)
2947c478bd9Sstevel@tonic-gate {
295d1477c77SAli Bahrami free_tempfile(&artmpfile);
296d1477c77SAli Bahrami free_tempfile(&elftmpfile);
2977c478bd9Sstevel@tonic-gate exit(val);
2987c478bd9Sstevel@tonic-gate }
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate /*
3017c478bd9Sstevel@tonic-gate * Insert the section name 'name' into the
3027c478bd9Sstevel@tonic-gate * section list.
3037c478bd9Sstevel@tonic-gate */
3047c478bd9Sstevel@tonic-gate static int
setup_sectname(char * name,int whoami)3057c478bd9Sstevel@tonic-gate setup_sectname(char *name, int whoami)
3067c478bd9Sstevel@tonic-gate {
3077c478bd9Sstevel@tonic-gate S_Name *new;
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate /*
3107c478bd9Sstevel@tonic-gate * Check if the name is already specified or not.
3117c478bd9Sstevel@tonic-gate */
3127c478bd9Sstevel@tonic-gate if ((whoami == MCS) && (sectcmp(name) == 0))
3137c478bd9Sstevel@tonic-gate return (0);
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate /*
3167c478bd9Sstevel@tonic-gate * Allocate one
3177c478bd9Sstevel@tonic-gate */
3187c478bd9Sstevel@tonic-gate if ((new = malloc(sizeof (S_Name))) == NULL) {
3197c478bd9Sstevel@tonic-gate error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog);
3207c478bd9Sstevel@tonic-gate exit(FAILURE);
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate new->name = strdup(name);
3237c478bd9Sstevel@tonic-gate if (new->name == NULL) {
3247c478bd9Sstevel@tonic-gate error_message(USAGE_ERROR, PLAIN_ERROR, (char *)0, prog);
3257c478bd9Sstevel@tonic-gate exit(FAILURE);
3267c478bd9Sstevel@tonic-gate }
3277c478bd9Sstevel@tonic-gate if (whoami == STRIP)
3287c478bd9Sstevel@tonic-gate new->flags = SNAME_FLG_STRNCMP;
3297c478bd9Sstevel@tonic-gate new->next = NULL;
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate /*
3327c478bd9Sstevel@tonic-gate * Put this one in the list
3337c478bd9Sstevel@tonic-gate */
3347c478bd9Sstevel@tonic-gate new->next = sect_head;
3357c478bd9Sstevel@tonic-gate sect_head = new;
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate return (0);
3387c478bd9Sstevel@tonic-gate }
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate /*
3417c478bd9Sstevel@tonic-gate * Check if the 'name' exists in the section list.
3427c478bd9Sstevel@tonic-gate *
3437c478bd9Sstevel@tonic-gate * If found
3447c478bd9Sstevel@tonic-gate * return 0;
3457c478bd9Sstevel@tonic-gate * else
3467c478bd9Sstevel@tonic-gate * return 1
3477c478bd9Sstevel@tonic-gate */
3487c478bd9Sstevel@tonic-gate int
sectcmp(char * name)3497c478bd9Sstevel@tonic-gate sectcmp(char *name)
3507c478bd9Sstevel@tonic-gate {
3517c478bd9Sstevel@tonic-gate /*
3527c478bd9Sstevel@tonic-gate * Check if the name is already specified or not.
3537c478bd9Sstevel@tonic-gate */
3547c478bd9Sstevel@tonic-gate if (sect_head != NULL) {
3557c478bd9Sstevel@tonic-gate S_Name *p1 = sect_head;
3567c478bd9Sstevel@tonic-gate while (p1 != NULL) {
3577c478bd9Sstevel@tonic-gate if (p1->flags & SNAME_FLG_STRNCMP) {
3587c478bd9Sstevel@tonic-gate if (strncmp(p1->name,
3597c478bd9Sstevel@tonic-gate name, strlen(p1->name)) == 0)
3607c478bd9Sstevel@tonic-gate return (0);
3617c478bd9Sstevel@tonic-gate } else if (strcmp(p1->name, name) == 0) {
3627c478bd9Sstevel@tonic-gate return (0); /* silently ignore */
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate p1 = p1->next;
3657c478bd9Sstevel@tonic-gate }
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate return (1);
3687c478bd9Sstevel@tonic-gate }
369