Files
async-http-client/Sources/CAsyncHTTPClient/CAsyncHTTPClient.c
Alastair HoughtonandGitHub 09b7eb751e Add support for Musl. (#726)
Motivation:

We would like to make this work for Musl so that we can build fully
statically linked binaries that use AsyncHTTPClient.

Modifications:

Define `_GNU_SOURCE` as a compiler argument; doing it in a source file
doesn't work properly with modular headers.

Add imports of `Musl` in appropriate places.

`Musl` doesn't have `strptime_l`, so avoid using that.

Result:

async-http-client will build for Musl.
2024-01-19 16:09:35 -08:00

44 lines
1.4 KiB
C

//===----------------------------------------------------------------------===//
//
// This source file is part of the AsyncHTTPClient open source project
//
// Copyright (c) 2018-2021 Apple Inc. and the AsyncHTTPClient project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
#if __APPLE__
#include <xlocale.h>
#elif __linux__
#include <locale.h>
#endif
#include <stdbool.h>
#include <time.h>
bool swiftahc_cshims_strptime(const char * string, const char * format, struct tm * result) {
const char * firstNonProcessed = strptime(string, format, result);
if (firstNonProcessed) {
return *firstNonProcessed == 0;
}
return false;
}
bool swiftahc_cshims_strptime_l(const char * string, const char * format, struct tm * result, void * locale) {
// The pointer cast is fine as long we make sure it really points to a locale_t.
#ifdef __musl__
const char * firstNonProcessed = strptime(string, format, result);
#else
const char * firstNonProcessed = strptime_l(string, format, result, (locale_t)locale);
#endif
if (firstNonProcessed) {
return *firstNonProcessed == 0;
}
return false;
}