⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getcwd.3

📁 unix/linux 编程实践 一书的所有源代码
💻 3
字号:
.\" Copyright (c) 1991 The Regents of the University of California..\" All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\"    notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\"    notice, this list of conditions and the following disclaimer in the.\"    documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\"    must display the following acknowledgement:.\"	This product includes software developed by the University of.\"	California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\"    may be used to endorse or promote products derived from this software.\"    without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\"     @(#)getcwd.3	6.4 (Berkeley) 4/19/91.\".Dd April 19, 1991.Dt GETWD 3.Os BSD 4.2.Sh NAME.Nm getwd.Nd get working directory pathname.Sh SYNOPSIS.Fd #include <stdio.h>.Ft char *.Fn getcwd "char *buf" "size_t size".Ft char *.Fn getwd "char *buf".Sh DESCRIPTIONThe.Fn getcwdfunction copies the absolute pathname of the current working directoryinto the memory referenced by.Fa bufand returns a pointer to.Fa buf .The.Fa sizeargument is the size, in bytes, of the array referenced by.Fa buf ..PpIf.Fa bufis.Dv NULL ,space is allocated as necessary to store the pathname.This space may later be.Xr free 3 Ns 'd..PpThe function.Fn getwdis a compatibility routine which calls.Fn getcwdwith its.Fa bufargument and a size of.Dv MAXPATHLEN(as defined in the includefile.Aq Pa sys/param.h ) .Obviously,.Fa bufshould be at least.Dv MAXPATHLENbytes in length..PpThese routines have traditionally been used by programs to save thename of a working directory for the purpose of returning to it.A much faster and less error-prone method of accomplishing this is toopen the current directory.Pq Ql \&.and use the.Xr fchdir 2function to return..Sh RETURN VALUESUpon successful completion, a pointer to the pathname is returned.Otherwise a.Dv NULLpointer is returned and the global variable.Va errnois set to indicate the error.In addition,.Fn getwdcopies the error message associated with.Va errnointo the memory referenced by.Fa buf ..Sh ERRORSThe.Fn getcwdfunctionwill fail if:.Bl -tag -width [EACCESS].It Bq Er EACCESSRead or search permission was denied for a component of the pathname..It Bq Er EINVALThe.Fa sizeargument is zero..It Bq Er ENOENTA component of the pathname no longer exists..It Bq Er ENOMEMInsufficient memory is available..It Bq Er ERANGEThe.Fa sizeargument is greater than zero but smaller than the length of the pathnameplus 1..El.Sh SEE ALSO.Xr chdir 2 ,.Xr fchdir 2 ,.Xr malloc 3 ,.Xr strerror 3.Sh STANDARDSThe.Fn getcwdfunctionconforms to.St -ansiC .The ability to specify a.Dv NULLpointer and have.Fn getcwdallocate memory as necessary is an extension..Sh HISTORYThe.Fn getwdfunction appeared in .Bx 4.0 ..Sh BUGSThe.Fn getwdfunctiondoes not do sufficient error checking and is not able to return verylong, but valid, paths.It is provided for compatibility.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -