166492cf0SYuri Pankov.\" 266492cf0SYuri Pankov.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for 366492cf0SYuri Pankov.\" permission to reproduce portions of its copyrighted documentation. 466492cf0SYuri Pankov.\" Original documentation from The Open Group can be obtained online at 566492cf0SYuri Pankov.\" http://www.opengroup.org/bookstore/. 666492cf0SYuri Pankov.\" 766492cf0SYuri Pankov.\" The Institute of Electrical and Electronics Engineers and The Open 866492cf0SYuri Pankov.\" Group, have given us permission to reprint portions of their 966492cf0SYuri Pankov.\" documentation. 1066492cf0SYuri Pankov.\" 1166492cf0SYuri Pankov.\" In the following statement, the phrase ``this text'' refers to portions 1266492cf0SYuri Pankov.\" of the system documentation. 1366492cf0SYuri Pankov.\" 1466492cf0SYuri Pankov.\" Portions of this text are reprinted and reproduced in electronic form 1566492cf0SYuri Pankov.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, 1666492cf0SYuri Pankov.\" Standard for Information Technology -- Portable Operating System 1766492cf0SYuri Pankov.\" Interface (POSIX), The Open Group Base Specifications Issue 6, 1866492cf0SYuri Pankov.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics 1966492cf0SYuri Pankov.\" Engineers, Inc and The Open Group. In the event of any discrepancy 2066492cf0SYuri Pankov.\" between these versions and the original IEEE and The Open Group 2166492cf0SYuri Pankov.\" Standard, the original IEEE and The Open Group Standard is the referee 2266492cf0SYuri Pankov.\" document. The original Standard can be obtained online at 2366492cf0SYuri Pankov.\" http://www.opengroup.org/unix/online.html. 2466492cf0SYuri Pankov.\" 2566492cf0SYuri Pankov.\" This notice shall appear on any product containing this material. 2666492cf0SYuri Pankov.\" 2766492cf0SYuri Pankov.\" The contents of this file are subject to the terms of the 2866492cf0SYuri Pankov.\" Common Development and Distribution License (the "License"). 2966492cf0SYuri Pankov.\" You may not use this file except in compliance with the License. 3066492cf0SYuri Pankov.\" 3166492cf0SYuri Pankov.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 3266492cf0SYuri Pankov.\" or http://www.opensolaris.org/os/licensing. 3366492cf0SYuri Pankov.\" See the License for the specific language governing permissions 3466492cf0SYuri Pankov.\" and limitations under the License. 3566492cf0SYuri Pankov.\" 3666492cf0SYuri Pankov.\" When distributing Covered Code, include this CDDL HEADER in each 3766492cf0SYuri Pankov.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. 3866492cf0SYuri Pankov.\" If applicable, add the following below this CDDL HEADER, with the 3966492cf0SYuri Pankov.\" fields enclosed by brackets "[]" replaced with your own identifying 4066492cf0SYuri Pankov.\" information: Portions Copyright [yyyy] [name of copyright owner] 4166492cf0SYuri Pankov.\" 4266492cf0SYuri Pankov.\" 43c10c16deSRichard Lowe.\" Copyright 1989 AT&T 44c10c16deSRichard Lowe.\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved 4566492cf0SYuri Pankov.\" Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved 463aa10614SRobert Mustacchi.\" Copyright 2021 Oxide Computer Company 4766492cf0SYuri Pankov.\" 483aa10614SRobert Mustacchi.Dd February 25, 2021 493aa10614SRobert Mustacchi.Dt CLOSEDIR 3C 503aa10614SRobert Mustacchi.Os 513aa10614SRobert Mustacchi.Sh NAME 523aa10614SRobert Mustacchi.Nm closedir 533aa10614SRobert Mustacchi.Nd close a directory stream 543aa10614SRobert Mustacchi.Sh SYNOPSIS 553aa10614SRobert Mustacchi.In sys/types.h 563aa10614SRobert Mustacchi.In dirent.h 573aa10614SRobert Mustacchi.Ft int 583aa10614SRobert Mustacchi.Fo closedir 593aa10614SRobert Mustacchi.Fa "DIR *dirp" 603aa10614SRobert Mustacchi.Fc 613aa10614SRobert Mustacchi.Sh DESCRIPTION 623aa10614SRobert MustacchiThe 633aa10614SRobert Mustacchi.Fn closedir 643aa10614SRobert Mustacchifunction closes the directory stream referred to by the argument 653aa10614SRobert Mustacchi.Fa dirp , 663aa10614SRobert Mustacchiwhich generally came from calling 673aa10614SRobert Mustacchi.Xr opendir 3C 683aa10614SRobert Mustacchior 693aa10614SRobert Mustacchi.Xr fdopendir 3C . 703aa10614SRobert MustacchiUpon return, the value of 713aa10614SRobert Mustacchi.Fa dirp 723aa10614SRobert Mustacchiwill no longer point to an accessible object of the type 733aa10614SRobert Mustacchi.Ft DIR . 743aa10614SRobert MustacchiThe underlying file descriptor for the directory stream will be closed. 753aa10614SRobert MustacchiThis includes a 763aa10614SRobert Mustacchi.Ft DIR 773aa10614SRobert Mustacchicreated by passing a file descriptor to 783aa10614SRobert Mustacchi.Xr fdopendir 3C . 793aa10614SRobert Mustacchi.Pp 803aa10614SRobert MustacchiWhen the directory stream is closed, any memory that is associated with 813aa10614SRobert Mustacchithe stream will no longer be valid. 823aa10614SRobert MustacchiMost notably, the dirent structures returned from 833aa10614SRobert Mustacchi.Xr readdir 3C 843aa10614SRobert Mustacchiuse memory associated with the corresponding 853aa10614SRobert Mustacchi.Ft "DIR *" 863aa10614SRobert Mustacchiargument. 873aa10614SRobert MustacchiEach directory stream has its own independent memory. 883aa10614SRobert MustacchiClosing one stream does not impact the validity of other streams. 893aa10614SRobert Mustacchi.Sh RETURN VALUES 903aa10614SRobert MustacchiUpon successful completion, the 913aa10614SRobert Mustacchi.Fn closedir 923aa10614SRobert Mustacchifunction returns 933aa10614SRobert Mustacchi.Sy 0 . 943aa10614SRobert MustacchiOtherwise, 953aa10614SRobert Mustacchi.Sy -1 963aa10614SRobert Mustacchiis returned and 973aa10614SRobert Mustacchi.Va errno 983aa10614SRobert Mustacchiis set to indicate the error. 993aa10614SRobert Mustacchi.Sh ERRORS 1003aa10614SRobert MustacchiThe 1013aa10614SRobert Mustacchi.Fn closedir 1023aa10614SRobert Mustacchifunction may fail if: 1033aa10614SRobert Mustacchi.Bl -tag -width Er 1043aa10614SRobert Mustacchi.It Er EBADF 1053aa10614SRobert MustacchiThe 1063aa10614SRobert Mustacchi.Fa dirp 1073aa10614SRobert Mustacchiargument does not refer to an open directory stream. 1083aa10614SRobert Mustacchi.It Er EINTR 1093aa10614SRobert MustacchiThe 1103aa10614SRobert Mustacchi.Fn closedir 1113aa10614SRobert Mustacchifunction was interrupted by a signal. 1123aa10614SRobert Mustacchi.El 1133aa10614SRobert Mustacchi.Sh INTERFACE STABILITY 1143aa10614SRobert Mustacchi.Sy Standard 1153aa10614SRobert Mustacchi.Sh MT-LEVEL 1163aa10614SRobert Mustacchi.Sy Safe 1173aa10614SRobert Mustacchi.Sh SEE ALSO 1183aa10614SRobert Mustacchi.Xr fdopendir 3C , 1193aa10614SRobert Mustacchi.Xr opendir 3C , 1203aa10614SRobert Mustacchi.Xr readdir 3C , 121*bbf21555SRichard Lowe.Xr attributes 7 122