char* getcwd(char* buf, size_t size) { // You can't specify size 0 unless you're asking us to allocate for you. if (buf != nullptr && size == 0) {
errno = EINVAL; return nullptr;
}
// Allocate a buffer if necessary. char* allocated_buf = nullptr;
size_t allocated_size = size; if (buf == nullptr) { if (size == 0) { // The Linux kernel won't return more than a page, so translate size 0 to 4KiB. // TODO: if we need to support paths longer than that, we'll have to walk the tree ourselves.
allocated_size = getpagesize();
}
buf = allocated_buf = static_cast<char*>(malloc(allocated_size)); if (buf == nullptr) { return nullptr;
}
}
// Ask the kernel to fill our buffer. int rc = __getcwd(buf, allocated_size); if (rc == -1) {
free(allocated_buf); // __getcwd set errno. return nullptr;
}
// If we allocated a whole page, only return as large an allocation as necessary. if (allocated_buf != nullptr) { if (size == 0) {
buf = strdup(allocated_buf);
free(allocated_buf);
} else {
buf = allocated_buf;
}
}
return buf;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.