Skip to content

Commit

Permalink
tests: add win32 setenv implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
braydonk committed Nov 13, 2023
1 parent 72160e4 commit 92ee69f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/include/win32/setenv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Fluent Bit
* ==========
* Copyright (C) 2015-2023 The Fluent Bit Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* This file provides windows wrappers for libc's setenv and unsetenv by using
* the _putenv_s function, which behaves in a similar manner.
*
* setenv man page:
* https://man7.org/linux/man-pages/man3/setenv.3.html
* SetEnvironmentVariable docs:
* https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setenvironmentvariable
*
* - Braydon Kains, @braydonk
*/

#ifndef SET_ENV_H_
#define SET_ENV_H_

/**
* Just in case some silly goose includes it in a non-Windows build.
*/
#ifdef _WIN32

#include <stdlib.h>

int setenv(char *name, char *value, int overwrite)
{
return _putenv_s(name, value);
}

int unsetenv(char *name)
{
return _putenv_s(name, "");
}

#endif /* _WIN32 */

#endif /* SET_ENV_H_ */
4 changes: 4 additions & 0 deletions tests/internal/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <string.h>
#include "flb_tests_internal.h"

#ifdef _WIN32
#include "../include/win32/setenv.h"
#endif

/* Parsers configuration */
#define JSON_PARSERS FLB_TESTS_DATA_PATH "/data/parser/json.conf"
#define REGEX_PARSERS FLB_TESTS_DATA_PATH "/data/parser/regex.conf"
Expand Down
4 changes: 4 additions & 0 deletions tests/internal/parser_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <math.h>
#include "flb_tests_internal.h"

#ifdef _WIN32
#include "../include/win32/setenv.h"
#endif

static int msgpack_strncmp(char* str, size_t str_len, msgpack_object obj)
{
int ret = -1;
Expand Down
4 changes: 4 additions & 0 deletions tests/internal/parser_logfmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <math.h>
#include "flb_tests_internal.h"

#ifdef _WIN32
#include "../include/win32/setenv.h"
#endif

static int msgpack_strncmp(char* str, size_t str_len, msgpack_object obj)
{
int ret = -1;
Expand Down
4 changes: 4 additions & 0 deletions tests/internal/parser_ltsv.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <math.h>
#include "flb_tests_internal.h"

#ifdef _WIN32
#include "../include/win32/setenv.h"
#endif

static int msgpack_strncmp(char* str, size_t str_len, msgpack_object obj)
{
int ret = -1;
Expand Down
4 changes: 4 additions & 0 deletions tests/internal/parser_regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <math.h>
#include "flb_tests_internal.h"

#ifdef _WIN32
#include "../include/win32/setenv.h"
#endif

static int msgpack_strncmp(char* str, size_t str_len, msgpack_object obj)
{
int ret = -1;
Expand Down
4 changes: 4 additions & 0 deletions tests/runtime/filter_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <fluent-bit/flb_parser.h>
#include "flb_tests_runtime.h"

#ifdef _WIN32
#include "../include/win32/setenv.h"
#endif

#define FLUSH_INTERVAL "1.0"

pthread_mutex_t result_mutex = PTHREAD_MUTEX_INITIALIZER;
Expand Down

0 comments on commit 92ee69f

Please sign in to comment.