-
Notifications
You must be signed in to change notification settings - Fork 1.9k
glob: fix glob function and extract as win32 utility file #11165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
|
||
| /* Fluent Bit | ||
| * ========== | ||
| * Copyright (C) 2015-2024 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. | ||
| */ | ||
|
|
||
| #ifndef FLB_GLOB_WIN32_H | ||
| #define FLB_GLOB_WIN32_H | ||
|
|
||
| #include <fluent-bit/flb_info.h> | ||
| #include <sys/stat.h> | ||
| #include <limits.h> | ||
|
|
||
| #ifdef FLB_SYSTEM_WINDOWS | ||
|
|
||
| #include <cfl/cfl_list.h> | ||
|
|
||
| #define FLB_FILE_GLOB_ABORT_ON_ERROR (((uint64_t) 1) << 0) | ||
| #define FLB_FILE_GLOB_MARK_DIRECTORIES (((uint64_t) 1) << 1) | ||
| #define FLB_FILE_GLOB_DO_NOT_SORT (((uint64_t) 1) << 2) | ||
| #define FLB_FILE_GLOB_EXPAND_TILDE (((uint64_t) 1) << 3) | ||
|
|
||
| #define FLB_FILE_GLOB_ERROR_SUCCESS 0 | ||
| #define FLB_FILE_GLOB_ERROR_ABORTED 1 | ||
| #define FLB_FILE_GLOB_ERROR_NO_MEMORY 2 | ||
| #define FLB_FILE_GLOB_ERROR_NO_FILE 3 | ||
| #define FLB_FILE_GLOB_ERROR_NO_ACCESS 4 | ||
| #define FLB_FILE_GLOB_ERROR_NO_MATCHES 5 | ||
| #define FLB_FILE_GLOB_ERROR_NO_MORE_RESULTS 6 | ||
| #define FLB_FILE_GLOB_ERROR_OVERSIZED_PATH 7 | ||
| #define FLB_FILE_GLOB_ERROR_INVALID_ARGUMENT 8 | ||
|
|
||
| #ifndef GLOB_NOSPACE | ||
| #define GLOB_NOSPACE FLB_FILE_GLOB_ERROR_NO_MEMORY | ||
| #endif | ||
|
|
||
| #ifndef GLOB_ABORTED | ||
| #define GLOB_ABORTED FLB_FILE_GLOB_ERROR_ABORTED | ||
| #endif | ||
|
|
||
| #ifndef GLOB_NOMATCH | ||
| #define GLOB_NOMATCH FLB_FILE_GLOB_ERROR_NO_MATCHES | ||
| #endif | ||
|
|
||
| #ifndef GLOB_ERR | ||
| #define GLOB_ERR FLB_FILE_GLOB_ABORT_ON_ERROR | ||
| #endif | ||
|
|
||
| #define FLB_FILE_MAX_PATH_LENGTH PATH_MAX | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| struct flb_file_glob_inner_entry { | ||
| char *path; | ||
| struct cfl_list _head; | ||
| }; | ||
|
|
||
| struct flb_file_glob_inner_context { | ||
| struct flb_file_glob_inner_entry *current_entry; | ||
| struct cfl_list results; | ||
| size_t entries; | ||
| size_t index; | ||
| uint64_t flags; | ||
| }; | ||
|
|
||
| struct flb_file_glob_context { | ||
| struct flb_file_glob_inner_context *inner_context; | ||
| uint64_t flags; | ||
| char *path; | ||
| }; | ||
|
|
||
| typedef struct { | ||
| struct flb_file_glob_context inner_context; | ||
| char **gl_pathv; | ||
| size_t gl_pathc; | ||
| } glob_t; | ||
|
|
||
| int glob(const char *path, uint64_t flags, void *unused, glob_t *context); | ||
| void globfree(glob_t *context); | ||
| int is_directory(char *path, struct stat *fs_entry_metadata); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| #endif /* FLB_SYSTEM_WINDOWS */ | ||
| #endif /* FLB_GLOB_WIN32_H */ | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |||||||||||||||||||
| * limitations under the License. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #if defined(FLB_SYSTEM_WINDOWS) && !defined(FLB_FILE_GLOB_ERROR_SUCCESS) | ||||||||||||||||||||
| #if defined(FLB_SYSTEM_WINDOWS) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #include <fluent-bit/flb_info.h> | ||||||||||||||||||||
| #include <fluent-bit/flb_file.h> | ||||||||||||||||||||
|
|
@@ -28,73 +28,14 @@ | |||||||||||||||||||
| #include <fluent-bit/flb_str.h> | ||||||||||||||||||||
| #include <cfl/cfl.h> | ||||||||||||||||||||
| #include <cfl/cfl_list.h> | ||||||||||||||||||||
| #include <fluent-bit/flb_glob_win32.h> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #include <lmaccess.h> | ||||||||||||||||||||
| #include <sys/stat.h> | ||||||||||||||||||||
| #include <stdio.h> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #define FLB_FILE_GLOB_ABORT_ON_ERROR (((uint64_t) 1) << 0) | ||||||||||||||||||||
| #define FLB_FILE_GLOB_MARK_DIRECTORIES (((uint64_t) 1) << 1) | ||||||||||||||||||||
| #define FLB_FILE_GLOB_DO_NOT_SORT (((uint64_t) 1) << 2) | ||||||||||||||||||||
| #define FLB_FILE_GLOB_EXPAND_TILDE (((uint64_t) 1) << 3) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #define FLB_FILE_GLOB_ERROR_SUCCESS 0 | ||||||||||||||||||||
| #define FLB_FILE_GLOB_ERROR_ABORTED 1 | ||||||||||||||||||||
| #define FLB_FILE_GLOB_ERROR_NO_MEMORY 2 | ||||||||||||||||||||
| #define FLB_FILE_GLOB_ERROR_NO_FILE 3 | ||||||||||||||||||||
| #define FLB_FILE_GLOB_ERROR_NO_ACCESS 4 | ||||||||||||||||||||
| #define FLB_FILE_GLOB_ERROR_NO_MATCHES 5 | ||||||||||||||||||||
| #define FLB_FILE_GLOB_ERROR_NO_MORE_RESULTS 6 | ||||||||||||||||||||
| #define FLB_FILE_GLOB_ERROR_OVERSIZED_PATH 7 | ||||||||||||||||||||
| #define FLB_FILE_GLOB_ERROR_INVALID_ARGUMENT 8 | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #ifndef GLOB_NOSPACE | ||||||||||||||||||||
| #define GLOB_NOSPACE FLB_FILE_GLOB_ERROR_NO_MEMORY | ||||||||||||||||||||
| #endif | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #ifndef GLOB_ABORTED | ||||||||||||||||||||
| #define GLOB_ABORTED FLB_FILE_GLOB_ERROR_ABORTED | ||||||||||||||||||||
| #endif | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #ifndef GLOB_NOMATCH | ||||||||||||||||||||
| #define GLOB_NOMATCH FLB_FILE_GLOB_ERROR_NO_MATCHES | ||||||||||||||||||||
| #endif | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #ifndef GLOB_ERR | ||||||||||||||||||||
| #define GLOB_ERR FLB_FILE_GLOB_ABORT_ON_ERROR | ||||||||||||||||||||
| #endif | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #define FLB_FILE_MAX_PATH_LENGTH PATH_MAX | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #define FLB_FILE_ISTYPE(m, t) (((m) & 0170000) == t) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| struct flb_file_glob_inner_entry { | ||||||||||||||||||||
| char *path; | ||||||||||||||||||||
| struct cfl_list _head; | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| struct flb_file_glob_inner_context { | ||||||||||||||||||||
| struct flb_file_glob_inner_entry *current_entry; | ||||||||||||||||||||
| struct cfl_list results; | ||||||||||||||||||||
| size_t entries; | ||||||||||||||||||||
| size_t index; | ||||||||||||||||||||
| uint64_t flags; | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| struct flb_file_glob_context { | ||||||||||||||||||||
| struct flb_file_glob_inner_context *inner_context; | ||||||||||||||||||||
| uint64_t flags; | ||||||||||||||||||||
| char *path; | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| struct glob_t { | ||||||||||||||||||||
| struct flb_file_glob_context inner_context; | ||||||||||||||||||||
| char **gl_pathv; | ||||||||||||||||||||
| size_t gl_pathc; | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| typedef struct glob_t glob_t; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| static int flb_file_glob_start(struct flb_file_glob_context *context, | ||||||||||||||||||||
| const char *path, | ||||||||||||||||||||
| uint64_t flags); | ||||||||||||||||||||
|
|
@@ -104,7 +45,7 @@ static void flb_file_glob_clean(struct flb_file_glob_context *context); | |||||||||||||||||||
| static int flb_file_glob_fetch(struct flb_file_glob_context *context, | ||||||||||||||||||||
| char **result); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| static void globfree(glob_t *context) | ||||||||||||||||||||
| void globfree(glob_t *context) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| size_t index; | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -116,7 +57,7 @@ static void globfree(glob_t *context) | |||||||||||||||||||
| flb_file_glob_clean(&context->inner_context); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| static int glob(const char *path, | ||||||||||||||||||||
| int glob(const char *path, | ||||||||||||||||||||
| uint64_t flags, | ||||||||||||||||||||
| void *unused, | ||||||||||||||||||||
| glob_t *context) | ||||||||||||||||||||
|
|
@@ -127,7 +68,7 @@ static int glob(const char *path, | |||||||||||||||||||
|
|
||||||||||||||||||||
| (void) unused; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| result = flb_file_glob_start(context, path, flags); | ||||||||||||||||||||
| result = flb_file_glob_start(&context->inner_context, path, flags); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (result == FLB_FILE_GLOB_ERROR_SUCCESS) { | ||||||||||||||||||||
| entries = cfl_list_size(&context->inner_context.inner_context->results); | ||||||||||||||||||||
|
|
@@ -150,14 +91,15 @@ static int glob(const char *path, | |||||||||||||||||||
| return result; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| context->gl_pathc = entries; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return result; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| static int is_directory(char *path, struct stat *fs_entry_metadata) | ||||||||||||||||||||
| int is_directory(char *path, struct stat *fs_entry_metadata) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| return (fs_entry_metadata->st_mode & S_IFDIR != 0); | ||||||||||||||||||||
| return ((fs_entry_metadata->st_mode & S_IFDIR) != 0); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+100
to
103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "flb_glob.c" -type fRepository: fluent/fluent-bit Length of output: 83 🌐 Web query:
💡 Result: On MSVC/Windows, MSVC typically does not provide POSIX
If you want the non-underscore names `#define` _CRT_INTERNAL_NONSTDC_NAMES 1
`#include` <sys/stat.h>Then you can use the POSIX-style macro definitions above. [2] Minimal MSVC-compatible directory check: `#include` <sys/stat.h>
int is_dir(const struct _stat* st) {
return (st->st_mode & _S_IFMT) == _S_IFDIR;
}
``` [1]
References:
[1] Microsoft `_stat` `st_mode` constants (`_S_IFMT`, `_S_IFDIR`, etc.)
[2] MSVC note/workaround: `_CRT_INTERNAL_NONSTDC_NAMES` and defining `S_ISDIR`
[3] POSIX definition/intent of `S_ISDIR(m)` checking `st_mode`
---
🏁 Script executed:
```shell
cat -n ./src/win32/flb_glob.c | head -120 | tail -50Repository: fluent/fluent-bit Length of output: 1640 🏁 Script executed: cat -n ./src/win32/flb_glob.c | head -20Repository: fluent/fluent-bit Length of output: 979 🏁 Script executed: cat -n ./src/win32/flb_glob.c | head -50Repository: fluent/fluent-bit Length of output: 2031 🏁 Script executed: rg "S_ISDIR|_CRT_INTERNAL_NONSTDC_NAMES" src/win32/Repository: fluent/fluent-bit Length of output: 43 🏁 Script executed: rg "FLB_FILE_ISTYPE" src/win32/flb_glob.c -A 2 -B 2Repository: fluent/fluent-bit Length of output: 380 Use proper file type masking for directory checks: The current check 🛠️ Suggested fix- return ((fs_entry_metadata->st_mode & S_IFDIR) != 0);
+ return FLB_FILE_ISTYPE(fs_entry_metadata->st_mode, S_IFDIR);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
| static void reset_errno() | ||||||||||||||||||||
|
|
@@ -485,9 +427,9 @@ static int limited_win32_glob(struct flb_file_glob_inner_context *context, | |||||||||||||||||||
| return ret; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| int flb_file_glob_start(struct flb_file_glob_context *context, | ||||||||||||||||||||
| const char *path, | ||||||||||||||||||||
| uint64_t flags) | ||||||||||||||||||||
| static int flb_file_glob_start(struct flb_file_glob_context *context, | ||||||||||||||||||||
| const char *path, | ||||||||||||||||||||
| uint64_t flags) | ||||||||||||||||||||
| { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| int tilde_expansion_attempted; | ||||||||||||||||||||
|
|
@@ -528,7 +470,7 @@ int flb_file_glob_start(struct flb_file_glob_context *context, | |||||||||||||||||||
| context->path); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| void flb_file_glob_clean(struct flb_file_glob_context *context) | ||||||||||||||||||||
| static void flb_file_glob_clean(struct flb_file_glob_context *context) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| struct cfl_list *iterator_backup; | ||||||||||||||||||||
| struct cfl_list *iterator; | ||||||||||||||||||||
|
|
@@ -564,8 +506,8 @@ void flb_file_glob_clean(struct flb_file_glob_context *context) | |||||||||||||||||||
|
|
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| int flb_file_glob_fetch(struct flb_file_glob_context *context, | ||||||||||||||||||||
| char **result) | ||||||||||||||||||||
| static int flb_file_glob_fetch(struct flb_file_glob_context *context, | ||||||||||||||||||||
| char **result) | ||||||||||||||||||||
| { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (context == NULL) { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <fluent-bit/flb_info.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <fluent-bit/flb_mem.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <fluent-bit/flb_str.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "flb_tests_internal.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef FLB_SYSTEM_WINDOWS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <fluent-bit/flb_glob_win32.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void test_glob_basic() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glob_t glob_data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FILE *fp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Create some dummy files */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fp = fopen("test_glob_1.txt", "w"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (fp) fclose(fp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fp = fopen("test_glob_2.txt", "w"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (fp) fclose(fp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+16
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for file creation. If Proposed fix /* Create some dummy files */
fp = fopen("test_glob_1.txt", "w");
- if (fp) fclose(fp);
+ TEST_CHECK(fp != NULL);
+ if (fp) fclose(fp);
fp = fopen("test_glob_2.txt", "w");
- if (fp) fclose(fp);
+ TEST_CHECK(fp != NULL);
+ if (fp) fclose(fp);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ret = glob("test_glob_*.txt", 0, NULL, &glob_data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_CHECK(ret == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_CHECK(glob_data.gl_pathc == 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| globfree(&glob_data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Cleanup */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unlink("test_glob_1.txt"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unlink("test_glob_2.txt"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing initialization for In Apply this diff to initialize the struct: void test_glob_basic()
{
- glob_t glob_data;
+ glob_t glob_data = {0};
int ret;
FILE *fp;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void test_glob_nomatch() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glob_t glob_data = {0}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ret = glob("non_existent_*.txt", 0, NULL, &glob_data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_CHECK(ret == GLOB_NOMATCH); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| globfree(&glob_data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void test_glob_wildcard() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glob_t glob_data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FILE *fp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Create dummy file */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fp = fopen("test_wildcard.txt", "w"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (fp) fclose(fp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+50
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for file creation. Same issue as Proposed fix /* Create dummy file */
fp = fopen("test_wildcard.txt", "w");
+ TEST_CHECK(fp != NULL);
if (fp) fclose(fp);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ret = glob("test_wild*.txt", 0, NULL, &glob_data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_CHECK(ret == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_CHECK(glob_data.gl_pathc == 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (glob_data.gl_pathc > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_CHECK(strstr(glob_data.gl_pathv[0], "test_wildcard.txt") != NULL); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| globfree(&glob_data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unlink("test_wildcard.txt"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+43
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same initialization concern in Similar to Apply this diff: void test_glob_wildcard()
{
- glob_t glob_data;
+ glob_t glob_data = {0};
int ret;
FILE *fp;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_LIST = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { "basic", test_glob_basic }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { "nomatch", test_glob_nomatch }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { "wildcard", test_glob_wildcard }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_LIST = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.