<div dir="ltr"><div class="gmail_extra">Mylène Josserand <span dir="ltr"><<a href="mailto:mylene.josserand@bootlin.com" target="_blank">mylene.josserand@bootlin.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">In some system, "getconf" application may not be installed.<br>
Some tests are using it to retrieve some variables such as the<br>
page size (PAGESIZE).<br>
<br>
Create a tst_getconf binary that use sysconf() function to retrieve<br>
these variables instead of relying on "getconf" application that<br>
may not be available.<br>
Add also this new helper in the documentation.<br>
<br>
Example:<br>
pagesize=`tst_getconf PAGESIZE`<br>
<br>
Signed-off-by: Mylène Josserand <<a href="mailto:mylene.josserand@bootlin.com" target="_blank">mylene.josserand@bootlin.com</a>><br>
<div style="font-size:small;display:inline" class="gmail_default">​[...]<br></div>
+<br>
+#include <stdio.h><br>
+#include <unistd.h><br>
+#include <string.h><br>
+<br>
+static void print_help(void)<br>
+{<br>
+       printf("Usage: tst_getconf variable\n\n");<br>
+       printf("       variable: can be PAGESIZE or _NPROCESSORS_ONLN (for the moment)\n");<br>
+       printf("example: tst_getconf PAGESIZE\n");<br>
+}<br>
+<br>
+int main(int argc, char *argv[])<br>
+{<br>
+       int opt;<br>
+<br>
+       while ((opt = getopt(argc, argv, ":h")) != -1) {<br>
+               switch (opt) {<br>
+               case 'h':<br>
+                       print_help();<br>
+                       return 0;<br>
+               default:<br>
+                       print_help();<br>
+                       return 1;<br>
+               }<br>
+       }<br></blockquote><div><br></div><div><div style="font-size:small" class="gmail_default">​What about set argc limitation here?​</div><br></div><div style="font-size:small" class="gmail_default">​    if (argc != 2) {<br>        print_help();<br>        return 1;<br>    }<br><br></div><div style="font-size:small" class="gmail_default">​</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+       if (optind >= argc) {<br>
+               fprintf(stderr, "ERROR: Expected variable argument\n\n");<br>
+               print_help();<br>
+               return 1;<br>
+       }<br>
+<br>
+       if (!strcmp(argv[optind], "_NPROCESSORS_ONLN"))<br>
+               printf("%ld", sysconf(_SC_NPROCESSORS_ONLN))<wbr>;<br>
+       else if (!strcmp(argv[optind],"PAGESIZ<wbr>E"))<br>
+               printf("%ld", sysconf(_SC_PAGE_SIZE));<br></blockquote><div><br></div><div><div style="font-size:small" class="gmail_default">​We'd better add a default check for invalid parameter here, assume that if someone gives</div><div style="font-size:small" class="gmail_default">a typo in use this tst_getconf, it's not easy to find the error.</div><div style="font-size:small" class="gmail_default"><br></div><div style="font-size:small" class="gmail_default"># ./tst_getconf _NPROCESSORS_ONL  <--- typo here<br># echo $?<br>0<br></div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+       return 0;<br>
+}<br>
<span class="gmail-m_7809488541505049206gmail-HOEnZb"><font color="#888888">-- <br>
2.11.0<br>
<br>
<br>
-- <br>
Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinf<wbr>o/ltp</a><br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail-m_7809488541505049206gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div>
</div></div>