char cwd[256];
if (getcwd(cwd, sizeof(cwd)) == NULL) {
return -1;
}
처음에는 getcwd()
이 cwd가 충분히 크지 않을 때 NULL
을 반환 할 수 있다는 사실을 염두에 둡니다. 다른 경우가 있습니까?getcwd()는 어떤 상황에서 NULL을 반환합니까?
char cwd[256];
if (getcwd(cwd, sizeof(cwd)) == NULL) {
return -1;
}
처음에는 getcwd()
이 cwd가 충분히 크지 않을 때 NULL
을 반환 할 수 있다는 사실을 염두에 둡니다. 다른 경우가 있습니까?getcwd()는 어떤 상황에서 NULL을 반환합니까?
Its documentation 상태 :
ERRORS The getcwd() function shall fail if: [EINVAL] The size argument is 0. [ERANGE] The size argument is greater than 0, but is smaller than the length of the pathname +1. The getcwd() function may fail if: [EACCES] Read or search permission was denied for a component of the pathname. [ENOMEM] Insufficient storage space is available.
If the length of the absolute pathname of the current working direc‐
tory, including the terminating null byte, exceeds size bytes, NULL is
returned, and errno is set to ERANGE; an application should check for
this error, and allocate a larger buffer if necessary.
소스 : 당신이 그것을 맞춤법 관련 문서를 보면, 함수의 정확한 의미에 대한 질문이있는 경우
을에 getcwd 사람 : 언어 표준, POSIX 표준, 맨 페이지, MSDN, ... 누군가에게 당신을 위해 페이지를 인용하도록 요청하는 것은 게으르며별로 유용하지 않습니다. 게다가 오래 걸립니다. – Deduplicator