Home | History | Annotate | Download | only in munlock
      1 /*
      2  *  This program is free software; you can redistribute it and/or modify
      3  *  it under the terms of the GNU General Public License version 2.
      4  *
      5  *  This program is distributed in the hope that it will be useful,
      6  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      7  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      8  *  GNU General Public License for more details.
      9  *
     10  * Test that munlock return a value of zero upon successful completion.
     11  *
     12  */
     13 #include <sys/mman.h>
     14 #include <stdio.h>
     15 #include <stdlib.h>
     16 #include <errno.h>
     17 #include "posixtest.h"
     18 
     19 #define BUFSIZE 8
     20 
     21 int main(void)
     22 {
     23 	int result;
     24 	void *ptr;
     25 
     26 	ptr = malloc(BUFSIZE);
     27 	if (ptr == NULL) {
     28 		printf("Can not allocate memory.\n");
     29 		return PTS_UNRESOLVED;
     30 	}
     31 
     32 	if (mlock(ptr, BUFSIZE) != 0) {
     33 		if (errno == EPERM) {
     34 			printf
     35 			    ("You don't have permission to lock your address space.\nTry to rerun this test as root.\n");
     36 		} else {
     37 			perror("An error occurs when calling mlock()");
     38 		}
     39 		return PTS_UNRESOLVED;
     40 	}
     41 
     42 	result = munlock(ptr, BUFSIZE);
     43 	if (result == 0 && errno == 0) {
     44 		printf("Test PASSED\n");
     45 		return PTS_PASS;
     46 	} else if (errno == 0) {
     47 		printf("mlock did not return a value of zero\n");
     48 		return PTS_FAIL;
     49 	}
     50 
     51 	perror("Unexpected error");
     52 	return PTS_UNRESOLVED;
     53 }
     54