From: Edward Liaw via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: kernel-team@android.com
Subject: [LTP] [PATCH] controllers: remove use of LINE_MAX
Date: Thu, 11 Apr 2024 18:18:38 +0000 [thread overview]
Message-ID: <20240411181838.4157368-1-edliaw@google.com> (raw)
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.
Signed-off-by: Edward Liaw <edliaw@google.com>
---
.../kernel/controllers/libcontrollers/libcontrollers.c | 8 +++++---
.../kernel/controllers/libcontrollers/libcontrollers.h | 2 --
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{
--
2.44.0.683.g7961c838ac-goog
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2024-04-11 18:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-11 18:18 Edward Liaw via ltp [this message]
2024-04-12 13:00 ` [LTP] [PATCH] controllers: remove use of LINE_MAX Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240411181838.4157368-1-edliaw@google.com \
--to=ltp@lists.linux.it \
--cc=edliaw@google.com \
--cc=kernel-team@android.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).