commit 00cf8fdf22024693ed1dc6c614f32849145ea22e
parent 8c4dfda8d59008a7fccfb339ae161fd498b89199
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 5 Sep 2023 14:45:41 +0200
Change default page size for les2htcp tool
To make it more portable, it is no longer set to 4096 by default, but
defined according to the size of a system page returned by sysconf(3).
Diffstat:
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/les2htcp.c b/src/les2htcp.c
@@ -28,7 +28,7 @@
#include <errno.h>
#include <netcdf.h>
#include <string.h>
-#include <unistd.h> /* getopt */
+#include <unistd.h> /* getopt, sysconf */
#include <fcntl.h> /* open */
#include <sys/stat.h> /* S_IRUSR & S_IWUSR */
@@ -45,7 +45,7 @@ struct args {
int no_output;
int quit; /* Quit the application */
};
-#define ARGS_DEFAULT__ {NULL,NULL,1.0,4096,0,0,0,0}
+#define ARGS_DEFAULT__ {NULL,NULL,1.0,-1,0,0,0,0}
static const struct args ARGS_DEFAULT = ARGS_DEFAULT__;
static INLINE void
@@ -66,10 +66,20 @@ args_release(struct args* args)
static res_T
args_init(struct args* args, const int argc, char** argv)
{
+ long system_pagesize;
int opt;
res_T res = RES_OK;
ASSERT(args && argc && argv);
+ system_pagesize = sysconf(_SC_PAGESIZE);
+ if(system_pagesize == -1) {
+ fprintf(stderr,
+ "Error when querying the size of a system page -- %s\n",
+ strerror(errno));
+ res = RES_BAD_OP;
+ goto error;
+ }
+
while((opt = getopt(argc, argv, "cfhi:m:o:p:qv")) != -1) {
switch(opt) {
case 'c': args->check = 1; break;
@@ -88,6 +98,7 @@ args_init(struct args* args, const int argc, char** argv)
case 'p':
res = cstr_to_long(optarg, &args->pagesize);
if(res == RES_OK && !IS_POW2(args->pagesize)) res = RES_BAD_ARG;
+ if(res == RES_OK && args->pagesize < system_pagesize) res = RES_BAD_ARG;
break;
case 'q': args->no_output = 1; break;
case 'v':
@@ -117,6 +128,11 @@ args_init(struct args* args, const int argc, char** argv)
if(args->no_output) args->output = NULL;
+ /* Use the default page size if not explicitly defined by the caller. */
+ if(args->pagesize < system_pagesize) {
+ args->pagesize = system_pagesize;
+ }
+
exit:
return res;
error: