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/*
2N/A * Copyright (c) 1996, by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * m_pathmax: mks specific library routine.
2N/A *
2N/A * Copyright 1992 by Mortice Kern Systems Inc. All rights reserved.
2N/A *
2N/A */
2N/A#ifdef M_RCSID
2N/A#ifndef lint
2N/Astatic char rcsID[] = "$Header: /rd/src/libc/mks/rcs/m_pathma.c 1.4 1992/06/19 17:28:24 gord Exp $";
2N/A#endif
2N/A#endif /* M_RCSID */
2N/A
2N/A#include <mks.h>
2N/A#include <unistd.h>
2N/A#include <stdlib.h>
2N/A#include <limits.h>
2N/A#include <stdio.h>
2N/A#include <errno.h>
2N/A#include <assert.h>
2N/A
2N/A#ifdef m_pathmax
2N/A#undef m_pathmax /* in case its #define'd in mks.h */
2N/A#endif
2N/A
2N/A/*f
2N/A * m_pathmax()
2N/A * - Determine current configuration value for PC_PATH_MAX
2N/A * relative to 'path'.
2N/A * - If 'path' is NULL, then relative to "/"
2N/A * - Return:
2N/A * configuration value
2N/A * or M_PATH_MAX if configuration value is indeterminate
2N/A * or -1 and errno is set if there's a problem with 'path'
2N/A */
2N/Aint
2N/Am_pathmax(path)
2N/Achar* path;
2N/A{
2N/A int x;
2N/A
2N/A if (path == NULL)
2N/A path = "/";
2N/A
2N/A errno = 0;
2N/A x = pathconf(path, _PC_PATH_MAX);
2N/A if (x == -1) {
2N/A if (errno == 0) {
2N/A /*
2N/A * unlimited size - so we use M_PATH_MAX
2N/A *
2N/A * M_PATH_MAX defined in mkslocal.h
2N/A * - use a sufficiently LARGE number (e.g 1024 or 2048)
2N/A */
2N/A if (M_PATH_MAX < _POSIX_PATH_MAX) {
2N/A printf("m_pathmax(): Assert failure: ");
2N/A printf("M_PATH_MAX < _POSIX_PATH_MAX\n");
2N/A (void) exit(126);
2N/A }
2N/A return M_PATH_MAX;
2N/A } else {
2N/A /* ASSUME: cannot get errno = EINVAL because PC_PATH_MAX * must be supported, and must
2N/A * be associated with all *valid* 'path's
2N/A * (if 'path' is not valid, then we
2N/A * should get ENOENT or ENOTDIR,
2N/A * not EINVAL)
2N/A */
2N/A if (errno == EINVAL) {
2N/A printf("m_pathmax(): Assert failure: ");
2N/A printf("pathconf() = -1 and errno = EINVAL\n");
2N/A (void) exit(126);
2N/A }
2N/A return -1;
2N/A }
2N/A }
2N/A
2N/A return x;
2N/A}
2N/A
2N/A#ifdef TEST
2N/A/*
2N/A * compile with
2N/A * "make m_pathma COPTS=TEST" - using MKS make and MKS environment
2N/A * or
2N/A * "cc -o m_pathma -DTEST m_pathma.c" - to get sunos std libraries
2N/A *
2N/A */
2N/Amain(argc, argv)
2N/Aint argc;
2N/Achar ** argv;
2N/A{
2N/A if (argc > 1) {
2N/A int x;
2N/A x = m_pathmax(argv[1]);
2N/A printf("m_pathmax('%s') returns %d\n", argv[1], x );
2N/A if (x == -1)
2N/A#ifdef __STDC__
2N/A printf("errno = %d (%s)\n", errno, strerror(errno));
2N/A#else
2N/A printf("errno = %d \n", errno);
2N/A#endif
2N/A } else
2N/A printf("usage: %s filename\n", argv[0]);
2N/A
2N/A}
2N/A#endif /* TEST */