xref: /onnv-gate/usr/src/lib/libc/port/gen/remove.c (revision 6812:febeba71273d)
15891Sraf /*
25891Sraf  * CDDL HEADER START
35891Sraf  *
45891Sraf  * The contents of this file are subject to the terms of the
55891Sraf  * Common Development and Distribution License (the "License").
65891Sraf  * You may not use this file except in compliance with the License.
75891Sraf  *
85891Sraf  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95891Sraf  * or http://www.opensolaris.org/os/licensing.
105891Sraf  * See the License for the specific language governing permissions
115891Sraf  * and limitations under the License.
125891Sraf  *
135891Sraf  * When distributing Covered Code, include this CDDL HEADER in each
145891Sraf  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155891Sraf  * If applicable, add the following below this CDDL HEADER, with the
165891Sraf  * fields enclosed by brackets "[]" replaced with your own identifying
175891Sraf  * information: Portions Copyright [yyyy] [name of copyright owner]
185891Sraf  *
195891Sraf  * CDDL HEADER END
205891Sraf  */
215891Sraf 
225891Sraf /*
235891Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
245891Sraf  * Use is subject to license terms.
255891Sraf  */
265891Sraf 
275891Sraf /*	Copyright (c) 1988 AT&T	*/
285891Sraf /*	  All Rights Reserved  	*/
295891Sraf 
30*6812Sraf #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*6812Sraf 
32*6812Sraf #include "lint.h"
335891Sraf #include <sys/types.h>
345891Sraf #include <sys/stat.h>
355891Sraf #include <unistd.h>
365891Sraf #include "libc.h"
375891Sraf 
385891Sraf int
remove(const char * filename)395891Sraf remove(const char *filename)
405891Sraf {
415891Sraf 	struct stat64	statb;
425891Sraf 
435891Sraf 	/*
445891Sraf 	 * If filename is not a directory, call unlink(filename)
455891Sraf 	 * Otherwise, call rmdir(filename)
465891Sraf 	 */
475891Sraf 
485891Sraf 	if (lstat64(filename, &statb) != 0)
495891Sraf 		return (-1);
505891Sraf 	if ((statb.st_mode & S_IFMT) != S_IFDIR)
515891Sraf 		return (unlink(filename));
525891Sraf 	return (rmdir(filename));
535891Sraf }
54