aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Liaw via ltp <ltp@lists.linux.it>2024-04-11 18:18:38 +0000
committerEdward Liaw <edliaw@google.com>2024-04-22 21:17:34 +0000
commit9b0e42199562d378f1f80fb01959f191c8a84246 (patch)
treef234a449fa88026694474a4ab5c8d071f5863f71
parent7c1ee6336dfe9bb4e52ecea616e5ebf0f89d07c0 (diff)
downloadltp-9b0e42199562d378f1f80fb01959f191c8a84246.tar.gz
controllers: remove use of LINE_MAX
LINE_MAX is not defined in Android's bionic and seems to be a leftover of POSIX standards. In this case, replace the use of fgets with getline, which will resize the line buffer if needed. Also, drop some unnecessarily exported variables. Bug: 333536295 Test: atest vts_ltp_test_x86_64 Change-Id: Iacb556b201530c49f3509bb4b35df39c35a0f57d Signed-off-by: Edward Liaw <edliaw@google.com> Reviewed-by: Cyril Hrubis <chrubis@suse.cz> (cherry picked from commit 70d3ea085665c8f11bda58a0645578d06d894ab3)
-rw-r--r--testcases/kernel/controllers/libcontrollers/libcontrollers.c8
-rw-r--r--testcases/kernel/controllers/libcontrollers/libcontrollers.h2
2 files changed, 5 insertions, 5 deletions
diff --git a/testcases/kernel/controllers/libcontrollers/libcontrollers.c b/testcases/kernel/controllers/libcontrollers/libcontrollers.c
index e9917271c..18f7257cc 100644
--- a/testcases/kernel/controllers/libcontrollers/libcontrollers.c
+++ b/testcases/kernel/controllers/libcontrollers/libcontrollers.c
@@ -39,11 +39,9 @@ char fullpath[PATH_MAX];
int FLAG;
volatile int timer_expired = 0;
int retval;
-unsigned int num_line;
unsigned int current_shares;
unsigned int total_shares;
unsigned int *shares_pointer;
-char target[LINE_MAX];
struct dirent *dir_pointer;
/*
@@ -133,6 +131,9 @@ int read_file(char *filepath, int action, unsigned int *value)
int num_line = 0;
FILE *fp;
int tmp;
+ size_t len;
+ char *target = NULL;
+
switch (action) {
case GET_SHARES:
tmp = read_shares_file(filepath);
@@ -147,8 +148,9 @@ int read_file(char *filepath, int action, unsigned int *value)
error_function("Could not open file", filepath);
return -1;
}
- while (fgets(target, LINE_MAX, fp) != NULL)
+ while (getline(&target, &len, fp) != -1)
num_line++;
+ free(target);
*value = (unsigned int)num_line;
if (fclose(fp)) {
error_function("Could not close file", filepath);
diff --git a/testcases/kernel/controllers/libcontrollers/libcontrollers.h b/testcases/kernel/controllers/libcontrollers/libcontrollers.h
index 7d7b8324b..548743225 100644
--- a/testcases/kernel/controllers/libcontrollers/libcontrollers.h
+++ b/testcases/kernel/controllers/libcontrollers/libcontrollers.h
@@ -46,11 +46,9 @@ extern char fullpath[PATH_MAX];
extern int FLAG;
extern volatile int timer_expired;
extern int retval;
-extern unsigned int num_line;
extern unsigned int current_shares;
extern unsigned int total_shares;
extern unsigned int *shares_pointer;
-extern char target[LINE_MAX];
extern struct dirent *dir_pointer;
enum{