Except the system call version doesn't need you to include any header files!
Which is NOT clear from the man page!

> On 13 Feb 2020, at 13:53, George N. White III <gnw...@gmail.com> wrote:
> 
> 
>> On Thu, 13 Feb 2020 at 06:40, Andy Paterson via users 
>> <users@lists.fedoraproject.org> wrote:
> 
>> [...] 
>> I am a little confused by getcwd(), on linux it is supposed to be a system 
>> call .. I expect to find a manual page for it in section 2 (man 2 getcwd)
>> instead it gives me the library function manual page from section 3 (man 3 
>> getcwd)
> 
> $ man -k getcwd
> getcwd (2)           - get current working directory
> getcwd (3)           - get current working directory
> getcwd (3p)          - get the pathname of the current working directory
> $ gzip -dc /usr/share/man/man2/getcwd.2.gz
> .so man3/getcwd.3
>  
>> I would fully expect a libc version of getcwd to make many system calls to 
>> traverse the current path but here getcwd() is a system call with all work 
>> done internally in the kernel, so I wouldnt expect anything to probe the 
>> path elements.
>> When I knock up a simple program to do a getcwd() and strace it I find that 
>> getcwd (on FC31 anyway) IS a system call.
>> Why does "man getcwd" give me a page from section 3?
> 
> The man page explains the differences, so it makes sense that "man 2" and 
> "man 3" give the same text:
> 
>  C library/kernel differences
>        On Linux, the kernel provides a getcwd() system call, which  the  func‐
>        tions  described  in  this  page will use if possible.  The system call
>        takes the same arguments as the library function of the same name,  but
>        is  limited  to  returning at most PATH_MAX bytes. 
> 
> The getcwd() system call saves overhead but should make the same storage 
> accesses as the
> library version.
> 
> -- 
> George N. White III
> 
> _______________________________________________
> users mailing list -- users@lists.fedoraproject.org
> To unsubscribe send an email to users-le...@lists.fedoraproject.org
> Fedora Code of Conduct: 
> https://docs.fedoraproject.org/en-US/project/code-of-conduct/
> List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
> List Archives: 
> https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org
_______________________________________________
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org

Reply via email to