1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 1996, by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 /* 30 * m_pathmax: mks specific library routine. 31 * 32 * Copyright 1992 by Mortice Kern Systems Inc. All rights reserved. 33 * 34 */ 35 #ifdef M_RCSID 36 #ifndef lint 37 static char rcsID[] = "$Header: /rd/src/libc/mks/rcs/m_pathma.c 1.4 1992/06/19 17:28:24 gord Exp $"; 38 #endif 39 #endif /* M_RCSID */ 40 41 #include <mks.h> 42 #include <unistd.h> 43 #include <stdlib.h> 44 #include <limits.h> 45 #include <stdio.h> 46 #include <errno.h> 47 #include <assert.h> 48 49 #ifdef m_pathmax 50 #undef m_pathmax /* in case its #define'd in mks.h */ 51 #endif 52 53 /*f 54 * m_pathmax() 55 * - Determine current configuration value for PC_PATH_MAX 56 * relative to 'path'. 57 * - If 'path' is NULL, then relative to "/" 58 * - Return: 59 * configuration value 60 * or M_PATH_MAX if configuration value is indeterminate 61 * or -1 and errno is set if there's a problem with 'path' 62 */ 63 int 64 m_pathmax(path) 65 char* path; 66 { 67 int x; 68 69 if (path == NULL) 70 path = "/"; 71 72 errno = 0; 73 x = pathconf(path, _PC_PATH_MAX); 74 if (x == -1) { 75 if (errno == 0) { 76 /* 77 * unlimited size - so we use M_PATH_MAX 78 * 79 * M_PATH_MAX defined in mkslocal.h 80 * - use a sufficiently LARGE number (e.g 1024 or 2048) 81 */ 82 if (M_PATH_MAX < _POSIX_PATH_MAX) { 83 printf("m_pathmax(): Assert failure: "); 84 printf("M_PATH_MAX < _POSIX_PATH_MAX\n"); 85 (void) exit(126); 86 } 87 return M_PATH_MAX; 88 } else { 89 /* ASSUME: cannot get errno = EINVAL because PC_PATH_MAX * must be supported, and must 90 * be associated with all *valid* 'path's 91 * (if 'path' is not valid, then we 92 * should get ENOENT or ENOTDIR, 93 * not EINVAL) 94 */ 95 if (errno == EINVAL) { 96 printf("m_pathmax(): Assert failure: "); 97 printf("pathconf() = -1 and errno = EINVAL\n"); 98 (void) exit(126); 99 } 100 return -1; 101 } 102 } 103 104 return x; 105 } 106 107 #ifdef TEST 108 /* 109 * compile with 110 * "make m_pathma COPTS=TEST" - using MKS make and MKS environment 111 * or 112 * "cc -o m_pathma -DTEST m_pathma.c" - to get sunos std libraries 113 * 114 */ 115 main(argc, argv) 116 int argc; 117 char ** argv; 118 { 119 if (argc > 1) { 120 int x; 121 x = m_pathmax(argv[1]); 122 printf("m_pathmax('%s') returns %d\n", argv[1], x ); 123 if (x == -1) 124 #ifdef __STDC__ 125 printf("errno = %d (%s)\n", errno, strerror(errno)); 126 #else 127 printf("errno = %d \n", errno); 128 #endif 129 } else 130 printf("usage: %s filename\n", argv[0]); 131 132 } 133 #endif /* TEST */ 134