xref: /titanic_51/usr/src/cmd/sgs/mcs/common/main.c (revision 9dc42874cbf5b71e55522fc6ab014d911f8d174a)
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 /*
23*9dc42874SAlek Pinchuk  * Copyright 2012 Nexenta Systems, Inc.  All rights reserved.
24*9dc42874SAlek 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.
307c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include "stdlib.h"
347c478bd9Sstevel@tonic-gate #include "conv.h"
357c478bd9Sstevel@tonic-gate #include "mcs.h"
367c478bd9Sstevel@tonic-gate #include "extern.h"
377c478bd9Sstevel@tonic-gate #define	OPTUNIT	100
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate static size_t optcnt = 0;
407c478bd9Sstevel@tonic-gate static size_t optbufsz = OPTUNIT;
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * Function prototypes.
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate static void usage(int);
467c478bd9Sstevel@tonic-gate static void sigexit(int);
477c478bd9Sstevel@tonic-gate static int setup_sectname(char *, int);
487c478bd9Sstevel@tonic-gate static void queue(int, char *);
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate int
517c478bd9Sstevel@tonic-gate main(int argc, char ** argv, char ** envp)
527c478bd9Sstevel@tonic-gate {
537c478bd9Sstevel@tonic-gate 	const char	*opt;
547c478bd9Sstevel@tonic-gate 	char		*str;
55*9dc42874SAlek Pinchuk 	int		error_count = 0, num_sect = 0, errflag = 0;
567c478bd9Sstevel@tonic-gate 	int		c, i, my_prog;
577c478bd9Sstevel@tonic-gate 	Cmd_Info	*cmd_info;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 	/*
607c478bd9Sstevel@tonic-gate 	 * Check for a binary that better fits this architecture.
617c478bd9Sstevel@tonic-gate 	 */
627010c12aSrie 	(void) conv_check_native(argv, envp);
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	/*
657c478bd9Sstevel@tonic-gate 	 * mcs(1) and strip() are hard linked together, determine which command
667c478bd9Sstevel@tonic-gate 	 * was invoked.
677c478bd9Sstevel@tonic-gate 	 */
687c478bd9Sstevel@tonic-gate 	prog = argv[0];
697c478bd9Sstevel@tonic-gate 	if ((str = strrchr(prog, '/')) != NULL)
707c478bd9Sstevel@tonic-gate 		str++;
717c478bd9Sstevel@tonic-gate 	else
727c478bd9Sstevel@tonic-gate 		str = prog;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	if (strcmp(str, "mcs") == 0) {
757c478bd9Sstevel@tonic-gate 		my_prog = MCS;
76*9dc42874SAlek Pinchuk 		opt = "a:cdn:pVz?";
777c478bd9Sstevel@tonic-gate 	} else if (strcmp(str, "strip") == 0) {
787c478bd9Sstevel@tonic-gate 		my_prog = STRIP;
79*9dc42874SAlek Pinchuk 		opt = "lxV?";
807c478bd9Sstevel@tonic-gate 	} else
81d1477c77SAli Bahrami 		exit(FAILURE);
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
847c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
857c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"
867c478bd9Sstevel@tonic-gate #endif
877c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	for (i = 0; signum[i]; i++)
907c478bd9Sstevel@tonic-gate 		if (signal(signum[i], SIG_IGN) != SIG_IGN)
917c478bd9Sstevel@tonic-gate 			(void) signal(signum[i], sigexit);
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	if ((Action =
947c478bd9Sstevel@tonic-gate 	    malloc(optbufsz * sizeof (struct action))) == NULL) {
957c478bd9Sstevel@tonic-gate 		error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog);
967c478bd9Sstevel@tonic-gate 		exit(FAILURE);
977c478bd9Sstevel@tonic-gate 	}
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	/*
1007c478bd9Sstevel@tonic-gate 	 * Allocate command info structure
1017c478bd9Sstevel@tonic-gate 	 */
1027c478bd9Sstevel@tonic-gate 	cmd_info = (Cmd_Info *) calloc(1, sizeof (Cmd_Info));
1037c478bd9Sstevel@tonic-gate 	if (cmd_info == NULL) {
1047c478bd9Sstevel@tonic-gate 		error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog);
1057c478bd9Sstevel@tonic-gate 		exit(FAILURE);
1067c478bd9Sstevel@tonic-gate 	}
1077c478bd9Sstevel@tonic-gate 	if (my_prog == STRIP)
1087c478bd9Sstevel@tonic-gate 		cmd_info->flags |= I_AM_STRIP;
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, (char *)opt)) != EOF) {
1117c478bd9Sstevel@tonic-gate 		switch (c) {
1127c478bd9Sstevel@tonic-gate 		case 'a':
1137c478bd9Sstevel@tonic-gate 			optcnt++;
1147c478bd9Sstevel@tonic-gate 			queue(ACT_APPEND, optarg);
1157c478bd9Sstevel@tonic-gate 			cmd_info->flags |= (MIGHT_CHG | aFLAG);
1167c478bd9Sstevel@tonic-gate 			cmd_info->str_size += strlen(optarg) + 1;
1177c478bd9Sstevel@tonic-gate 			break;
1187c478bd9Sstevel@tonic-gate 		case 'c':
1197c478bd9Sstevel@tonic-gate 			optcnt++;
1207c478bd9Sstevel@tonic-gate 			queue(ACT_COMPRESS, NULL);
1217c478bd9Sstevel@tonic-gate 			cmd_info->flags |= (MIGHT_CHG | cFLAG);
1227c478bd9Sstevel@tonic-gate 			break;
1237c478bd9Sstevel@tonic-gate 		case 'd':
1247c478bd9Sstevel@tonic-gate 			optcnt++;
1257c478bd9Sstevel@tonic-gate 			if (CHK_OPT(cmd_info, dFLAG) == 0)
1267c478bd9Sstevel@tonic-gate 				queue(ACT_DELETE, NULL);
1277c478bd9Sstevel@tonic-gate 			cmd_info->flags |= (MIGHT_CHG | dFLAG);
1287c478bd9Sstevel@tonic-gate 			break;
1297c478bd9Sstevel@tonic-gate 		case 'z':
1307c478bd9Sstevel@tonic-gate 			optcnt++;
1317c478bd9Sstevel@tonic-gate 			queue(ACT_ZAP, NULL);
1327c478bd9Sstevel@tonic-gate 			cmd_info->flags |= (MIGHT_CHG | zFLAG);
1337c478bd9Sstevel@tonic-gate 			break;
1347c478bd9Sstevel@tonic-gate 		case 'n':
1357c478bd9Sstevel@tonic-gate 			(void) setup_sectname(optarg, my_prog);
1367c478bd9Sstevel@tonic-gate 			num_sect++;
1377c478bd9Sstevel@tonic-gate 			break;
1387c478bd9Sstevel@tonic-gate 		case 'l':
1397c478bd9Sstevel@tonic-gate 			optcnt++;
1407c478bd9Sstevel@tonic-gate 			cmd_info->flags |= lFLAG;
1417c478bd9Sstevel@tonic-gate 			break;
1427c478bd9Sstevel@tonic-gate 		case 'p':
1437c478bd9Sstevel@tonic-gate 			optcnt++;
1447c478bd9Sstevel@tonic-gate 			queue(ACT_PRINT, NULL);
1457c478bd9Sstevel@tonic-gate 			cmd_info->flags |= pFLAG;
1467c478bd9Sstevel@tonic-gate 			break;
1477c478bd9Sstevel@tonic-gate 		case 'x':
1487c478bd9Sstevel@tonic-gate 			optcnt++;
1497c478bd9Sstevel@tonic-gate 			cmd_info->flags |= xFLAG;
1507c478bd9Sstevel@tonic-gate 			break;
1517c478bd9Sstevel@tonic-gate 		case 'V':
1527c478bd9Sstevel@tonic-gate 			cmd_info->flags |= VFLAG;
1537c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: %s %s\n", prog,
1547c478bd9Sstevel@tonic-gate 			    (const char *)SGU_PKG, (const char *)SGU_REL);
1557c478bd9Sstevel@tonic-gate 			break;
1567c478bd9Sstevel@tonic-gate 		case '?':
1577c478bd9Sstevel@tonic-gate 			errflag++;
1587c478bd9Sstevel@tonic-gate 			break;
1597c478bd9Sstevel@tonic-gate 		default:
1607c478bd9Sstevel@tonic-gate 			break;
1617c478bd9Sstevel@tonic-gate 		}
1627c478bd9Sstevel@tonic-gate 	}
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	if (errflag) {
1657c478bd9Sstevel@tonic-gate 		usage(my_prog);
1667c478bd9Sstevel@tonic-gate 		exit(FAILURE);
1677c478bd9Sstevel@tonic-gate 	}
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 	/*
1707c478bd9Sstevel@tonic-gate 	 * strip command may not take any options.
1717c478bd9Sstevel@tonic-gate 	 */
1727c478bd9Sstevel@tonic-gate 	if (my_prog != STRIP) {
1737c478bd9Sstevel@tonic-gate 		if (argc == optind &&
1747c478bd9Sstevel@tonic-gate 		    (CHK_OPT(cmd_info, MIGHT_CHG) || CHK_OPT(cmd_info, pFLAG) ||
1757c478bd9Sstevel@tonic-gate 		    argc == 1))
1767c478bd9Sstevel@tonic-gate 			usage(my_prog);
1777c478bd9Sstevel@tonic-gate 		else if (!CHK_OPT(cmd_info, MIGHT_CHG) &&
1787c478bd9Sstevel@tonic-gate 		    !CHK_OPT(cmd_info, pFLAG) && !CHK_OPT(cmd_info, VFLAG))
1797c478bd9Sstevel@tonic-gate 			usage(my_prog);
1807c478bd9Sstevel@tonic-gate 	}
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 	/*
1837c478bd9Sstevel@tonic-gate 	 * This version only allows multiple section names
1847c478bd9Sstevel@tonic-gate 	 * only for -d option.
1857c478bd9Sstevel@tonic-gate 	 */
1867c478bd9Sstevel@tonic-gate 	if ((num_sect >= 2) && (CHK_OPT(cmd_info, pFLAG) ||
1877c478bd9Sstevel@tonic-gate 	    CHK_OPT(cmd_info, aFLAG) ||
1887c478bd9Sstevel@tonic-gate 	    CHK_OPT(cmd_info, cFLAG))) {
1897c478bd9Sstevel@tonic-gate 		error_message(USAGE_ERROR, PLAIN_ERROR, (char *)0,  prog);
190d1477c77SAli Bahrami 		exit(FAILURE);
1917c478bd9Sstevel@tonic-gate 	}
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	/*
1947c478bd9Sstevel@tonic-gate 	 * If no -n was specified,
1957c478bd9Sstevel@tonic-gate 	 * set the default, ".comment".
1967c478bd9Sstevel@tonic-gate 	 * This is for mcs only.
1977c478bd9Sstevel@tonic-gate 	 */
1987c478bd9Sstevel@tonic-gate 	if (num_sect == 0 && my_prog == MCS) {
1997c478bd9Sstevel@tonic-gate 		(void) setup_sectname(".comment", MCS);
2007c478bd9Sstevel@tonic-gate 	}
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	/*
2037c478bd9Sstevel@tonic-gate 	 * If I am strip command, then add needed
2047c478bd9Sstevel@tonic-gate 	 * section names.
2057c478bd9Sstevel@tonic-gate 	 */
2067c478bd9Sstevel@tonic-gate 	if (my_prog == STRIP) {
2077c478bd9Sstevel@tonic-gate 		(void) setup_sectname(".line", MCS);
2087c478bd9Sstevel@tonic-gate 		if (CHK_OPT(cmd_info, lFLAG) == 0) {
2097c478bd9Sstevel@tonic-gate 			(void) setup_sectname(".debug", STRIP);
2107c478bd9Sstevel@tonic-gate 			(void) setup_sectname(".stab", STRIP);
2117c478bd9Sstevel@tonic-gate 		}
2127c478bd9Sstevel@tonic-gate 		if (CHK_OPT(cmd_info, dFLAG) == 0) {
2137c478bd9Sstevel@tonic-gate 			queue(ACT_DELETE, NULL);
2147c478bd9Sstevel@tonic-gate 			cmd_info->flags |= MIGHT_CHG;
2157c478bd9Sstevel@tonic-gate 			cmd_info->flags |= dFLAG;
2167c478bd9Sstevel@tonic-gate 		}
2177c478bd9Sstevel@tonic-gate 	}
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	(void) elf_version(EV_NONE);
2207c478bd9Sstevel@tonic-gate 	if (elf_version(EV_CURRENT) == EV_NONE) {
2217c478bd9Sstevel@tonic-gate 		error_message(ELFVER_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog);
2227c478bd9Sstevel@tonic-gate 		exit(FAILURE);
2237c478bd9Sstevel@tonic-gate 	}
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	if (CHK_OPT(cmd_info, pFLAG) || CHK_OPT(cmd_info, MIGHT_CHG)) {
2267c478bd9Sstevel@tonic-gate 		for (; optind < argc; optind++) {
2277c478bd9Sstevel@tonic-gate 			error_count = error_count +
2287c478bd9Sstevel@tonic-gate 			    (each_file(argv[optind], cmd_info));
2297c478bd9Sstevel@tonic-gate 		}
2307c478bd9Sstevel@tonic-gate 	}
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	mcs_exit(error_count);
2337c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
2347c478bd9Sstevel@tonic-gate 	return (0);
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate /*
2387c478bd9Sstevel@tonic-gate  * Supplementary functions
2397c478bd9Sstevel@tonic-gate  */
2407c478bd9Sstevel@tonic-gate static void
2417c478bd9Sstevel@tonic-gate queue(int activity, char *string)
2427c478bd9Sstevel@tonic-gate {
2437c478bd9Sstevel@tonic-gate 	if (optcnt > optbufsz) {
2447c478bd9Sstevel@tonic-gate 		optbufsz = optbufsz * 2;
2457c478bd9Sstevel@tonic-gate 		if ((Action = realloc((struct action *)Action,
2467c478bd9Sstevel@tonic-gate 		    optbufsz * sizeof (struct action))) == NULL) {
2477c478bd9Sstevel@tonic-gate 		    error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog);
2487c478bd9Sstevel@tonic-gate 		    mcs_exit(FAILURE);
2497c478bd9Sstevel@tonic-gate 		}
2507c478bd9Sstevel@tonic-gate 	}
2517c478bd9Sstevel@tonic-gate 	Action[actmax].a_action = activity;
2527c478bd9Sstevel@tonic-gate 	Action[actmax].a_cnt = 0;
2537c478bd9Sstevel@tonic-gate 	Action[actmax].a_string = string;
2547c478bd9Sstevel@tonic-gate 	actmax++;
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate 
257d1477c77SAli Bahrami /*
258d1477c77SAli Bahrami  * Reset a temporary file descriptor for reuse.
259d1477c77SAli Bahrami  * If the file requires unlinking, that is done first.
260d1477c77SAli Bahrami  */
261d1477c77SAli Bahrami void
262d1477c77SAli Bahrami free_tempfile(Tmp_File *temp_file)
263d1477c77SAli Bahrami {
264d1477c77SAli Bahrami 	if ((temp_file->tmp_name != NULL) && (temp_file->tmp_unlink))
265d1477c77SAli Bahrami 		(void) unlink(temp_file->tmp_name);
266d1477c77SAli Bahrami 	(void) memset(temp_file, 0, sizeof (*temp_file));
267d1477c77SAli Bahrami }
268d1477c77SAli Bahrami 
2697c478bd9Sstevel@tonic-gate /*ARGSUSED0*/
2707c478bd9Sstevel@tonic-gate static void
2717c478bd9Sstevel@tonic-gate sigexit(int i)
2727c478bd9Sstevel@tonic-gate {
273d1477c77SAli Bahrami 	free_tempfile(&artmpfile);
274d1477c77SAli Bahrami 	free_tempfile(&elftmpfile);
2757c478bd9Sstevel@tonic-gate 	exit(100);
2767c478bd9Sstevel@tonic-gate }
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate static void
2797c478bd9Sstevel@tonic-gate usage(int me)
2807c478bd9Sstevel@tonic-gate {
2817c478bd9Sstevel@tonic-gate 	if (me == MCS)
2827c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
2837c478bd9Sstevel@tonic-gate 		"usage: %s [-cdpVz] [-a string] [-n name] file ...\n"), prog);
2847c478bd9Sstevel@tonic-gate 	else
2857c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
2867c478bd9Sstevel@tonic-gate 		"usage: %s [-lVx] file ...\n"), prog);
2877c478bd9Sstevel@tonic-gate 	mcs_exit(FAILURE);
2887c478bd9Sstevel@tonic-gate }
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate void
2917c478bd9Sstevel@tonic-gate mcs_exit(int val)
2927c478bd9Sstevel@tonic-gate {
293d1477c77SAli Bahrami 	free_tempfile(&artmpfile);
294d1477c77SAli Bahrami 	free_tempfile(&elftmpfile);
2957c478bd9Sstevel@tonic-gate 	exit(val);
2967c478bd9Sstevel@tonic-gate }
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate /*
2997c478bd9Sstevel@tonic-gate  * Insert the section name 'name' into the
3007c478bd9Sstevel@tonic-gate  * section list.
3017c478bd9Sstevel@tonic-gate  */
3027c478bd9Sstevel@tonic-gate static int
3037c478bd9Sstevel@tonic-gate setup_sectname(char *name, int whoami)
3047c478bd9Sstevel@tonic-gate {
3057c478bd9Sstevel@tonic-gate 	S_Name *new;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	/*
3087c478bd9Sstevel@tonic-gate 	 * Check if the name is already specified or not.
3097c478bd9Sstevel@tonic-gate 	 */
3107c478bd9Sstevel@tonic-gate 	if ((whoami == MCS) && (sectcmp(name) == 0))
3117c478bd9Sstevel@tonic-gate 		return (0);
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	/*
3147c478bd9Sstevel@tonic-gate 	 * Allocate one
3157c478bd9Sstevel@tonic-gate 	 */
3167c478bd9Sstevel@tonic-gate 	if ((new = malloc(sizeof (S_Name))) == NULL) {
3177c478bd9Sstevel@tonic-gate 		error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog);
3187c478bd9Sstevel@tonic-gate 		exit(FAILURE);
3197c478bd9Sstevel@tonic-gate 	}
3207c478bd9Sstevel@tonic-gate 	new->name = strdup(name);
3217c478bd9Sstevel@tonic-gate 	if (new->name == NULL) {
3227c478bd9Sstevel@tonic-gate 		error_message(USAGE_ERROR, PLAIN_ERROR, (char *)0, prog);
3237c478bd9Sstevel@tonic-gate 		exit(FAILURE);
3247c478bd9Sstevel@tonic-gate 	}
3257c478bd9Sstevel@tonic-gate 	if (whoami == STRIP)
3267c478bd9Sstevel@tonic-gate 		new->flags = SNAME_FLG_STRNCMP;
3277c478bd9Sstevel@tonic-gate 	new->next = NULL;
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 	/*
3307c478bd9Sstevel@tonic-gate 	 * Put this one in the list
3317c478bd9Sstevel@tonic-gate 	 */
3327c478bd9Sstevel@tonic-gate 	new->next = sect_head;
3337c478bd9Sstevel@tonic-gate 	sect_head = new;
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	return (0);
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate /*
3397c478bd9Sstevel@tonic-gate  * Check if the 'name' exists in the section list.
3407c478bd9Sstevel@tonic-gate  *
3417c478bd9Sstevel@tonic-gate  * If found
3427c478bd9Sstevel@tonic-gate  *	return 0;
3437c478bd9Sstevel@tonic-gate  * else
3447c478bd9Sstevel@tonic-gate  *	return 1
3457c478bd9Sstevel@tonic-gate  */
3467c478bd9Sstevel@tonic-gate int
3477c478bd9Sstevel@tonic-gate sectcmp(char *name)
3487c478bd9Sstevel@tonic-gate {
3497c478bd9Sstevel@tonic-gate 	/*
3507c478bd9Sstevel@tonic-gate 	 * Check if the name is already specified or not.
3517c478bd9Sstevel@tonic-gate 	 */
3527c478bd9Sstevel@tonic-gate 	if (sect_head != NULL) {
3537c478bd9Sstevel@tonic-gate 		S_Name *p1 = sect_head;
3547c478bd9Sstevel@tonic-gate 		while (p1 != NULL) {
3557c478bd9Sstevel@tonic-gate 			if (p1->flags & SNAME_FLG_STRNCMP) {
3567c478bd9Sstevel@tonic-gate 				if (strncmp(p1->name,
3577c478bd9Sstevel@tonic-gate 				    name, strlen(p1->name)) == 0)
3587c478bd9Sstevel@tonic-gate 					return (0);
3597c478bd9Sstevel@tonic-gate 			} else if (strcmp(p1->name, name) == 0) {
3607c478bd9Sstevel@tonic-gate 				return (0);	/* silently ignore */
3617c478bd9Sstevel@tonic-gate 			}
3627c478bd9Sstevel@tonic-gate 			p1 = p1->next;
3637c478bd9Sstevel@tonic-gate 		}
3647c478bd9Sstevel@tonic-gate 	}
3657c478bd9Sstevel@tonic-gate 	return (1);
3667c478bd9Sstevel@tonic-gate }
367