summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/powerpc/nx-gzip
diff options
context:
space:
mode:
authorBenjamin Gray <bgray@linux.ibm.com>2023-02-03 03:39:47 +0300
committerMichael Ellerman <mpe@ellerman.id.au>2023-02-09 15:56:45 +0300
commit8d7253dc447473dfcf3f09fb0fa2bd6f7d05b43b (patch)
treecbf5ab6fd7a01894b5482ba47c5d6d95dfded4e4 /tools/testing/selftests/powerpc/nx-gzip
parent5c20de57888f0962e25a0eeec1a59c98056fc42e (diff)
downloadlinux-8d7253dc447473dfcf3f09fb0fa2bd6f7d05b43b.tar.xz
selftests/powerpc: Add automatically allocating read_file
A couple of tests roll their own auto-allocating file read logic. Add a generic implementation and convert them to use it. Signed-off-by: Benjamin Gray <bgray@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20230203003947.38033-6-bgray@linux.ibm.com
Diffstat (limited to 'tools/testing/selftests/powerpc/nx-gzip')
-rw-r--r--tools/testing/selftests/powerpc/nx-gzip/gzfht_test.c38
1 files changed, 1 insertions, 37 deletions
diff --git a/tools/testing/selftests/powerpc/nx-gzip/gzfht_test.c b/tools/testing/selftests/powerpc/nx-gzip/gzfht_test.c
index fbc3d265155b..4de079923ccb 100644
--- a/tools/testing/selftests/powerpc/nx-gzip/gzfht_test.c
+++ b/tools/testing/selftests/powerpc/nx-gzip/gzfht_test.c
@@ -143,42 +143,6 @@ int gzip_header_blank(char *buf)
return i;
}
-/* Caller must free the allocated buffer return nonzero on error. */
-int read_alloc_input_file(char *fname, char **buf, size_t *bufsize)
-{
- int err;
- struct stat statbuf;
- char *p;
- size_t num_bytes;
-
- if (stat(fname, &statbuf)) {
- perror(fname);
- return -1;
- }
-
- assert(NULL != (p = (char *) malloc(statbuf.st_size)));
-
- err = read_file(fname, p, statbuf.st_size, &num_bytes);
- if (err) {
- perror(fname);
- goto fail;
- }
-
- if (num_bytes != statbuf.st_size) {
- fprintf(stderr, "Actual bytes != expected bytes\n");
- err = -1;
- goto fail;
- }
-
- *buf = p;
- *bufsize = num_bytes;
- return 0;
-
-fail:
- free(p);
- return err;
-}
-
/*
* Z_SYNC_FLUSH as described in zlib.h.
* Returns number of appended bytes
@@ -245,7 +209,7 @@ int compress_file(int argc, char **argv, void *handle)
fprintf(stderr, "usage: %s <fname>\n", argv[0]);
exit(-1);
}
- if (read_alloc_input_file(argv[1], &inbuf, &inlen))
+ if (read_file_alloc(argv[1], &inbuf, &inlen))
exit(-1);
fprintf(stderr, "file %s read, %ld bytes\n", argv[1], inlen);