Commits

UENISHI Kota  committed 4bae55e

getloadavg(2) ... test .. .

  • Participants
  • Parent commits b3c4836

Comments (0)

Files changed (3)

     $(CProg.new mychroot.out, mychroot, '')
     $(CProg.new myfsevent.out, myfsevent, -framework CoreServices)
     $(CProg.new myregex.out, myregex, '')
+    $(CProg.new getloadavg.out, getloadavg, '')
 
 DEPS.foreach(prog)
     prog.dep()

File c/getloadavg.c

+#include <stdio.h>
+#include <stdlib.h>
+
+#define N 3
+
+int main(){
+  double loadavg[N];
+  int nelem=N;
+
+  int nproc = getloadavg(loadavg, nelem);
+  int i;
+  for(i=0; i<nproc; ++i){
+    printf("%f\n", loadavg[i]);
+  }
+}
 // see http://blog.majide.com/2009/03/c-regex-sample-code/
 int main(int args, char ** argv){
   regex_t reg;
-  const char * regex = "^(regex)$";
+  const char * regex = "^hogehage$";
   int i;
   size_t nmatch = 5;
   regmatch_t pmatch[5];
 
   regcomp(&reg, regex, REG_EXTENDED|REG_NEWLINE);
   printf("match for '%s':\n", regex);
-  for(i=0; i<args; ++i){
+  for(i=1; i<args; ++i){
     printf("'%s': ", argv[i]);
     if(regexec( &reg, argv[i], nmatch, pmatch, 0) != 0){
-      printf("No match.\n");
+      printf("doesn't match: %s\n", argv[i]);
     }else{
-      printf("matched: ");
+      printf("matched      : ");
       int j, k;
       for(j=0;j<nmatch;++j){
 	if (pmatch[j].rm_so >= 0 && pmatch[j].rm_eo >= 0) {
-	  printf("from %d to %d\n", pmatch[j].rm_so, pmatch[j].rm_eo);
+	  printf("from %d to %d\n", (int)pmatch[j].rm_so, (int)pmatch[j].rm_eo);
 	  //	  for (k = pmatch[j].rm_so ; k < pmatch[j].rm_eo; k++) {
 	  //	    putchar(argv[i][k]);
 	}