📄 getcwd.3
字号:
.\" SCCSID: @(#)getcwd.3 8.1 9/11/90.TH getcwd 3 .SH Namegetcwd \- get pathname of working directory.SH Syntax.nf.B char \(\fI**getcwd (buf, size\fP).B char \(\fI**buf\fP;.B int \fIsize\fP;.fi.SH Description.NXR "getcwd subroutine (standard C)".NXR "working directory" "getting pathname".NXA "directory" "working directory"The.PN getcwdsubroutine returns a pointer to the current directory pathname.The value of.I sizemust be at least two greater than the length of thepathname to be returned..PPIf.I bufis a NULL pointer,.PN getcwdwill obtain.I sizebytes of space using .PN malloc (3) .In this case, the pointer returned by.PN getcwdmay be used as the argument in a subsequent call to.I free..PPThe function is implemented by using .PN popen (3)to pipe the output of the .PN pwd (1)command into the specified string space..SH Examples.EXchar \(**cwd, \(**getcwd();\&.\&.\&.if ((cwd = getcwd((char \(**)NULL, 64)) == NULL) { perror("pwd"); exit(1);}printf("%s\en", cwd);.EE.SH Return ValuesReturns NULL with.I errnoset if.I sizeis not large enough, or if an error occursin a lower-level function..SH Diagnostics.TP 15[EINVAL]The size argument is zero or negative..TP[ERANGE]The size argument is greater than zero, but is smallerthan the length of the pathname+1;.TP[EACCES]Read or search permission is denied for a component of thepathname..TP[ENOMEM]Insufficient storage space is available..SH See Alsopwd(1), malloc(3), popen(3)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -