mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-01 13:49:05 +00:00
LibTimeZone: Replace PATH_MAX usage with heap allocation
This commit is contained in:
parent
ae10d085ba
commit
de6664c0cb
Notes:
sideshowbarker
2024-07-16 23:34:44 +09:00
Author: https://github.com/bugaevc
Commit: de6664c0cb
Pull-request: https://github.com/SerenityOS/serenity/pull/20958
Reviewed-by: https://github.com/ADKaster ✅
1 changed files with 5 additions and 3 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/DeprecatedString.h>
|
||||||
|
#include <AK/ScopeGuard.h>
|
||||||
#include <LibTimeZone/TimeZone.h>
|
#include <LibTimeZone/TimeZone.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -106,10 +107,11 @@ StringView current_time_zone()
|
||||||
return system_time_zone();
|
return system_time_zone();
|
||||||
#else
|
#else
|
||||||
static constexpr auto zoneinfo = "/zoneinfo/"sv;
|
static constexpr auto zoneinfo = "/zoneinfo/"sv;
|
||||||
char buffer[PATH_MAX];
|
char* real_path = realpath("/etc/localtime", nullptr);
|
||||||
|
ScopeGuard free_path = [real_path]() { free(real_path); };
|
||||||
|
|
||||||
if (realpath("/etc/localtime", buffer)) {
|
if (real_path) {
|
||||||
auto time_zone = StringView { buffer, strlen(buffer) };
|
auto time_zone = StringView { real_path, strlen(real_path) };
|
||||||
|
|
||||||
if (auto index = time_zone.find(zoneinfo); index.has_value())
|
if (auto index = time_zone.find(zoneinfo); index.has_value())
|
||||||
time_zone = time_zone.substring_view(*index + zoneinfo.length());
|
time_zone = time_zone.substring_view(*index + zoneinfo.length());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue