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