Skip to content

Default buffer size of getcwd for linux #92672

Closed
@inteon

Description

@inteon

It seems like, by default, the initial buffer size for the return value of getcwd is set to 512 bytes:

let mut buf = Vec::with_capacity(512);

The default in glibc is defined as follows (https://code.woboq.org/userspace/glibc/sysdeps/unix/sysv/linux/getcwd.c.html#61):

MAX (PATH_MAX, __getpagesize ())

This might cause some unnecessary linux kernel context switches for longer paths (multiple buffer resizes).
Is there a reason for not using a larger buffer (eg. identical to the glibc implementation)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions