1*9781SMoriah.Waterland@Sun.COM /* 2*9781SMoriah.Waterland@Sun.COM * CDDL HEADER START 3*9781SMoriah.Waterland@Sun.COM * 4*9781SMoriah.Waterland@Sun.COM * The contents of this file are subject to the terms of the 5*9781SMoriah.Waterland@Sun.COM * Common Development and Distribution License (the "License"). 6*9781SMoriah.Waterland@Sun.COM * You may not use this file except in compliance with the License. 7*9781SMoriah.Waterland@Sun.COM * 8*9781SMoriah.Waterland@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*9781SMoriah.Waterland@Sun.COM * or http://www.opensolaris.org/os/licensing. 10*9781SMoriah.Waterland@Sun.COM * See the License for the specific language governing permissions 11*9781SMoriah.Waterland@Sun.COM * and limitations under the License. 12*9781SMoriah.Waterland@Sun.COM * 13*9781SMoriah.Waterland@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 14*9781SMoriah.Waterland@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*9781SMoriah.Waterland@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 16*9781SMoriah.Waterland@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 17*9781SMoriah.Waterland@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 18*9781SMoriah.Waterland@Sun.COM * 19*9781SMoriah.Waterland@Sun.COM * CDDL HEADER END 20*9781SMoriah.Waterland@Sun.COM */ 21*9781SMoriah.Waterland@Sun.COM 22*9781SMoriah.Waterland@Sun.COM /* 23*9781SMoriah.Waterland@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24*9781SMoriah.Waterland@Sun.COM * Use is subject to license terms. 25*9781SMoriah.Waterland@Sun.COM */ 26*9781SMoriah.Waterland@Sun.COM 27*9781SMoriah.Waterland@Sun.COM 28*9781SMoriah.Waterland@Sun.COM 29*9781SMoriah.Waterland@Sun.COM #include <stdio.h> 30*9781SMoriah.Waterland@Sun.COM #include <sys/types.h> 31*9781SMoriah.Waterland@Sun.COM #include <sys/stat.h> 32*9781SMoriah.Waterland@Sun.COM #include <errno.h> 33*9781SMoriah.Waterland@Sun.COM #include <fcntl.h> 34*9781SMoriah.Waterland@Sun.COM #include <limits.h> 35*9781SMoriah.Waterland@Sun.COM #include <stdlib.h> 36*9781SMoriah.Waterland@Sun.COM #include <unistd.h> 37*9781SMoriah.Waterland@Sun.COM #include <string.h> 38*9781SMoriah.Waterland@Sun.COM #include "pkglib.h" 39*9781SMoriah.Waterland@Sun.COM 40*9781SMoriah.Waterland@Sun.COM /* 41*9781SMoriah.Waterland@Sun.COM * Name: fmkdir 42*9781SMoriah.Waterland@Sun.COM * Description: force the creation of a directory, even if the current 43*9781SMoriah.Waterland@Sun.COM * node exists and is not a directory 44*9781SMoriah.Waterland@Sun.COM * Arguments: a_path - pointer to string representing the path to the 45*9781SMoriah.Waterland@Sun.COM * directory to create 46*9781SMoriah.Waterland@Sun.COM * a_mode - mode(2) bits to set the path to if created 47*9781SMoriah.Waterland@Sun.COM * returns: 0 - directory created 48*9781SMoriah.Waterland@Sun.COM * 1 - could not remove existing non-directory node 49*9781SMoriah.Waterland@Sun.COM * 2 - could not create specified new directory 50*9781SMoriah.Waterland@Sun.COM */ 51*9781SMoriah.Waterland@Sun.COM int 52*9781SMoriah.Waterland@Sun.COM fmkdir(char *a_path, int a_mode) 53*9781SMoriah.Waterland@Sun.COM { 54*9781SMoriah.Waterland@Sun.COM if (access(a_path, F_OK) == 0) { 55*9781SMoriah.Waterland@Sun.COM if (rrmdir(a_path) != 0) { 56*9781SMoriah.Waterland@Sun.COM return (1); 57*9781SMoriah.Waterland@Sun.COM } 58*9781SMoriah.Waterland@Sun.COM } 59*9781SMoriah.Waterland@Sun.COM 60*9781SMoriah.Waterland@Sun.COM if (mkdir(a_path, a_mode) != 0) { 61*9781SMoriah.Waterland@Sun.COM return (2); 62*9781SMoriah.Waterland@Sun.COM } 63*9781SMoriah.Waterland@Sun.COM 64*9781SMoriah.Waterland@Sun.COM return (0); 65*9781SMoriah.Waterland@Sun.COM } 66